Skip to content

Commit 2e1a34c

Browse files
committed
worklow optimized
1 parent 72fcde7 commit 2e1a34c

1 file changed

Lines changed: 35 additions & 183 deletions

File tree

.github/workflows/codestyle-and-unittest.yml

Lines changed: 35 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -9,179 +9,40 @@ on:
99
- "**.php"
1010

1111
jobs:
12-
phplint:
13-
name: PHP Lint
12+
# 1. Job: Statische Analyse (Lint, Stan, CodeSniffer)
13+
# Diese laufen zusammen, da sie keine Datenbank benötigen.
14+
static-analysis:
15+
name: PHP Quality Checks
1416
runs-on: ubuntu-latest
15-
1617
steps:
1718
- uses: actions/checkout@v5
1819

19-
- name: Setup PHP with PECL extension
20-
uses: shivammathur/setup-php@v2
21-
with:
22-
php-version: '8.4'
23-
24-
- name: Validate composer.json and composer.lock
25-
run: composer validate --strict
26-
27-
- name: Cache Composer packages
28-
id: composer-cache
29-
uses: actions/cache@v4
30-
with:
31-
path: vendor
32-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
33-
restore-keys: |
34-
${{ runner.os }}-php-
35-
36-
- name: Install dependencies
37-
run: composer install --prefer-dist --no-progress
20+
- name: Setup PHP and Composer
21+
uses: ./.github/actions/setup-php-composer
3822

3923
- name: Run PHP Linter
4024
run: composer run-script phplint
4125

42-
- name: Check Info Failure
43-
uses: rjstone/discord-webhook-notify@v1.0.4
44-
with:
45-
severity: error
46-
details: PHP Lint failed.
47-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
48-
if: failure()
49-
50-
phpstan:
51-
name: PHP Stan
52-
runs-on: ubuntu-latest
53-
54-
steps:
55-
- uses: actions/checkout@v5
56-
57-
- name: Setup PHP with PECL extension
58-
uses: shivammathur/setup-php@v2
59-
with:
60-
php-version: '8.4'
61-
62-
- name: Validate composer.json and composer.lock
63-
run: composer validate --strict
64-
65-
- name: Cache Composer packages
66-
id: composer-cache
67-
uses: actions/cache@v4
68-
with:
69-
path: vendor
70-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
71-
restore-keys: |
72-
${{ runner.os }}-php-
73-
74-
- name: Install dependencies
75-
run: composer install --prefer-dist --no-progress
76-
7726
- name: Run PHP Stan
7827
run: composer run-script phpstan
7928

80-
- name: Check Info Failure
81-
uses: rjstone/discord-webhook-notify@v1.0.4
82-
with:
83-
severity: error
84-
details: PHP Stan failed.
85-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
86-
if: failure()
87-
88-
phpcs:
89-
name: PHP CodeSniffer
90-
runs-on: ubuntu-latest
91-
92-
steps:
93-
- uses: actions/checkout@v5
94-
95-
- name: Setup PHP with PECL extension
96-
uses: shivammathur/setup-php@v2
97-
with:
98-
php-version: '8.4'
99-
100-
- name: Validate composer.json and composer.lock
101-
run: composer validate --strict
102-
103-
- name: Cache Composer packages
104-
id: composer-cache
105-
uses: actions/cache@v4
106-
with:
107-
path: vendor
108-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
109-
restore-keys: |
110-
${{ runner.os }}-php-
111-
112-
- name: Install dependencies
113-
run: composer install --prefer-dist --no-progress
114-
11529
- name: Run PHP Codesniffer
11630
run: composer run-script phpcs
11731

118-
- name: Check Info Failure
119-
uses: rjstone/discord-webhook-notify@v1.0.4
120-
with:
121-
severity: error
122-
details: CodeSniffer failed.
123-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
32+
- name: Notify Failure
12433
if: failure()
125-
126-
phpunit:
127-
name: PHP Unit Test
128-
needs:
129-
- phplint
130-
- phpstan
131-
- phpcs
132-
runs-on: ubuntu-latest
133-
134-
steps:
135-
- uses: actions/checkout@v5
136-
137-
- name: Setup PHP with PECL extension
138-
uses: shivammathur/setup-php@v2
139-
with:
140-
php-version: '8.4'
141-
142-
- name: Validate composer.json and composer.lock
143-
run: composer validate --strict
144-
145-
- name: Cache Composer packages
146-
id: composer-cache
147-
uses: actions/cache@v4
148-
with:
149-
path: vendor
150-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
151-
restore-keys: |
152-
${{ runner.os }}-php-
153-
154-
- name: Install dependencies
155-
run: composer install --prefer-dist --no-progress
156-
157-
- name: Run PHP Unit Test
158-
run: composer run-script unittest
159-
160-
- name: Test Info Failure
161-
uses: rjstone/discord-webhook-notify@v2
34+
uses: rjstone/discord-webhook-notify@v1.0.4
16235
with:
16336
severity: error
164-
details: PHP Unit Test failed.
37+
details: Static Analysis (Lint/Stan/CS) failed.
16538
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
166-
if: failure()
16739

168-
phpfunctional:
169-
name: PHP Functional Test
170-
needs:
171-
- phplint
172-
- phpstan
173-
- phpcs
40+
# 2. Job: Tests (Unit & Functional)
41+
# Dieser Job benötigt die MariaDB Service-Container
42+
tests:
43+
name: PHP Tests
44+
needs: static-analysis
17445
runs-on: ubuntu-latest
175-
env:
176-
DB_DATABASE: db
177-
DB_USERNAME: dev
178-
DB_PASSWORD: dev
179-
DB_HOST: 127.0.0.1
180-
DB_PORT: 3306
181-
MYSQL_ALLOW_EMPTY_PASSWORD: false
182-
MYSQL_ROOT_PASSWORD: root
183-
MYSQL_DATABASE: db
184-
APP_ENV: action
18546
services:
18647
database-testing:
18748
image: mariadb:latest
@@ -194,61 +55,52 @@ jobs:
19455
ports:
19556
- 3306:3306
19657
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
58+
env:
59+
DB_DATABASE: db
60+
DB_USERNAME: dev
61+
DB_PASSWORD: dev
62+
DB_HOST: 127.0.0.1
63+
DB_PORT: 3306
64+
APP_ENV: action
19765
steps:
19866
- uses: actions/checkout@v5
199-
- name: Install PHP with extensions.
200-
uses: shivammathur/setup-php@v2
201-
with:
202-
php-version: 8.4
203-
extensions: pdo
204-
ini-values: date.timezone='UTC'
205-
- name: Validate composer.json and composer.lock
206-
run: composer validate --strict
20767

208-
- name: Cache Composer packages
209-
id: composer-cache
210-
uses: actions/cache@v4
211-
with:
212-
path: vendor
213-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
214-
restore-keys: |
215-
${{ runner.os }}-php-
68+
- name: Setup PHP and Composer
69+
uses: ./.github/actions/setup-php-composer
21670

217-
- name: Install dependencies
218-
run: composer install --prefer-dist --no-progress
71+
- name: Run PHP Unit Test
72+
run: composer run-script unittest
21973

22074
- name: Run PHP Functional Test
22175
run: composer run-script functionaltest
22276

223-
- name: Test Info Failure
77+
- name: Notify Failure
78+
if: failure()
22479
uses: rjstone/discord-webhook-notify@v1.0.4
22580
with:
22681
severity: error
227-
details: Functional Test failed.
82+
details: Unit or Functional Tests failed.
22883
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
229-
if: failure()
23084

231-
message:
232-
needs:
233-
- phpcs
234-
- phplint
235-
- phpstan
236-
- phpunit
237-
- phpfunctional
85+
# 3. Job: Abschluss-Benachrichtigung
86+
final-status:
87+
name: Final Status Message
88+
needs: [static-analysis, tests]
89+
if: always()
23890
runs-on: ubuntu-latest
23991
steps:
24092
- name: Check Info Success
93+
if: ${{ needs.static-analysis.result == 'success' && needs.tests.result == 'success' }}
24194
uses: rjstone/discord-webhook-notify@v1.0.4
24295
with:
24396
severity: info
24497
details: Checks successfully executed on API.
24598
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
246-
if: success()
24799

248100
- name: Check Info Failure
101+
if: ${{ needs.static-analysis.result != 'success' || needs.tests.result != 'success' }}
249102
uses: rjstone/discord-webhook-notify@v1.0.4
250103
with:
251104
severity: error
252105
details: Incorrect checks during the API check.
253106
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
254-
if: failure()

0 commit comments

Comments
 (0)