forked from oxsecurity/megalinter
-
Notifications
You must be signed in to change notification settings - Fork 0
431 lines (393 loc) · 16.2 KB
/
Copy pathdeploy-DEV.yml
File metadata and controls
431 lines (393 loc) · 16.2 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
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
---
#########################
#########################
## Deploy Docker Image ##
#########################
#########################
#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#
#######################################
# Start the job on all push to main #
#######################################
name: "Build & Deploy - DEV"
on:
push:
branches-ignore:
- main
paths-ignore:
- .github/CONTRIBUTING.md
- CHANGELOG.md
- README.md
- .github/workflows/slash-command-dispatch.yml
- .github/workflows/help-command.yml
- .github/workflows/build-command.yml
pull_request:
###############
# Set the Job #
###############
permissions: {}
concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
##################################################################
# Producer: build the image, populate GHA buildx cache (no push) #
##################################################################
build:
name: Build Docker Image - DEV
runs-on: ubuntu-latest
permissions:
contents: read
# Prevent duplicate run from happening when a forked push is committed
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && !contains(github.event.head_commit.message, 'skip deploy')
timeout-minutes: 90
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
image-version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
dockerfile: ${{ steps.setup.outputs.dockerfile }}
cache-scope: ${{ steps.setup.outputs.cache-scope }}
build-args: ${{ steps.setup.outputs.build-args }}
is-quick: ${{ steps.setup.outputs.is-quick }}
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free Disk space
shell: bash
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
sudo rm -rf /opt/ghc
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache/CodeQL # large cache
sudo rm -rf /opt/hostedtoolcache/go # Go toolcache
- name: Docker Metadata action
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
id: meta
with:
images: |
${{ github.repository }}
- name: Select Dockerfile, cache scope, and build args
id: setup
shell: bash
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
META_CREATED: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
META_VERSION: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
META_REVISION: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
run: |
if [[ "${COMMIT_MSG}" == *"quick build"* ]]; then
{
echo "is-quick=true"
echo "dockerfile=Dockerfile-quick"
echo "cache-scope=dev-quick"
echo "build-args<<EOF"
echo "BUILD_DATE=${META_CREATED}"
echo "BUILD_VERSION=${META_VERSION}"
echo "BUILD_REVISION=${META_REVISION}"
echo "MEGALINTER_BASE_IMAGE=ghcr.io/oxsecurity/megalinter:beta"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
else
{
echo "is-quick=false"
echo "dockerfile=Dockerfile"
echo "cache-scope=dev-main"
echo "build-args<<EOF"
echo "BUILD_DATE=${META_CREATED}"
echo "BUILD_VERSION=${META_VERSION}"
echo "BUILD_REVISION=${META_REVISION}"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
# Build once and export the image as a Docker tarball.
# DEV is read-only on the layer cache: it consumes the warm caches
# produced by the BETA workflow on main and never writes back. Writing
# a fresh cache for a throwaway PR branch costs ~14 min of cache export
# per build that nobody else reads, so we skip `cache-to` entirely here.
- name: Build MegaLinter Docker Image
id: docker_build
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
continue-on-error: true
with:
context: .
file: ${{ steps.setup.outputs.dockerfile }}
platforms: linux/amd64
build-args: ${{ steps.setup.outputs.build-args }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=beta-main,ignore-error=true
outputs: type=docker,dest=/tmp/megalinter-image.tar,compression=zstd,compression-level=3,force-compression=true
timeout-minutes: 90
# Fallback: if the cached build above failed (e.g. GHA cache returned a
# stale manifest pointing to an evicted blob — buildx surfaces this as
# 'ERROR: blob sha256:...: not found'), rebuild from scratch with no
# cache-from. Slower but never blocks on cache corruption.
- name: Build MegaLinter Docker Image (no-cache fallback)
if: steps.docker_build.outcome == 'failure'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
with:
context: .
file: ${{ steps.setup.outputs.dockerfile }}
platforms: linux/amd64
build-args: ${{ steps.setup.outputs.build-args }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
tags: ${{ steps.meta.outputs.tags }}
outputs: type=docker,dest=/tmp/megalinter-image.tar,compression=zstd,compression-level=3,force-compression=true
timeout-minutes: 90
- name: Upload image artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: megalinter-image
path: /tmp/megalinter-image.tar
retention-days: 1
if-no-files-found: error
compression-level: 0
###############################################################
# Consumer: Run linter test cases against the cached image #
###############################################################
test-cases:
name: Run Test Cases - DEV
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
# Require writing security events to upload SARIF file to security tab
security-events: write
timeout-minutes: 120
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free Disk space
shell: bash
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /opt/hostedtoolcache/go
- name: Download image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: megalinter-image
path: /tmp
- name: Load Docker image
shell: bash
run: |
set -euo pipefail
docker load -i /tmp/megalinter-image.tar
rm -f /tmp/megalinter-image.tar
docker image ls
- name: Run Test Cases
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
GH_REPOSITORY: ${{ github.repository }}
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
COMMIT_MSG: ${{ github.event.head_commit.message }}
DOCKER_IMAGE: ${{ needs.build.outputs.image-tag }}
GH_SHA: ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GITHUB_REPOSITORY=$([ "$EVENT_NAME" == "pull_request" ] && echo "$PR_HEAD_REPO" || echo "$GH_REPOSITORY")
GITHUB_BRANCH=$([ "$EVENT_NAME" == "pull_request" ] && echo "$HEAD_REF" || echo "$REF_NAME")
CI_ENV="$(bash <(curl -s https://codecov.io/env)) -e GITHUB_ACTIONS"
export CI_ENV
TEST_KEYWORDS_TO_USE=""
if [[ "${COMMIT_MSG}" == *"TEST_KEYWORDS="* ]]; then
TEST_KEYWORDS_TO_USE=${COMMIT_MSG#*TEST_KEYWORDS=}
echo "Run only tests with keywords ${TEST_KEYWORDS_TO_USE}"
if [[ "${TEST_KEYWORDS_TO_USE}" =~ $'\r' ]]; then
echo "Problem while parsing test keywords: switch back to all tests"
TEST_KEYWORDS_TO_USE=""
fi
fi
docker image ls
# shellcheck disable=SC2086
docker run $CI_ENV -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER="${GH_SHA}" -e OUTPUT_DETAIL=detailed -e GITHUB_SHA="${GH_SHA}" -e GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" -e GITHUB_BRANCH="${GITHUB_BRANCH}" -e GITHUB_TOKEN="${GITHUB_TOKEN}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v "${GITHUB_WORKSPACE}:/tmp/lint" "${DOCKER_IMAGE}"
timeout-minutes: 120
- name: Archive production artifacts (test-cases)
if: success() || failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: MegaLinter reports (test-cases)
include-hidden-files: "true"
path: |
megalinter-reports
mega-linter.log
linter-helps.json
linter-versions.json
###############################################################
# Consumer: Run megalinter against the entire code base #
###############################################################
run-all-code:
name: Run against all code base - DEV
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
if: needs.build.outputs.is-quick != 'true'
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free Disk space
shell: bash
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /opt/hostedtoolcache/go
- name: Download image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: megalinter-image
path: /tmp
- name: Load Docker image
shell: bash
run: |
set -euo pipefail
docker load -i /tmp/megalinter-image.tar
rm -f /tmp/megalinter-image.tar
docker image ls
- name: Run against all code base
shell: bash
env:
DOCKER_IMAGE: ${{ needs.build.outputs.image-tag }}
GH_REPOSITORY: ${{ github.repository }}
GH_SHA: ${{ github.sha }}
GH_TOKEN_VALUE: ${{ github.token }}
GH_RUN_ID: ${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: docker run -e GITHUB_REPOSITORY="${GH_REPOSITORY}" -e GITHUB_SHA="${GH_SHA}" -e GITHUB_TOKEN="${GH_TOKEN_VALUE}" -e GITHUB_RUN_ID="${GH_RUN_ID}" -e GITHUB_TOKEN="${GITHUB_TOKEN}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v "${GITHUB_WORKSPACE}:/tmp/lint" "${DOCKER_IMAGE}"
timeout-minutes: 15
- name: Archive production artifacts (run-all-code)
if: success() || failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: MegaLinter reports (run-all-code)
include-hidden-files: "true"
path: |
megalinter-reports
mega-linter.log
linter-helps.json
linter-versions.json
###############################################################
# Consumer: mega-linter-runner tests against the cached image #
###############################################################
runner-tests:
name: mega-linter-runner tests - DEV
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
if: needs.build.outputs.is-quick != 'true'
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free Disk space
shell: bash
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /opt/hostedtoolcache/go
- name: Download image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: megalinter-image
path: /tmp
- name: Load Docker image
shell: bash
run: |
set -euo pipefail
docker load -i /tmp/megalinter-image.tar
rm -f /tmp/megalinter-image.tar
docker image ls
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24.x"
- name: Install NPM dependencies
run: cd mega-linter-runner && yarn install --frozen-lockfile && npm link
- name: Run mega-linter-runner tests
env:
MEGALINTER_RELEASE: ${{ needs.build.outputs.image-version }}
MEGALINTER_IMAGE: ${{ needs.build.outputs.image-tag }}
run: cd mega-linter-runner && MEGALINTER_RELEASE="${MEGALINTER_RELEASE}" MEGALINTER_IMAGE="${MEGALINTER_IMAGE}" MEGALINTER_NO_DOCKER_PULL=true npm run test
###############################################################
# Consumer: Trivy vulnerability scan #
###############################################################
trivy:
name: Trivy scan - DEV
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free Disk space
shell: bash
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /opt/hostedtoolcache/go
- name: Download image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: megalinter-image
path: /tmp
- name: Load Docker image
shell: bash
run: |
set -euo pipefail
docker load -i /tmp/megalinter-image.tar
rm -f /tmp/megalinter-image.tar
docker image ls
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
# renovate: datasource=github-releases depName=aquasecurity/trivy
version: "v0.72.0"
image-ref: "${{ needs.build.outputs.image-tag }}"
format: 'table'
exit-code: '1'
ignore-unfixed: true
scanners: vuln
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
timeout: 15m0s
# - name: Run OSV-Scanner vulnerability scanner
# uses: google/osv-scanner-action/osv-scanner-action@v2.3.5
# with:
# scan-args: |-
# --docker ${{ needs.build.outputs.image-tag }}