@@ -2,24 +2,84 @@ name: Test
22
33on :
44 push :
5- branches : [ ' main' ]
5+ branches : [main]
66 pull_request :
7- types : [ 'opened', 'synchronize', 'reopened' ]
7+ branches : [main]
8+ types : [opened, synchronize, reopened]
9+
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.ref }}
12+ cancel-in-progress : true
813
914jobs :
15+ lint :
16+ name : Lint
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout
21+ uses : actions/checkout@v4
22+
23+ - name : Set up PHP
24+ uses : shivammathur/setup-php@v2
25+ with :
26+ php-version : " 8.3"
27+ tools : composer:v2
28+
29+ - name : Cache dependencies
30+ uses : actions/cache@v4
31+ with :
32+ path : ~/.composer/cache
33+ key : php-8.3-composer-${{ hashFiles('**/composer.json') }}
34+ restore-keys : php-8.3-composer-
35+
36+ - name : Install dependencies
37+ run : composer install --prefer-dist --no-progress
38+
39+ - name : Check code style
40+ run : composer pint-test
41+
42+ analyse :
43+ name : Static Analysis
44+ runs-on : ubuntu-latest
45+
46+ steps :
47+ - name : Checkout
48+ uses : actions/checkout@v4
49+
50+ - name : Set up PHP
51+ uses : shivammathur/setup-php@v2
52+ with :
53+ php-version : " 8.3"
54+ tools : composer:v2
55+
56+ - name : Cache dependencies
57+ uses : actions/cache@v4
58+ with :
59+ path : ~/.composer/cache
60+ key : php-8.3-composer-${{ hashFiles('**/composer.json') }}
61+ restore-keys : php-8.3-composer-
62+
63+ - name : Install dependencies
64+ run : composer install --prefer-dist --no-progress
65+
66+ - name : Run PHPStan
67+ run : composer analyse
68+ continue-on-error : true
69+
1070 test :
11- name : Test on PHP ${{ matrix.php-version }}
71+ name : Test ( PHP ${{ matrix.php-version }})
1272 runs-on : ubuntu-latest
73+ needs : [lint]
1374
1475 strategy :
76+ fail-fast : false
1577 matrix :
16- php-version : [ ' 8.2', ' 8.3', ' 8.4' ]
78+ php-version : [" 8.2", " 8.3", " 8.4" ]
1779
1880 steps :
19- - name : Checkout source code
20- uses : actions/checkout@v2
21- with :
22- fetch-depth : 0
81+ - name : Checkout
82+ uses : actions/checkout@v4
2383
2484 - name : Set up PHP ${{ matrix.php-version }}
2585 uses : shivammathur/setup-php@v2
@@ -29,24 +89,86 @@ jobs:
2989 tools : composer:v2
3090
3191 - name : Cache dependencies
32- uses : actions/cache@v4.3.0
92+ uses : actions/cache@v4
3393 with :
3494 path : ~/.composer/cache
3595 key : php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
3696 restore-keys : php-${{ matrix.php-version }}-composer-
3797
38- - name : Validate composer.json and composer.lock
39- run : composer validate
40-
41- - name : Install Dependencies
42- if : steps.composer-cache.outputs.cache-hit != 'true'
98+ - name : Install dependencies
4399 run : composer install --prefer-dist --no-progress
44100
45- - name : Check Code Style
46- run : composer pint- test
101+ - name : Run tests
102+ run : composer test
47103
48- - name : Execute Static Code analysis
49- run : composer analyse
104+ - name : Upload coverage artifact
105+ if : matrix.php-version == '8.4'
106+ uses : actions/upload-artifact@v4
107+ with :
108+ name : coverage-report
109+ path : |
110+ coverage.xml
111+ test.xml
50112
51- - name : Execute Unit, Integration and Acceptance Tests
52- run : composer test
113+ sonarcloud :
114+ name : SonarCloud Analysis
115+ runs-on : ubuntu-latest
116+ needs : [test]
117+
118+ steps :
119+ - name : Checkout
120+ uses : actions/checkout@v4
121+ with :
122+ fetch-depth : 0
123+
124+ - name : Download coverage artifact
125+ uses : actions/download-artifact@v4
126+ with :
127+ name : coverage-report
128+
129+ - name : Fix paths in coverage reports
130+ run : |
131+ sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
132+ sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' test.xml
133+
134+ - name : SonarCloud Scan
135+ uses : SonarSource/sonarqube-scan-action@v6
136+ env :
137+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
138+
139+ ci-success :
140+ name : CI Success
141+ runs-on : ubuntu-latest
142+ needs : [lint, analyse, test, sonarcloud]
143+ if : always()
144+
145+ steps :
146+ - name : Check all jobs
147+ run : |
148+ echo "===== Job Results ====="
149+ echo "Lint: ${{ needs.lint.result }}"
150+ echo "Analyse: ${{ needs.analyse.result }}"
151+ echo "Test: ${{ needs.test.result }}"
152+ echo "SonarCloud: ${{ needs.sonarcloud.result }}"
153+ echo "======================="
154+
155+ if [ "${{ needs.lint.result }}" != "success" ]; then
156+ echo "❌ Lint failed"
157+ exit 1
158+ fi
159+
160+ if [ "${{ needs.test.result }}" != "success" ]; then
161+ echo "❌ Tests failed"
162+ exit 1
163+ fi
164+
165+ if [ "${{ needs.analyse.result }}" == "failure" ]; then
166+ echo "⚠️ Static analysis failed (non-blocking)"
167+ fi
168+
169+ if [ "${{ needs.sonarcloud.result }}" != "success" ]; then
170+ echo "❌ SonarCloud failed"
171+ exit 1
172+ fi
173+
174+ echo "✅ All required checks passed!"
0 commit comments