-
Notifications
You must be signed in to change notification settings - Fork 0
279 lines (246 loc) · 9.92 KB
/
run-tests.yml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: Run tests
on: [pull_request]
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
permissions:
contents: write
checks: write
pull-requests: write
actions: read
statuses: write
steps:
- name: Checkout Code
id: checkout
uses: actions/checkout@v4
- name: Extract PHP Version
id: php
uses: docker://ghcr.io/un-ocha/actions:extract-php-version-main
with:
docker_file: 'docker/Dockerfile'
docker_image: 'public.ecr.aws/unocha/php-k8s'
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
if: ${{ !env.ACT }}
with:
php-version: ${{ steps.php.outputs.php_version }}
tools: composer
env:
fail-fast: true
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
if: ${{ env.ACT }}
with:
php-version: ${{ steps.php.outputs.php_version }}
tools: composer
env:
fail-fast: true
runner: self-hosted
- name: Software versions
id: versions
uses: cafuego/command-output@main
with:
run: |
php --version && composer --version
- name: Composer Validate
id: validate
uses: cafuego/command-output@main
with:
run: |
composer validate --no-check-version --strict
env:
fail-fast: true
- name: Composer Audit
id: audit
uses: cafuego/command-output@main
with:
run: |
composer audit
env:
fail-fast: true
- name: Code Lint
id: lint
uses: cafuego/command-output@main
with:
run: |
test ! -d ./src || find -L ./src -iregex '.*\.\(php\)$' -print0 | xargs -0 -n 1 -P 4 php -l
env:
fail-fast: true
- name: Configure AWS Credentials
id: aws
if: ${{ !env.ACT }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Public ECR
id: aws-login
if: ${{ !env.ACT }}
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: us-east-1
- name: Build Image
id: build
uses: cafuego/command-output@main
with:
run: |
make
env:
fail-fast: true
- name: Setup Environment
id: docker
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml up -d
sleep 4
docker ps -a
env:
fail-fast: true
- name: Install Environment
id: install
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console doctrine:database:drop --force
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console doctrine:database:create --if-not-exists -n
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console doctrine:schema:create -n
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console netbrothers:version --drop-version -n
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console netbrothers:version -n
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console hautelook:fixtures:load -n
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console cache:clear
env:
fail-fast: true
- name: Config Lint
id: symfony
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console lint:yaml config --parse-tags
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console lint:twig templates --env=prod
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console lint:xliff translations
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console lint:container
docker compose -f tests/docker-compose.yml exec -w /srv/www -T site ./bin/console doctrine:schema:validate --skip-sync -vvv --no-interaction
env:
fail-fast: true
- name: Unit Tests
id: phpunit
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -T site mkdir -p /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -T site chmod -R 777 /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -T site mkdir -p /srv/www/coverage
docker compose -f tests/docker-compose.yml exec -T site chmod -R 777 /srv/www/coverage
docker compose -f tests/docker-compose.yml exec -u appuser -T -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e DTT_BASE_URL=http://127.0.0.1 site ./bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --cache-result-file /tmp/phpunit-result-cache --debug
docker cp "$(docker compose -f tests/docker-compose.yml ps -q site)":/srv/www/html/build/logs/clover.xml .
env:
fail-fast: true
- name: Monitor coverage
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_path: "clover.xml"
threshold_alert: 10
threshold_warning: 50
threshold_metric: "lines"
- name: Post Comment
if: ${{ !env.ACT }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Composer Validate \`${{ steps.validate.outcome }}\`
#### Composer Audit \`${{ steps.audit.outcome }}\`
#### PHP Lint \`${{ steps.lint.outcome }}\`
#### Docker Build \`${{ steps.build.outcome }}\`
#### Environment Setup \`${{ steps.docker.outcome }}\`
#### Site Install \`${{ steps.install.outcome }}\`
#### Config Lint \`${{ steps.symfony.outcome }}\`
#### Unit Tests \`${{ steps.phpunit.outcome }}\`
<details><summary>Software Versions</summary>
\`\`\`${{ steps.versions.outputs.stdout }}\`\`\`
</details>
<details><summary>Composer Audit</summary>
\`\`\`${{ steps.audit.outputs.stdout }}\`\`\`
</details>
<details><summary>Config Lint</summary>
\`\`\`${{ steps.symfony.outputs.stdout }}\`\`\`
</details>
<details><summary>Unit Tests</summary>
\`\`\`${{ steps.phpunit.outputs.stdout }}\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Slack Success Notification
id: slack_success
if: ${{ !env.ACT && success() }}
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: '${{ vars.SLACK_CHANNEL }}'
payload: |
{
"text": "Tests passed for a pull request on ${{ github.repository }}",
"attachments": [
{
"color": "#00FF00",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pull request by @${{ github.triggering_actor }} to merge _${{ github.head_ref }}_ into _${{ github.base_ref }}_ on <${{ github.repositoryUrl }}|${{ github.repository }}> passed tests (<${{ github.event.pull_request.html_url }}|Review>)"
}
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Slack Failure Notification
id: slack_failure
if: ${{ !env.ACT && failure() }}
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: '${{ vars.SLACK_CHANNEL }}'
payload: |
{
"text": "Tests failed for a pull request on ${{ github.repository }}",
"attachments": [
{
"color": "#FF0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pull request by @${{ github.triggering_actor }} to merge _${{ github.head_ref }}_ into _${{ github.base_ref }}_ on <${{ github.repositoryUrl }}|${{ github.repository }}> failed tests (<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Review>)"
}
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Clean up
id: docker-clean-up
if: ${{ env.ACT }}
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml down
env:
fail-fast: true