Skip to content

Commit d153745

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

File tree

23 files changed

+242
-156
lines changed

23 files changed

+242
-156
lines changed

.github/workflows/code-quality.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,126 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22+
validate-packages:
23+
name: Valide packages definition
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- run: npm i -g corepack && corepack enable
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version-file: '.nvmrc'
32+
cache: 'pnpm'
33+
cache-dependency-path: |
34+
pnpm-lock.yaml
35+
package.json
36+
37+
- name: Install root JS dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Check all composer.json have label "symfony-ux"
41+
if: always()
42+
run: |
43+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
44+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
45+
echo "File $file does not have the keyword 'symfony-ux' in its composer.json";
46+
exit 1;
47+
fi
48+
done
49+
50+
- name: Check all composer.json have license "MIT"
51+
if: always()
52+
run: |
53+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
54+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
55+
echo "File $file does not have the license 'MIT' in its composer.json";
56+
exit 1;
57+
fi
58+
done
59+
60+
- name: Check all composer.json have minimum-stability "dev"
61+
if: always()
62+
run: |
63+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
64+
if ! jq -e '."minimum-stability" == "dev"' "$file" > /dev/null; then
65+
echo "File $file does not have the minimum-stability 'dev' in its composer.json";
66+
exit 1;
67+
fi
68+
done
69+
70+
- name: Check all composer.json have dependency to "php" >=8.1
71+
if: always()
72+
run:
73+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
74+
if ! jq -e '.require.php | test(">=8.1")' "$file" > /dev/null; then
75+
echo "File $file does not have the dependency 'php' >=8.1 in its composer.json";
76+
exit 1;
77+
fi
78+
done
79+
80+
- name: Check all package.json have license "MIT"
81+
if: always()
82+
run: |
83+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
84+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
85+
echo "File $file does not have the license 'MIT' in its package.json";
86+
exit 1;
87+
fi
88+
done
89+
90+
- name: Check all package.json have keywords including "symfony-ux"
91+
if: always()
92+
run: |
93+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
94+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
95+
echo "File $file does not have the keyword 'symfony-ux' in its package.json";
96+
exit 1;
97+
fi
98+
done
99+
100+
101+
- name: Check all package.json have type "module"
102+
if: always()
103+
run: |
104+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
105+
if ! jq -e '.type == "module"' "$file" > /dev/null; then
106+
echo "File $file does not have the type 'module' in its package.json";
107+
exit 1;
108+
fi
109+
done
110+
111+
- name: Check all package.json have files '["dist"]'
112+
if: always()
113+
run: |
114+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
115+
if ! jq -e '.files | index("dist")' "$file" > /dev/null; then
116+
echo "File $file does not have the files 'dist' in its package.json";
117+
exit 1;
118+
fi
119+
done
120+
121+
- name: Check all package.json peerDependencies are present in devDependencies and importmap to the exact same version
122+
if: always()
123+
run: |
124+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
125+
peerDependencies=$(jq -r '.peerDependencies | keys[]' "$file")
126+
for peerDependency in $peerDependencies; do
127+
peerDependencyVersion=$(jq -r --arg dep "$peerDependency" '.peerDependencies[$dep]' "$file")
128+
importmapVersion=$(jq -r ".symfony.importmap.\"$peerDependency\" | if type == \"string\" then . else .version end" "$file")
129+
130+
if [ "$importmapVersion" == null ]; then
131+
echo "File $file does not have the peerDependency '$peerDependency' in its symfony.importmap, skipping version check";
132+
continue
133+
fi
134+
135+
if [ "$peerDependencyVersion" != "$importmapVersion" ]; then
136+
echo "File $file has a mismatch for $peerDependency: peerDependency version is '$peerDependencyVersion' but symfony.importmap version is '$importmapVersion'";
137+
exit 1;
138+
fi
139+
done
140+
done
141+
22142
coding-style-js:
23143
name: JavaScript Coding Style
24144
runs-on: ubuntu-latest

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)