-
Notifications
You must be signed in to change notification settings - Fork 1
607 lines (542 loc) · 19.8 KB
/
lint-test.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
---
# Lint the code base and launch unit test at each push or pull request
name: Lint and test
on: # yamllint disable-line rule:truthy
push:
# execute when pushing only branches, not tags
branches:
- "**"
# avoid infinite loop for auto created PRs
- "!update/pre-commit-*"
tags:
- "**"
workflow_dispatch:
# cancel previous build if several pushes
concurrency:
group: |
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
# Apply linter fixes configuration
# When active, APPLY_FIXES must also be defined as
# environment variable (in github/workflows/mega-linter.yml
# or other CI tool)
APPLY_FIXES: all
# Decide which event triggers application of fixes in a
# commit or a PR (pull_request, push, all)
APPLY_FIXES_EVENT: all
# If APPLY_FIXES is used, defines if the fixes are
# directly committed (commit) or posted in a PR (pull_request)
APPLY_FIXES_MODE: pull_request
# variables to compute complex conditions
COND_UPDATED_SOURCES: false
COND_APPLY_FIXES_NEEDED: false
jobs:
# -------------------------------------------------------
# Build frankenphp docker image
# -------------------------------------------------------
build-frankenphp-docker-image:
runs-on: ubuntu-22.04
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
# needed by ncipollo/release-action
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# overall process
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-frankenphp-docker-image
status: pending
- name: Set env vars
id: vars
# shellcheck disable=SC2129
run: |
(
echo "updateDate=$(date '+%Y-%m')"
echo "job_tag=${{github.run_id}}"
echo "image_tag=latest"
echo "image_name=scrasnups/frankenphp-composer-onbuild"
echo "branch_name=${GITHUB_REF##*/}"
) >> "${GITHUB_ENV}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{env.image_name}}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- uses: docker/build-push-action@v5
continue-on-error: false
with:
load: true
context: command-configurator
file: command-configurator/Dockerfile
pull: true
github-token: ${{ github.token }}
build-args: |
UPDATE_DATE: "${{ env.updateDate }}"
target: base
tags: |
${{ env.image_name }}:${{ env.image_tag }}
cache-from: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
cache-to: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }},mode=max
- name: Check image
continue-on-error: false
run: |
docker run --rm "${{ env.image_name }}:${{ env.image_tag }}" php --version
- uses: docker/build-push-action@v5
continue-on-error: false
with:
load: true
context: command-configurator
file: command-configurator/Dockerfile
target: base
push: true
github-token: ${{ github.token }}
tags: |
${{ env.image_name }}:${{ env.image_tag }}
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-frankenphp-docker-image
status: ${{ job.status }}
# overall process
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
with:
name: build-frankenphp-binary-file
status: pending
- name: Ensure vendor dir can be written in the binary
continue-on-error: false
if: ${{ !cancelled() && startsWith(github.ref, 'refs/tags/') }}
run: |
echo ".git/" > .dockerignore
- uses: docker/build-push-action@v5
continue-on-error: false
if: ${{ !cancelled() && startsWith(github.ref, 'refs/tags/') }}
with:
load: true
context: command-configurator
file: command-configurator/Dockerfile
target: build-bin-file
pull: true
push: false
github-token: ${{ github.token }}
build-args: |
UPDATE_DATE: "${{ env.updateDate }}"
cache-from: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
tags: static-app
- name: Check and copy binary
continue-on-error: false
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
run: |
set -exo pipefail
storeContainer="$(docker create --name static-app-tmp static-app)"
docker cp "${storeContainer}:/go/src/app/dist/frankenphp-linux-x86_64" my-app
docker rm static-app-tmp
ls -al my-app
mv my-app/my-app command-configurator
- name: Special Release
uses: ncipollo/release-action@v1
with:
name: latest-command-configurator
omitBody: true
allowUpdates: true
artifacts: "command-configurator"
artifactErrorsFailBuild: true
replacesArtifacts: true
prerelease: true
generateReleaseNotes: true
skipIfReleaseExists: false
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
with:
name: build-frankenphp-binary-file
status: ${{ job.status }}
# -------------------------------------------------------
# Build bash docker images
# -------------------------------------------------------
build-bash-docker-images:
runs-on: ubuntu-22.04
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
strategy:
fail-fast: true
matrix:
vendor:
- ubuntu
- alpine
bashTarVersion:
- "4.4"
- "5.0"
- "5.3"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# overall process
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-bash-tools
status: pending
- name: Set env vars
id: vars
# shellcheck disable=SC2129
run: |
(
echo "job_tag=${{github.run_id}}-${{matrix.vendor}}-${{matrix.bashTarVersion}}"
echo "image_tag=bash-tools-${{matrix.vendor}}-${{matrix.bashTarVersion}}"
echo "image_name=scrasnups/build"
echo "branch_name=${GITHUB_REF##*/}"
if [[ "${{ matrix.vendor }}" = "ubuntu" ]]; then
echo "bashImage=ubuntu:20.04"
else
echo "bashImage=amd64/bash:${{ matrix.bashTarVersion }}-alpine3.19"
fi
) >> "${GITHUB_ENV}"
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-${{ env.image_tag }}
status: pending
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{env.image_name}}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- uses: docker/build-push-action@v5
continue-on-error: false
with:
load: true
context: .docker
file: .docker/Dockerfile.${{ matrix.vendor }}
pull: true
github-token: ${{ github.token }}
tags: |
${{ env.image_name }}:${{ env.image_tag }}
build-args: |
BASH_IMAGE: "${{ env.bashImage }}"
BASH_TAR_VERSION: "${{ matrix.bashTarVersion }}"
cache-from: type=gha,scope=${{ env.image_tag }}
cache-to: type=gha,mode=max,scope=${{ env.image_tag }}
- name: Check image
continue-on-error: false
run: |
docker run --rm "${{ env.image_name }}:${{ env.image_tag }}" bash --version
- uses: docker/build-push-action@v5
continue-on-error: false
with:
load: true
context: .docker
file: .docker/Dockerfile.${{ matrix.vendor }}
push: true
github-token: ${{ github.token }}
tags: |
${{ env.image_name }}:${{ env.image_tag }}
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-to: type=gha,mode=max,scope=${{ env.image_tag }}
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-${{ env.image_tag }}
status: ${{ job.status }}
# -------------------------------------------------------
# Pre-commit
# -------------------------------------------------------
pre-commit:
runs-on: ubuntu-22.04
needs: [build-bash-docker-images]
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: crazy-max/ghaction-import-gpg@v6
if: ${{ success() }}
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- uses: tibdex/github-app-token@v1
if: ${{ success() }}
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: pre-commit-megalinter
status: pending
- name: Set env vars
id: vars
# shellcheck disable=SC2129
run: |
(
echo "branch_name=${GITHUB_REF##*/}"
) >> "${GITHUB_ENV}"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- uses: fchastanet/[email protected]
- name: Install requirements
run: |
set -exo pipefail
bin/installRequirements
- name: Run pre-commit
uses: pre-commit/[email protected]
id: preCommit
with:
extra_args: >-
-c .pre-commit-config-github.yaml -a --hook-stage manual
- name: MegaLinter
id: ml
if: ${{ !cancelled() }}
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/flavors/
uses: oxsecurity/megalinter/flavors/terraform@v7
# All available variables are described in documentation
# https://megalinter.io/configuration/
env:
# Validates all source when push on master,
# else just the git diff with master.
# Override with true if you always want to lint all sources
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MEGALINTER_CONFIG: .mega-linter-githubAction.yml
CI_MODE: 1
- name: Upload MegaLinter artifacts
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
- name: MegaLinter/Precommit has updated sources
if: >
steps.preCommit.outcome == 'failure' || (
steps.ml.outputs.has_updated_sources == 1 && (
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
)
)
run: |
echo "COND_UPDATED_SOURCES=true" >> "${GITHUB_ENV}"
- name: is apply fixes needed ?
if: >
env.APPLY_FIXES_MODE == 'pull_request' && (
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name ==
github.repository
)
run: |
echo "COND_APPLY_FIXES_NEEDED=true" >> "${GITHUB_ENV}"
- name: Create Pull Request
id: cpr
# prettier-ignore
if: >
env.COND_UPDATED_SOURCES == 'true' &&
env.COND_APPLY_FIXES_NEEDED == 'true' &&
!contains(github.event.head_commit.message, 'skip fix')
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate-token.outputs.token }}
committer: fchastanet <[email protected]>
branch: update/pre-commit-fixes-${{ env.branch_name }}
delete-branch: true
title: lint fixes
commit-message: Auto-update lint fixes
body: |
some auto fixes have been generated during pre-commit run
labels: pre-commit-fixes
- name: Print Pull request created
if: |
steps.cpr.outputs.pull-request-number &&
steps.cpr.outcome == 'success'
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
if: ${{ always() }}
with:
name: pre-commit-megalinter
status: ${{ job.status }}
# -------------------------------------------------------
# Unit tests
# -------------------------------------------------------
unit-tests:
runs-on: ubuntu-22.04
needs: [build-bash-docker-images]
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
# needed by mikepenz/action-junit-report@v4
checks: write
strategy:
fail-fast: true
matrix:
vendor:
- ubuntu
- alpine
bashTarVersion:
- "4.4"
- "5.0"
- "5.3"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: crazy-max/ghaction-import-gpg@v6
if: ${{ success() }}
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- uses: tibdex/github-app-token@v1
if: ${{ success() }}
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: unit-tests-${{matrix.vendor}}-${{matrix.bashTarVersion}}
status: pending
- name: Set env vars
id: vars
# shellcheck disable=SC2129
run: |
(
echo "job_tag=${{github.run_id}}-${{matrix.vendor}}-${{matrix.bashTarVersion}}"
echo "image_tag=bash-tools-${{matrix.vendor}}-${{matrix.bashTarVersion}}"
echo "image_name=scrasnups/build"
echo "branch_name=${GITHUB_REF##*/}"
if [[ "${{ matrix.vendor }}" = "ubuntu" ]]; then
echo "bashImage=ubuntu:20.04"
echo "batsOptions=-j 30"
else
echo "bashImage=amd64/bash:${{ matrix.bashTarVersion }}-alpine3.19"
echo "batsOptions=-j 30 --filter-tags '!ubuntu_only'"
fi
) >> "${GITHUB_ENV}"
- name: run unit tests
id: unitTests
run: |
set -exo pipefail
bin/installRequirements
chmod 777 logs
docker pull "scrasnups/build:${{env.image_tag}}"
status=0
docker run --rm \
-e KEEP_TEMP_FILES=0 \
-e BATS_FIX_TEST=0 \
-e USER_ID="1000" \
-e GROUP_ID="1000" \
--user "www-data:www-data" \
-w /bash \
-v "$(pwd):/bash" \
"scrasnups/build:${{env.image_tag}}" \
/bash/vendor/bats/bin/bats \
${{env.batsOptions}} \
--formatter junit -o logs -r src 2>&1 |
tee "logs/bats-${{ env.job_tag }}.log" || status=$?
awk '/xml version="1.0"/{flag=1} flag; /<\/testsuites>/{flag=0}' \
"logs/bats-${{ env.job_tag }}.log" >"logs/junit-${{ env.job_tag }}.xml"
exit "${status}"
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: ${{ always() }}
with:
token: ${{ github.token }}
check_name: JUnit ${{ env.image_tag }}
fail_on_failure: true
require_tests: true
require_passed_tests: true
report_paths: "logs/**.xml"
- name: Upload Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Results ${{ env.image_tag }}
path: |
logs/**
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: unit-tests-${{matrix.vendor}}-${{matrix.bashTarVersion}}
status: ${{ job.status }}
overallTestResults:
name: "Overall Tests Results"
if: ${{ always() }}
needs: [unit-tests]
runs-on: ubuntu-22.04
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
steps:
# run this action to get the workflow conclusion
# You can get the conclusion via env (env.WORKFLOW_CONCLUSION)
- uses: AbsoLouie/[email protected]
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-bash-tools
# neutral, success, skipped, cancelled, timed_out, action_required, failure
status: ${{ env.WORKFLOW_CONCLUSION }}