Skip to content

Commit 72fcde7

Browse files
committed
worklow optimized
1 parent 6f3f61b commit 72fcde7

3 files changed

Lines changed: 81 additions & 221 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .github/actions/setup-php-composer/action.yml
2+
name: 'Setup PHP and Composer'
3+
description: 'Common setup for PHP jobs'
4+
inputs:
5+
php-version:
6+
description: 'PHP Version'
7+
default: '8.4'
8+
install-flags:
9+
description: 'Composer install flags'
10+
default: '--prefer-dist --no-progress'
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: ${{ inputs.php-version }}
19+
extensions: pdo, mbstring # hier Standard-Extensions ergänzen
20+
21+
- name: Cache Composer packages
22+
uses: actions/cache@v4
23+
with:
24+
path: vendor
25+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
26+
restore-keys: ${{ runner.os }}-php-
27+
28+
- name: Install dependencies
29+
shell: bash
30+
run: composer install ${{ inputs.install-flags }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- '*'
66
- '!master'
7-
- '!develope'
7+
- '!develop'
88
paths:
99
- "**.php"
1010

.github/workflows/deploy_dev.yml

Lines changed: 50 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,267 +1,105 @@
1-
name: Deployment on Developement
1+
name: Deployment on Development
22
on:
33
push:
4-
branches: [ "develope" ]
4+
branches: [ "develop" ]
55
workflow_dispatch:
66

77
jobs:
8-
phplint:
9-
name: PHP Lint
8+
# 1. Statische Analyse (Zusammengefasst, da sie keine DB brauchen)
9+
static-analysis:
10+
name: PHP Quality Checks
1011
runs-on: ubuntu-latest
11-
1212
steps:
1313
- uses: actions/checkout@v5
1414

15-
- name: Setup PHP with PECL extension
16-
uses: shivammathur/setup-php@v2
17-
with:
18-
php-version: '8.4'
15+
- name: Setup Environment
16+
uses: ./.github/actions/setup-php-composer
1917

20-
- name: Validate composer.json and composer.lock
18+
- name: Validate Composer
2119
run: composer validate --strict
2220

23-
- name: Cache Composer packages
24-
id: composer-cache
25-
uses: actions/cache@v4
26-
with:
27-
path: vendor
28-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
29-
restore-keys: |
30-
${{ runner.os }}-php-
31-
32-
- name: Install dependencies
33-
run: composer install --prefer-dist --no-progress
34-
35-
- name: Run PHP Linter
36-
run: composer run-script phplint
37-
38-
- name: Check Info Failure
39-
uses: rjstone/discord-webhook-notify@v1.0.4
40-
with:
41-
severity: error
42-
details: PHP Lint failed.
43-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
44-
if: failure()
45-
46-
phpstan:
47-
name: PHP Stan
48-
runs-on: ubuntu-latest
49-
50-
steps:
51-
- uses: actions/checkout@v5
52-
53-
- name: Setup PHP with PECL extension
54-
uses: shivammathur/setup-php@v2
55-
with:
56-
php-version: '8.4'
57-
58-
- name: Validate composer.json and composer.lock
59-
run: composer validate --strict
60-
61-
- name: Cache Composer packages
62-
id: composer-cache
63-
uses: actions/cache@v4
64-
with:
65-
path: vendor
66-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
67-
restore-keys: |
68-
${{ runner.os }}-php-
69-
70-
- name: Install dependencies
71-
run: composer install --prefer-dist --no-progress
21+
- name: Run Checks
22+
run: |
23+
composer run-script phplint
24+
composer run-script phpstan
25+
composer run-script phpcs
7226
73-
- name: Run PHP Stan
74-
run: composer run-script phpstan
75-
76-
- name: Check Info Failure
77-
uses: rjstone/discord-webhook-notify@v1.0.4
78-
with:
79-
severity: error
80-
details: PHP Stan failed.
81-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
27+
- name: Notify Failure
8228
if: failure()
83-
84-
phpcs:
85-
name: PHP CodeSniffer
86-
runs-on: ubuntu-latest
87-
88-
steps:
89-
- uses: actions/checkout@v5
90-
91-
- name: Setup PHP with PECL extension
92-
uses: shivammathur/setup-php@v2
93-
with:
94-
php-version: '8.4'
95-
96-
- name: Validate composer.json and composer.lock
97-
run: composer validate --strict
98-
99-
- name: Cache Composer packages
100-
id: composer-cache
101-
uses: actions/cache@v4
102-
with:
103-
path: vendor
104-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
105-
restore-keys: |
106-
${{ runner.os }}-php-
107-
108-
- name: Install dependencies
109-
run: composer install --prefer-dist --no-progress
110-
111-
- name: Run PHP Codesniffer
112-
run: composer run-script phpcs
113-
114-
- name: Check Info Failure
11529
uses: rjstone/discord-webhook-notify@v1.0.4
11630
with:
11731
severity: error
118-
details: CodeSniffer failed.
32+
details: Static Analysis (Lint/Stan/CS) failed.
11933
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
120-
if: failure()
12134

122-
phpunit:
123-
name: PHP Unit Test
124-
needs:
125-
- phplint
126-
- phpstan
127-
- phpcs
35+
# 2. Tests (Unit & Functional getrennt, da Functional DB braucht)
36+
tests:
37+
name: PHP Tests
38+
needs: static-analysis
12839
runs-on: ubuntu-latest
129-
130-
steps:
131-
- uses: actions/checkout@v5
132-
133-
- name: Setup PHP with PECL extension
134-
uses: shivammathur/setup-php@v2
135-
with:
136-
php-version: '8.4'
137-
138-
- name: Validate composer.json and composer.lock
139-
run: composer validate --strict
140-
141-
- name: Cache Composer packages
142-
id: composer-cache
143-
uses: actions/cache@v4
144-
with:
145-
path: vendor
146-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
147-
restore-keys: |
148-
${{ runner.os }}-php-
149-
150-
- name: Install dependencies
151-
run: composer install --prefer-dist --no-progress
152-
153-
- name: Run PHP Unit Test
154-
run: composer run-script unittest
155-
156-
- name: Test Info Failure
157-
uses: rjstone/discord-webhook-notify@v1.0.4
158-
with:
159-
severity: error
160-
details: PHP Unit Test failed.
161-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
162-
if: failure()
163-
164-
phpfunctional:
165-
name: PHP Functional Test
166-
needs:
167-
- phplint
168-
- phpstan
169-
- phpcs
170-
runs-on: ubuntu-latest
171-
env:
172-
DB_DATABASE: db
173-
DB_USERNAME: dev
174-
DB_PASSWORD: dev
175-
DB_HOST: 127.0.0.1
176-
DB_PORT: 3306
177-
MYSQL_ALLOW_EMPTY_PASSWORD: false
178-
MYSQL_ROOT_PASSWORD: root
179-
MYSQL_DATABASE: db
180-
APP_ENV: action
18140
services:
182-
database-testing:
41+
mariadb:
18342
image: mariadb:latest
18443
env:
185-
MYSQL_ALLOW_EMPTY_PASSWORD: false
18644
MYSQL_ROOT_PASSWORD: root
18745
MYSQL_DATABASE: db
18846
MYSQL_USER: dev
18947
MYSQL_PASSWORD: dev
190-
ports:
191-
- 3306:3306
48+
ports: ["3306:3306"]
19249
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
50+
env:
51+
DB_DATABASE: db
52+
DB_USERNAME: dev
53+
DB_PASSWORD: dev
54+
DB_HOST: 127.0.0.1
55+
APP_ENV: action
19356
steps:
19457
- uses: actions/checkout@v5
58+
- name: Setup Environment
59+
uses: ./.github/actions/setup-php-composer
19560

196-
- name: Install PHP with extensions.
197-
uses: shivammathur/setup-php@v2
198-
with:
199-
php-version: 8.4
200-
extensions: pdo
201-
ini-values: date.timezone='UTC'
202-
- name: Validate composer.json and composer.lock
203-
run: composer validate --strict
204-
205-
- name: Cache Composer packages
206-
id: composer-cache
207-
uses: actions/cache@v4
208-
with:
209-
path: vendor
210-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
211-
restore-keys: |
212-
${{ runner.os }}-php-
213-
214-
- name: Install dependencies
215-
run: composer install --prefer-dist --no-progress
61+
- name: Run Unit Tests
62+
run: composer run-script unittest
21663

217-
- name: Run PHP Functional Test
64+
- name: Run Functional Tests
21865
run: composer run-script functionaltest
21966

220-
- name: Test Info Failure
67+
- name: Notify Failure
68+
if: failure()
22169
uses: rjstone/discord-webhook-notify@v1.0.4
22270
with:
22371
severity: error
224-
details: Functional Test failed.
72+
details: PHP Tests failed.
22573
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
226-
if: failure()
22774

228-
deployment_of_stormannsgal_to_develope:
229-
name: Deploy Build
230-
needs:
231-
- phpcs
232-
- phplint
233-
- phpstan
234-
- phpunit
235-
- phpfunctional
75+
# 3. Deployment
76+
deploy:
77+
name: Deploy to Dev
78+
needs: tests
23679
runs-on: ubuntu-latest
23780
steps:
238-
- name: Get latest code
239-
uses: actions/checkout@v5
81+
- uses: actions/checkout@v5
24082

241-
- name: Setup PHP with PECL extension
242-
uses: shivammathur/setup-php@v2
83+
- name: Setup Environment (No Dev)
84+
uses: ./.github/actions/setup-php-composer
24385
with:
244-
php-version: '8.4'
245-
246-
- name: Install Composer Dependencies
247-
run: composer install --prefer-dist --no-progress --no-dev
86+
install-flags: '--prefer-dist --no-progress --no-dev'
24887

249-
- name: Run create openapi Data
88+
- name: Build OpenAPI
25089
run: composer run-script openapi
25190

252-
- name: rsync deployments
91+
- name: Deploy via rsync
25392
uses: burnett01/rsync-deployments@7.0.1
25493
with:
25594
switches: -avz --no-o --no-g --no-perms --no-t --omit-dir-times --delete --exclude-from='.rsync-exclude'
256-
path: /
25795
remote_path: ${{ secrets.DEPLOY_PATH_API_DEV }}
25896
remote_host: ${{ secrets.DEPLOY_HOST }}
25997
remote_port: ${{ secrets.DEPLOY_PORT }}
26098
remote_user: ${{ secrets.DEPLOY_USER }}
26199
remote_key: ${{ secrets.DEPLOY_KEY }}
262100
remote_key_pass: ${{ secrets.DEPLOY_KEY_PASS }}
263101

264-
- name: Clear remote cache folder
102+
- name: Clear Cache
265103
uses: appleboy/ssh-action@v1.2.2
266104
with:
267105
host: ${{ secrets.DEPLOY_HOST }}
@@ -270,18 +108,10 @@ jobs:
270108
passphrase: ${{ secrets.DEPLOY_KEY_PASS }}
271109
script: rm -rf ${{ secrets.DEPLOY_PATH_API_DEV }}/data/cache/*
272110

273-
- name: Deploay Info Success
111+
- name: Deployment Notification
112+
if: always()
274113
uses: rjstone/discord-webhook-notify@v1.0.4
275114
with:
276-
severity: info
277-
details: Successful deployment on build https://dev.ownhackathon.de/api/docs
115+
severity: ${{ job.status == 'success' && 'info' || 'error' }}
116+
details: ${{ job.status == 'success' && 'Successful deployment to dev!' || 'Deployment failed!' }}
278117
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
279-
if: success()
280-
281-
- name: Deplay Info Failure
282-
uses: rjstone/discord-webhook-notify@v1.0.4
283-
with:
284-
severity: error
285-
details: Failure deployment on develope.
286-
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
287-
if: failure()

0 commit comments

Comments
 (0)