Skip to content

Commit 4949e62

Browse files
committed
Refactor "test_package.sh" to its original purpose, add multiples checks for packages definition
1 parent 405251f commit 4949e62

File tree

23 files changed

+231
-157
lines changed

23 files changed

+231
-157
lines changed

.github/workflows/code-quality.yaml

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,114 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22+
validate-packages:
23+
name: Validate packages definition
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Check all composer.json have label "symfony-ux"
29+
if: always()
30+
run: |
31+
for file in $(find src/ -mindepth 2 -type f -name composer.json); do
32+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
33+
echo "File $file does not have the keyword 'symfony-ux' in its composer.json";
34+
exit 1;
35+
fi
36+
done
37+
38+
- name: Check all composer.json have license "MIT"
39+
if: always()
40+
run: |
41+
for file in $(find src/ -mindepth 2 -type f -name composer.json); do
42+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
43+
echo "File $file does not have the license 'MIT' in its composer.json";
44+
exit 1;
45+
fi
46+
done
47+
48+
- name: Check all composer.json have minimum-stability "dev"
49+
if: always()
50+
run: |
51+
for file in $(find src/ -mindepth 2 -type f -name composer.json); do
52+
if ! jq -e '."minimum-stability" == "dev"' "$file" > /dev/null; then
53+
echo "File $file does not have the minimum-stability 'dev' in its composer.json";
54+
exit 1;
55+
fi
56+
done
57+
58+
- name: Check all composer.json have dependency to "php" >=8.1
59+
if: always()
60+
run: |
61+
for file in $(find src/ -mindepth 2 -type f -name composer.json); do
62+
if ! jq -e '.require.php | test(">=8.1")' "$file" > /dev/null; then
63+
echo "File $file does not have the dependency 'php' >=8.1 in its composer.json";
64+
exit 1;
65+
fi
66+
done
67+
68+
- name: Check all package.json have license "MIT"
69+
if: always()
70+
run: |
71+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/tests/*"); do
72+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
73+
echo "File $file does not have the license 'MIT' in its package.json";
74+
exit 1;
75+
fi
76+
done
77+
78+
- name: Check all package.json have keywords including "symfony-ux"
79+
if: always()
80+
run: |
81+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/tests/*"); do
82+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
83+
echo "File $file does not have the keyword 'symfony-ux' in its package.json";
84+
exit 1;
85+
fi
86+
done
87+
88+
89+
- name: Check all package.json have type "module"
90+
if: always()
91+
run: |
92+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/tests/*"); do
93+
if ! jq -e '.type == "module"' "$file" > /dev/null; then
94+
echo "File $file does not have the type 'module' in its package.json";
95+
exit 1;
96+
fi
97+
done
98+
99+
- name: Check all package.json have files '["dist"]'
100+
if: always()
101+
run: |
102+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/tests/*"); do
103+
if ! jq -e '.files | index("dist")' "$file" > /dev/null; then
104+
echo "File $file does not have the files 'dist' in its package.json";
105+
exit 1;
106+
fi
107+
done
108+
109+
- name: Check all package.json peerDependencies are present in devDependencies and importmap to the exact same version
110+
if: always()
111+
run: |
112+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/tests/*"); do
113+
peerDependencies=$(jq -r '.peerDependencies | keys[]' "$file")
114+
for peerDependency in $peerDependencies; do
115+
peerDependencyVersion=$(jq -r --arg dep "$peerDependency" '.peerDependencies[$dep]' "$file")
116+
importmapVersion=$(jq -r ".symfony.importmap.\"$peerDependency\" | if type == \"string\" then . else .version end" "$file")
117+
118+
if [ "$importmapVersion" == null ]; then
119+
echo "File $file does not have the peerDependency '$peerDependency' in its symfony.importmap, skipping version check";
120+
continue
121+
fi
122+
123+
if [ "$peerDependencyVersion" != "$importmapVersion" ]; then
124+
echo "File $file has a mismatch for $peerDependency: peerDependency version is '$peerDependencyVersion' but symfony.importmap version is '$importmapVersion'";
125+
exit 1;
126+
fi
127+
done
128+
done
129+
22130
coding-style-js:
23131
name: JavaScript Coding Style
24132
runs-on: ubuntu-latest
@@ -68,7 +176,7 @@ jobs:
68176
69177
# TODO: Only Turbo has PHPStan configuration, let's improve this later :)
70178
PACKAGES=Turbo
71-
#PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | sed 's/^src\///' | sort | tr '\n' ' ')
179+
#PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -printf '%h\n' | sed 's/^src\///' | sort | tr '\n' ' ')
72180
echo "Packages: $PACKAGES"
73181
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
74182

bin/test_package.sh renamed to bin/unit_test_package.sh

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# This script is used to test an UX package.
3+
# This script is used to unit test assets from an UX package.
44
# It also handle the case where a package has multiple versions of a peerDependency defined.
55

66
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
@@ -21,13 +21,6 @@ if [ ! -d "$location" ]; then
2121
exit 1
2222
fi
2323

24-
shift
25-
case "$1" in
26-
--unit) testType="unit" ;;
27-
--browser) testType="browser" ;;
28-
*) echo "Unknown test type: $2. Please use --unit or --browser."; exit 1 ;;
29-
esac
30-
3124
shift
3225
args=("$@")
3326

@@ -38,15 +31,9 @@ if ! command -v jq &> /dev/null; then
3831
fi
3932

4033
runTestSuite() {
41-
if [ "$testType" == "unit" ]; then
42-
echo -e "🧪 Running unit tests for $workspace...\n"
43-
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
44-
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
45-
elif [ "$testType" == "browser" ]; then
46-
echo -e "🧪 Running browser tests for $workspace...\n"
47-
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
48-
(cd "$location"; pnpm exec playwright test "${args[@]}") || { all_tests_passed=false; }
49-
fi
34+
echo -e "🧪 Running unit tests for $workspace...\n"
35+
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
36+
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
5037
}
5138

5239
processWorkspace() {
@@ -69,30 +56,6 @@ processWorkspace() {
6956

7057
echo -e "⏳ Processing workspace $workspace at location $location...\n"
7158

72-
# TODO: Refactor the `test_package.sh` script to its simple form: only run unit tests for a given UX package,
73-
# The rest will be moved to `pnpm` scripts or other CI checks
74-
if [ "$testType" == "browser" ]; then
75-
runTestSuite
76-
fi
77-
78-
echo "⚙️ Checking '$package_json_path' for peerDependencies and importmap dependencies to have the same version"
79-
deps=$(jq -r '.peerDependencies | keys[]' "$package_json_path")
80-
for library in $deps; do
81-
version=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
82-
importmap_version=$(jq -r ".symfony.importmap.\"$library\" | if type == \"string\" then . else .version end" "$package_json_path")
83-
84-
if [ "$importmap_version" == null ]; then
85-
echo " ⚠ No importmap version found for $library in $package_json_path, skipping..."
86-
continue
87-
fi
88-
89-
if [ "$version" != "$importmap_version" ]; then
90-
echo " ⚠ Version mismatch for $library: $version (peerDependencies) vs $importmap_version (importmap)"
91-
echo " ⚠ You need to match the version of the \"peerDependency\" with the version in the \"importmap\""
92-
exit 1
93-
fi
94-
done
95-
9659
echo "⚙️ Checking '$package_json_path' for peerDependencies with multiple versions defined"
9760
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
9861

src/Autocomplete/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit && pnpm run test:browser",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
22-
"test:browser": "../../../bin/test_package.sh . --browser",
23-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
22+
"test:browser": "playwright test",
23+
"test:browser:ui": "playwright test --ui",
2424
"check": "biome check",
2525
"ci": "biome ci"
2626
},

src/Chartjs/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit && pnpm run test:browser",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
22-
"test:browser": "../../../bin/test_package.sh . --browser",
23-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
22+
"test:browser": "playwright test",
23+
"test:browser:ui": "playwright test --ui",
2424
"check": "biome check",
2525
"ci": "biome ci"
2626
},

src/Cropperjs/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"build": "tsx ../../../bin/build_package.ts .",
2222
"watch": "tsx ../../../bin/build_package.ts . --watch",
2323
"test": "pnpm run test:unit && pnpm run test:browser",
24-
"test:unit": "../../../bin/test_package.sh . --unit",
25-
"test:browser": "../../../bin/test_package.sh . --browser",
26-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
24+
"test:unit": "../../../bin/unit_test_package.sh .",
25+
"test:browser": "playwright test",
26+
"test:browser:ui": "playwright test --ui",
2727
"check": "biome check",
2828
"ci": "biome ci"
2929
},

src/Dropzone/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"build": "tsx ../../../bin/build_package.ts .",
2222
"watch": "tsx ../../../bin/build_package.ts . --watch",
2323
"test": "pnpm run test:unit && pnpm run test:browser",
24-
"test:unit": "../../../bin/test_package.sh . --unit",
25-
"test:browser": "../../../bin/test_package.sh . --browser",
26-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
24+
"test:unit": "../../../bin/unit_test_package.sh .",
25+
"test:browser": "playwright test",
26+
"test:browser:ui": "playwright test --ui",
2727
"check": "biome check",
2828
"ci": "biome ci"
2929
},

src/LazyImage/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
2222
"check": "biome check",
2323
"ci": "biome ci"
2424
},

src/LiveComponent/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"build": "tsx ../../../bin/build_package.ts .",
2424
"watch": "tsx ../../../bin/build_package.ts . --watch",
2525
"test": "pnpm run test:unit && pnpm run test:browser",
26-
"test:unit": "../../../bin/test_package.sh . --unit",
27-
"test:browser": "../../../bin/test_package.sh . --browser",
28-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
26+
"test:unit": "../../../bin/unit_test_package.sh .",
27+
"test:browser": "playwright test",
28+
"test:browser:ui": "playwright test --ui",
2929
"check": "biome check",
3030
"ci": "biome ci"
3131
},

src/Map/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "tsx ../../../bin/build_package.ts .",
2323
"watch": "tsx ../../../bin/build_package.ts . --watch",
2424
"test": "pnpm run test:unit",
25-
"test:unit": "../../../bin/test_package.sh . --unit",
25+
"test:unit": "../../../bin/unit_test_package.sh .",
2626
"check": "biome check",
2727
"ci": "biome ci"
2828
},

src/Map/src/Bridge/Google/assets/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"build": "tsx ../../../../../../bin/build_package.ts .",
2121
"watch": "tsx ../../../../../../bin/build_package.ts . --watch",
2222
"test": "pnpm run test:browser",
23-
"test:browser": "../../../../../../bin/test_package.sh . --browser",
24-
"test:browser:ui": "../../../../../../bin/test_package.sh . --browser --ui",
23+
"test:browser": "playwright test",
24+
"test:browser:ui": "playwright test --ui",
2525
"check": "biome check",
2626
"ci": "biome ci"
2727
},

0 commit comments

Comments
 (0)