Skip to content

Commit b131e51

Browse files
committed
minor #1629 [CI] Add configurable dependency version validation script (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [CI] Add configurable dependency version validation script | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- bf117c2 [CI] Add configurable dependency version validation script
2 parents 75e8236 + bf117c2 commit b131e51

File tree

4 files changed

+65
-45
lines changed

4 files changed

+65
-45
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#
3+
# Validates that all components and bridges use the required version of a given package in require-dev.
4+
#
5+
# Usage: validate-dependency-versions.sh PACKAGE REQUIRED_VERSION
6+
#
7+
# Example: validate-dependency-versions.sh phpunit/phpunit "^11.5.53"
8+
#
9+
# Checks all composer.json files under src/ and ensures that if the given package is
10+
# present in require-dev, it is set to exactly the required version.
11+
12+
set -e
13+
14+
if [[ $# -ne 2 ]]; then
15+
echo "Usage: $0 PACKAGE REQUIRED_VERSION"
16+
exit 1
17+
fi
18+
19+
PACKAGE="$1"
20+
REQUIRED_VERSION="$2"
21+
ERRORS=0
22+
23+
echo "Validating ${PACKAGE} version in all composer.json files..."
24+
echo ""
25+
26+
while IFS= read -r -d '' composer_file; do
27+
package_version=$(jq -r --arg pkg "$PACKAGE" '.["require-dev"][$pkg] // empty' "$composer_file" 2>/dev/null)
28+
29+
if [[ -n "$package_version" ]]; then
30+
if [[ "$package_version" != "$REQUIRED_VERSION" ]]; then
31+
echo "::error file=${composer_file}::${PACKAGE} version must be \"${REQUIRED_VERSION}\" but found \"${package_version}\" in ${composer_file}"
32+
ERRORS=$((ERRORS + 1))
33+
else
34+
echo "${composer_file}: ${PACKAGE} = \"${package_version}\""
35+
fi
36+
fi
37+
done < <(find src/ -name "composer.json" -not -path "*/vendor/*" -print0 | sort -z)
38+
39+
if [[ $ERRORS -gt 0 ]]; then
40+
echo ""
41+
echo "::error::Found $ERRORS composer.json file(s) with incorrect ${PACKAGE} version (expected \"${REQUIRED_VERSION}\")"
42+
exit 1
43+
fi
44+
45+
echo ""
46+
echo "All composer.json files use the required ${PACKAGE} version (${REQUIRED_VERSION})!"

.github/scripts/validate-phpunit-version.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/validation.yaml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- '.github/scripts/validate-bridge-splitsh.sh'
1313
- '.github/scripts/validate-bridge-files.sh'
1414
- '.github/scripts/validate-bridge-type.sh'
15-
- '.github/scripts/validate-phpunit-version.sh'
15+
- '.github/scripts/validate-dependency-versions.sh'
1616
pull_request:
1717
paths:
1818
- 'src/*/src/Bridge/**/*'
@@ -24,7 +24,7 @@ on:
2424
- '.github/scripts/validate-bridge-splitsh.sh'
2525
- '.github/scripts/validate-bridge-files.sh'
2626
- '.github/scripts/validate-bridge-type.sh'
27-
- '.github/scripts/validate-phpunit-version.sh'
27+
- '.github/scripts/validate-dependency-versions.sh'
2828

2929
concurrency:
3030
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -141,12 +141,24 @@ jobs:
141141
- name: Validate Mate bridges have correct type
142142
run: .github/scripts/validate-bridge-type.sh mate
143143

144-
validate_phpunit_version:
145-
name: PHPUnit Version
144+
validate_dependency_versions:
145+
name: "${{ matrix.package }} ${{ matrix.version }}"
146146
runs-on: ubuntu-latest
147+
strategy:
148+
fail-fast: false
149+
matrix:
150+
include:
151+
- package: phpunit/phpunit
152+
version: "^11.5.53"
153+
- package: phpstan/phpstan
154+
version: "^2.1"
155+
- package: phpstan/phpstan-phpunit
156+
version: "^2.0"
157+
- package: phpstan/phpstan-strict-rules
158+
version: "^2.0"
147159
steps:
148160
- name: Checkout
149161
uses: actions/checkout@v6
150162

151-
- name: Validate phpunit/phpunit version in all composer.json files
152-
run: .github/scripts/validate-phpunit-version.sh
163+
- name: Validate ${{ matrix.package }} version in all composer.json files
164+
run: .github/scripts/validate-dependency-versions.sh "${{ matrix.package }}" "${{ matrix.version }}"

src/platform/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"symfony/uid": "^7.3|^8.0"
6363
},
6464
"require-dev": {
65-
"phpstan/phpstan": "^2.1.17",
65+
"phpstan/phpstan": "^2.1",
6666
"phpstan/phpstan-phpunit": "^2.0",
6767
"phpstan/phpstan-strict-rules": "^2.0",
6868
"phpunit/phpunit": "^11.5.53",

0 commit comments

Comments
 (0)