-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (116 loc) · 4.36 KB
/
ci.yaml
File metadata and controls
140 lines (116 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: CI/CD
on:
push:
tags: [ '*.*.*' ]
branches: [ master ]
pull_request:
branches: [ master ]
release:
types: [ published ]
env:
COMPOSE_FILE: compose.yaml
COMPOSE_PROJECT_NAME: php-library-ci
jobs:
architecture:
name: Architecture
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
run: ln -s .env.dist .env
- name: Setup environment
run: docker compose run --build --remove-orphans --entrypoint='/usr/src/app/vendor/bin/deptrac analyse --config-file=deptrac.yaml' run-deptrac
security:
name: Security
runs-on: ubuntu-latest
needs: [ architecture ]
strategy:
fail-fast: false
matrix:
PHP_VERSION: [ 71, 80, 85 ]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
run: ln -s .env.dist .env
- name: Dependency vulnerability check
run: docker compose run -v "$PWD:/app" --build --remove-orphans --entrypoint="composer audit" run-tests
- name: Install Composer dependencies
run: docker compose run -v "$PWD:/app" --build --remove-orphans --entrypoint="composer install" run-tests
- name: PHP Security Checker
uses: symfonycorp/security-checker-action@v5
quality:
name: Code quality
runs-on: ubuntu-latest
needs: [ security ]
strategy:
fail-fast: false
matrix:
PHP_VERSION: [ 71, 80, 85 ]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
run: |
export PHP_VERSION="${{ matrix.PHP_VERSION }}"
sed -e "s/PHP_VERSION=.*/PHP_VERSION=$PHP_VERSION/" ./.env.dist > .env
- name: Install Composer dependencies
run: |
export PHP_VERSION="${{ matrix.PHP_VERSION }}"
docker compose run -v "$PWD:/app" --build --remove-orphans --env-from-file .env -e "PHP_VERSION=${PHP_VERSION}" --entrypoint="bash -c 'composer install ; rm composer.lock'" run-tests
- name: Run Psalm
run: |
export PHP_VERSION="${{ matrix.PHP_VERSION }}"
docker run -v "$PWD:/app" -v "$PWD/vendor${PHP_VERSION}:/app/vendor" --rm ghcr.io/danog/psalm:latest /composer/vendor/bin/psalm --no-cache
- name: Run PHPStan
run: |
export PHP_VERSION="${{ matrix.PHP_VERSION }}"
docker run -v "$PWD:/app" -v "$PWD/vendor${PHP_VERSION}:/app/vendor" --rm ghcr.io/phpstan/phpstan analyse /app/src --configuration phpstan.neon --error-format=github
tests:
name: Tests
runs-on: ubuntu-latest
needs: [security]
strategy:
fail-fast: false
matrix:
PHP_VERSION: [ 71 , 80, 85 ]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
run: ln -s .env.dist .env
- name: Run PHPUnit with Coverage
run: |
sudo apt-get update ;
sudo apt-get install -y ansifilter;
chmod o+w "$GITHUB_STEP_SUMMARY"
export PHP_VERSION="${{ matrix.PHP_VERSION }}"
export CONFIGURATION_FILE="/usr/src/app/phpunit.php$(( PHP_VERSION == 85 ? 80 : PHP_VERSION )).xml.dist"
sudo mkdir -m o+w -p ./var
docker compose run \
-e PHP_VERSION="${PHP_VERSION}" -e XDEBUG_MODE=coverage \
--build --remove-orphans \
--entrypoint="bash -c 'composer install ; /usr/src/app/vendor/bin/phpunit --configuration \"$CONFIGURATION_FILE\" --coverage-text | tee -a /usr/src/app/var/tests-report'" \
run-tests
{
echo '```'
cat ./var/tests-report | ansifilter
echo '```'
} > "$GITHUB_STEP_SUMMARY"
build-and-publish:
name: Build and Publish
runs-on: ubuntu-latest
needs: [quality, tests, security]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Publish to Packagist
env:
PACKAGIST_USERNAME: ${{ secrets.PACKAGIST_USERNAME }}
PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }}
run: |
curl -f -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $PACKAGIST_USERNAME:$PACKAGIST_TOKEN" \
'https://packagist.org/api/update-package' \
-d "{\"repository\": {\"url\": \"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY\"}}"