-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yml
More file actions
330 lines (328 loc) · 10.6 KB
/
Copy pathaction.yml
File metadata and controls
330 lines (328 loc) · 10.6 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
# yamllint disable rule:line-length
# yamllint disable rule:quoted-strings
---
name: mcvs-golang-action
description: |
The Mission Critical Vulnerability Scanner (MCVS) Golang action.
inputs:
build-tags:
description: "What kind of code should be checked, e.g. component, e2e"
code-coverage-expected:
default: "80"
description: |
The minimum code coverage.
code-coverage-opa-expected:
default: "80"
description: |
The minimum OPA code coverage.
code-coverage-timeout:
description: |
The duration before calculating the code-coverage times out.
github-token-for-downloading-private-go-modules:
description: |
Whether private go modules have to be downloaded.
go-version-file:
default: "go.mod"
description: |
The Path to the go.mod or go.work file.
golang-unit-tests-exclusions:
default: " "
description: |
The Golang paths that should be excluded from unit testing.
golangci-timeout:
description: |
The duration before golangci-lint times out. If <= 0, then the timeout is
disabled.
grype-version:
description: The grype version to be used by the anchore/scan-action.
gta-base-branch:
default: main
description: |
The base branch to compare changed code to.
gta-partial-testing:
default: false
description: |
Whether partial testing should be performed. Only changed packages will be
tested.
release-application-name:
description: |
The name of the application that has to be released.
release-architecture:
description: |
The architecture of the release, e.g. amd64, arm64, etc.
release-build-tags:
description: |
The build tags that have to be used when building the release. e.g. for \
AWS Lambda, the tag lambda.norpc is used.
release-dir:
description: |
The directory of the main.go file to be compiled and released.
release-os:
default: linux
description: |
The OS of the main.go file to be compiled and released.
release-type:
description: |
The type of the release, e.g. binary, zip, etc.
task-install:
default: no
description: |
Whether Task should be installed.
task-version:
default: 3.49.1
description: |
The Task version that has to be installed and used.
test-timeout:
description: |
The duration before a test times out. Note: this setting can be used for
various types of testing, such as unit, integration, etc.
testing-type:
description: |
The testing type, e.g. integration, unit or some other.
token:
description: |
A token could be used to pull private golang modules.
runs:
using: "composite"
steps:
#
# Install task and the golang version that has been defined in the go.mod
# file.
#
- uses: actions/setup-go@v6.3.0
if: |
inputs.release-dir != '' ||
inputs.task-install == 'yes' ||
inputs.testing-type == 'component' ||
inputs.testing-type == 'coverage' ||
inputs.testing-type == 'graphql-lint' ||
inputs.testing-type == 'integration' ||
inputs.testing-type == 'lint' ||
inputs.testing-type == 'mocks-tidy' ||
inputs.testing-type == 'opa' ||
inputs.testing-type == 'security-golang-modules' ||
inputs.testing-type == 'unit'
with:
go-version-file: ${{ inputs.go-version-file }}
cache: false
- name: install task
if: |
inputs.release-dir != '' ||
inputs.task-install == 'yes' ||
inputs.testing-type == 'component' ||
inputs.testing-type == 'coverage' ||
inputs.testing-type == 'graphql-lint' ||
inputs.testing-type == 'integration' ||
inputs.testing-type == 'lint' ||
inputs.testing-type == 'mcvs-texttidy' ||
inputs.testing-type == 'mocks-tidy' ||
inputs.testing-type == 'opa' ||
inputs.testing-type == 'security-golang-modules' ||
inputs.testing-type == 'unit'
shell: bash
run: |
if ! task --version | grep -q "Task version: v${{ inputs.task-version }}"; then
major_version=$(echo "${{ inputs.task-version }}" | sed -E 's/^([0-9]+).*/\1/')
go install github.com/go-task/task/v${major_version}/cmd/task@v${{ inputs.task-version }}
fi
echo "verifying that task can be found and run..."
task --version
- run: |
git config --global url.https://${{ inputs.github-token-for-downloading-private-go-modules }}@github.com/.insteadOf https://github.com/
shell: bash
if: ${{ inputs.github-token-for-downloading-private-go-modules != '' }}
- if: |
inputs.release-dir != '' ||
inputs.testing-type == 'component' ||
inputs.testing-type == 'coverage' ||
inputs.testing-type == 'integration' ||
inputs.testing-type == 'lint' ||
inputs.testing-type == 'mcvs-texttidy' ||
inputs.testing-type == 'mocks-tidy' ||
inputs.testing-type == 'unit'
run: |
go mod tidy
if [[ -n $(git diff --exit-code) ]]; then
echo "A discrepancy has been detected. Has 'go mod tidy' been issued?"
exit 1
fi
shell: bash
#
# Verify downloaded dependencies.
#
- name: verify golang modules
if: inputs.testing-type == 'security-golang-modules'
shell: bash
run: |
go mod verify
task remote:osv-scanner --yes
#
# Code security scanning.
#
# * Grype
#
- uses: anchore/scan-action@7037fa011853d5a11690026fb85feee79f4c946c # v7.3.2
if: inputs.token != '' && inputs.testing-type == 'security-grype'
with:
grype-version: ${{ inputs.grype-version }}
only-fixed: false
output-format: table
path: "."
severity-cutoff: high
#
# Run golangci-lint.
#
- name: golangci-lint
if: inputs.testing-type == 'lint'
shell: bash
env:
BUILD_TAGS: ${{ inputs.build-tags }}
GITHUB_TOKEN: ${{ inputs.token }}
GOLANGCI_LINT_RUN_TIMEOUT_MINUTES: ${{ inputs.golangci-timeout }}
run: |
task remote:golangci-lint --yes
#
# Run graphql-linter.
#
- name: graphql-lint
if: inputs.testing-type == 'graphql-lint'
shell: bash
run: |
task remote:graphql-lint --yes
#
# Run MCVS-texttidy.
#
- name: mcvs-texttidy
if: inputs.testing-type == 'mcvs-texttidy'
shell: bash
run: |
task remote:mcvs-texttidy --yes
#
# Run mocks-tidy.
#
- name: mocks-tidy
if: inputs.testing-type == 'mocks-tidy'
shell: bash
run: |
task remote:mocks-tidy --yes
#
# Run Regal for linting and OPA.
#
- name: regal and opa
if: inputs.testing-type == 'opa'
shell: bash
run: |
task remote:regal --yes
task remote:opa --yes
#
# Install digitalocean/gta if partial testing is enabled.
#
- name: install gta for partial testing
if: inputs.gta-partial-testing == true || inputs.gta-partial-testing == 'true'
shell: bash
run: |
task remote:gta-install --yes
#
# Unit tests.
#
- name: unit tests
if: inputs.testing-type == 'unit'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
run: |
task remote:test-cicd --yes
#
# Integration tests.
#
- name: integration tests
if: inputs.testing-type == 'integration'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
TEST_TIMEOUT: ${{ inputs.test-timeout }}
run: |
task remote:test-integration-cicd --yes
#
# Coverage.
#
- name: code coverage
if: inputs.testing-type == 'coverage'
shell: bash
env:
CODE_COVERAGE_EXPECTED: ${{ inputs.code-coverage-expected }}
CODE_COVERAGE_FILE_EXCLUSIONS: ${{ inputs.golang-unit-tests-exclusions }}
GITHUB_TOKEN: ${{ inputs.token }}
CODE_COVERAGE_TIMEOUT: ${{ inputs.code-coverage-timeout }}
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
run: |
task remote:coverage --yes
#
# Component tests.
#
- name: component tests
if: inputs.testing-type == 'component'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
run: |
task remote:test-component-cicd --yes
#
# Build binary (with optional tags)
#
- name: Build binary
if: inputs.release-dir != ''
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
BUILD_DIR: build/${{ inputs.release-type }}/${{ inputs.release-application-name }}/${{ inputs.release-architecture }}
GOARCH: ${{ inputs.release-architecture }}
GOOS: ${{ inputs.release-os }}
SOURCE_FILE: ${{ inputs.release-dir }}/main.go
run: |
mkdir -p "${BUILD_DIR}"
if [ -n "${{ inputs.release-build-tags }}" ]; then
go build \
-tags "${{ inputs.release-build-tags }}" \
-o "${BUILD_DIR}/main" "${SOURCE_FILE}"
else
go build \
-ldflags="-X 'main.Version=${{ github.ref_name }}'" \
-o "${BUILD_DIR}/main" "${SOURCE_FILE}"
fi
#
# Compute asset name
#
- name: Compute asset name
if: inputs.release-dir != ''
id: compute_asset_name
shell: bash
run: |
ASSET_NAME_BASE="${{ inputs.release-application-name }}-${{ github.ref_name }}-${{ inputs.release-os }}-${{ inputs.release-architecture }}"
if [ -n "${{ inputs.release-build-tags }}" ]; then
ASSET_NAME="${ASSET_NAME_BASE}-${{ inputs.release-build-tags }}"
else
ASSET_NAME="${ASSET_NAME_BASE}"
fi
echo "asset_name=${ASSET_NAME}" >> $GITHUB_OUTPUT
#
# Upload binaries to release
#
- name: Upload binaries to release
if: |
github.event_name == 'push' &&
contains(github.ref, 'refs/tags/') &&
inputs.release-dir != ''
uses: svenstaro/upload-release-action@2.11.5
with:
repo_token: ${{ inputs.token }}
file: build/${{ inputs.release-type }}/${{ inputs.release-application-name }}/${{ inputs.release-architecture }}/main
asset_name: ${{ steps.compute_asset_name.outputs.asset_name }}
tag: ${{ github.ref }}