-
Notifications
You must be signed in to change notification settings - Fork 0
343 lines (301 loc) · 10.6 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
---
# kics-scan disable=CWE-829
# 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
permissions: read-all
jobs:
# -------------------------------------------------------
# Pre-commit
# -------------------------------------------------------
pre-commit:
runs-on: ubuntu-22.04
permissions:
# needed by ouzi-dev/commit-status-updater@v2
statuses: write
# needed by megalinter
issues: write
# needed by megalinter
pull-requests: write
steps:
- uses: ouzi-dev/commit-status-updater@v2
with:
name: build-bash-tools
status: pending
- 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@v2
if: ${{ success() }}
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: ouzi-dev/commit-status-updater@v2
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
vendor/bash-tools-framework/bin/installRequirements
vendor/bash-tools-framework/bin/installRequirements
docker pull scrasnups/build:bash-tools-ubuntu-5.3
- 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: ${{ always() }}
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors/
uses: oxsecurity/megalinter/flavors/terraform@v8
# All available variables are described in documentation
# https://megalinter.io/latest/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@v7
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: ouzi-dev/commit-status-updater@v2
if: ${{ always() }}
with:
name: pre-commit-megalinter
status: ${{ job.status }}
# -------------------------------------------------------
# Unit tests
# -------------------------------------------------------
unit-tests:
runs-on: ubuntu-22.04
permissions:
# needed by ouzi-dev/commit-status-updater@v2
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@v2
if: ${{ success() }}
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: ouzi-dev/commit-status-updater@v2
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: install requirements
run: |
set -exo pipefail
chmod 777 logs
bin/installRequirements
vendor/bash-tools-framework/bin/installRequirements
- name: run unit tests
id: unitTests
run: |
set -exo pipefail
status=0
CI_MODE=1 ./test.sh "scrasnups/build:${{env.image_tag}}" \
${{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@v5
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: Checkstyle aggregation
uses: lcollins/[email protected]
with:
path: "logs/*.xml"
- name: Upload Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Results ${{ env.image_tag }}
path: |
logs/**
- uses: ouzi-dev/commit-status-updater@v2
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 ouzi-dev/commit-status-updater@v2
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: ouzi-dev/commit-status-updater@v2
with:
name: build-bash-tools
# neutral, success, skipped, cancelled, timed_out, action_required, failure
status: ${{ env.WORKFLOW_CONCLUSION }}