-
Notifications
You must be signed in to change notification settings - Fork 0
293 lines (257 loc) · 12.3 KB
/
lint-and-build-using-ci-matrix.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
# Copyright 2022 Adam Chalkley
#
# https://github.com/atc0005/shared-project-resources
#
# Licensed under the MIT License. See LICENSE file in the project root for
# full license information.
on:
workflow_call:
inputs:
os-dependencies:
required: false
type: string
default-repo:
required: false
type: string
default: origin
primary-branch:
required: false
type: string
default: master
development-branch:
required: false
type: string
default: development
fetch-depth:
required: false
type: number
default: 50
jobs:
# https://stackoverflow.com/questions/76151411/use-github-actions-to-check-if-branch-is-up-to-date-with-main
# https://stackoverflow.com/a/76151412/903870
# https://github.com/atc0005/shared-project-resources/issues/135
assert_pr_branch_is_ahead_of_primary_branch:
name: Assert PR branch is ahead
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Assert source branches are set
run: |
abort="false"
if [[ "${{ format('{0}/{1}', inputs.default-repo, inputs.primary-branch) }}" == "/" ]] ; then \
echo "default repo and primary branch values not set!"; abort="true"; fi
if [[ "${{ format('{0}/{1}', inputs.default-repo, inputs.development-branch) }}" == "/" ]] ; then \
echo "default repo and development branch values not set!"; abort="true"; fi
if [[ "$abort" == "true" ]]; then exit 1; fi
echo "Primary branch: ${{ format('{0}/{1}', inputs.default-repo, inputs.primary-branch) }}"
echo "Development branch: ${{ format('{0}/{1}', inputs.default-repo, inputs.development-branch) }}"
- name: Check out code (subset)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4.2.2
with:
fetch-depth: ${{ inputs.fetch-depth }}
# Mark the current working directory as a safe directory in git to
# resolve "dubious ownership" complaints.
#
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html
# https://github.com/actions/runner-images/issues/6775
# https://github.com/actions/checkout/issues/766
- name: Mark the current working directory as a safe directory in git
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
run: git config --global --add safe.directory "${PWD}"
- name: Fetch additional references
if: ${{ github.event_name == 'pull_request' }}
run: |
git fetch origin ${{ inputs.primary-branch }} --depth ${{ inputs.fetch-depth }}
# Allow fetch attempts for ${{ inputs.development-branch }} to fail
git fetch origin ${{ inputs.development-branch }} --depth ${{ inputs.fetch-depth }} || true
- name: Assert PR branch is ahead of acceptable source branches
if: ${{ github.event_name == 'pull_request' }}
run: |
if ! (git merge-base --is-ancestor ${{ format('{0}/{1}', inputs.default-repo, inputs.primary-branch) }} ${{ github.event.pull_request.head.sha }} || \
git merge-base --is-ancestor ${{ format('{0}/{1}', inputs.default-repo, inputs.development-branch) }} ${{ github.event.pull_request.head.sha }});
then echo "This branch is not up to date with ${{ inputs.primary-branch }} or ${{ inputs.development-branch }} branches!";
exit 1; fi
lint_code:
needs: assert_pr_branch_is_ahead_of_primary_branch
name: Lint codebase
runs-on: ubuntu-latest
timeout-minutes: 10
# Don't flag the whole workflow as failed if "experimental" matrix jobs
# fail. This allows the unstable image linting tasks to fail without
# marking the oldstable and stable image linting jobs as failed.
continue-on-error: ${{ matrix.experimental }}
strategy:
# Don't stop all workflow jobs if the unstable image linting tasks fail.
fail-fast: false
matrix:
container-image: ["go-ci-oldstable", "go-ci-stable"]
experimental: [false]
include:
- container-image: "go-ci-unstable"
experimental: true
container:
image: "ghcr.io/atc0005/go-ci:${{ matrix.container-image }}"
steps:
- name: Check out code
uses: actions/checkout@v4.2.2
# Mark the current working directory as a safe directory in git to
# resolve "dubious ownership" complaints.
#
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html
# https://github.com/actions/runner-images/issues/6775
# https://github.com/actions/checkout/issues/766
- name: Mark the current working directory as a safe directory in git
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
run: git config --global --add safe.directory "${PWD}"
- name: Install Ubuntu packages (custom set)
if: ${{ inputs.os-dependencies != '' }}
run: apt-get update && apt-get install -y --no-install-recommends ${{ inputs.os-dependencies }}
- name: Remove repo-provided golangci-lint config file
run: |
# Remove the copy of the config file bundled with the repo/code so
# that the configuration provided by the atc0005/go-ci project is
# used instead
rm -vf .golangci.yml
- name: Run golangci-lint using container-provided config file settings
run: |
golangci-lint --version
# Override default timeout to accomodate more complex (or CGO)
# codebases which take longer to lint.
golangci-lint run --timeout=5m
# This is the very latest stable version of staticcheck provided by the
# atc0005/go-ci container. The version included with golangci-lint often
# lags behind the official stable releases.
- name: Run staticcheck
run: |
staticcheck --version
staticcheck $(go list -mod=vendor ./... | grep -v /vendor/)
optional_linting:
needs: assert_pr_branch_is_ahead_of_primary_branch
name: Optional Linting
with:
# Pass on any values specified by the importing workflow.
os-dependencies: ${{ inputs.os-dependencies }}
uses: atc0005/shared-project-resources/.github/workflows/lint-using-optional-linters.yml@master
test_code:
needs: assert_pr_branch_is_ahead_of_primary_branch
name: Run tests
runs-on: ubuntu-latest
timeout-minutes: 10
# Don't flag the whole workflow as failed if "experimental" matrix jobs
# fail. This allows unstable image tests to fail without marking the
# oldstable and stable image jobs as failed.
continue-on-error: ${{ matrix.experimental }}
strategy:
# Don't stop all workflow jobs if the unstable image tests fail.
fail-fast: false
matrix:
container-image: ["go-ci-oldstable", "go-ci-stable"]
experimental: [false]
include:
- container-image: "go-ci-unstable"
experimental: true
container:
image: "ghcr.io/atc0005/go-ci:${{ matrix.container-image }}"
steps:
- name: Check out code
uses: actions/checkout@v4.2.2
# Mark the current working directory as a safe directory in git to
# resolve "dubious ownership" complaints.
#
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html
# https://github.com/actions/runner-images/issues/6775
# https://github.com/actions/checkout/issues/766
- name: Mark the current working directory as a safe directory in git
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
run: git config --global --add safe.directory "${PWD}"
- name: Install Ubuntu packages (custom set)
if: ${{ inputs.os-dependencies != '' }}
run: apt-get update && apt-get install -y --no-install-recommends ${{ inputs.os-dependencies }}
- name: Run all tests
run: go test -mod=vendor -v ./...
# https://github.com/atc0005/shared-project-resources/issues/145
evaluate_loopvar_scoping_changes:
needs: assert_pr_branch_is_ahead_of_primary_branch
name: Evaluate loopvar scoping changes
runs-on: ubuntu-latest
# Default: 360 minutes
timeout-minutes: 10
# Brief testing indicates the syntax of this job is correct and that the
# matches are not false-positives; we'll treat linting failures as real
# errors.
continue-on-error: false
container:
image: "ghcr.io/atc0005/go-ci:go-ci-mirror-build-go1.21"
steps:
- name: Print go version
run: go version
- name: Check out code
uses: actions/checkout@v4.2.2
# Mark the current working directory as a safe directory in git to
# resolve "dubious ownership" complaints.
#
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html
# https://github.com/actions/runner-images/issues/6775
# https://github.com/actions/checkout/issues/766
- name: Mark the current working directory as a safe directory in git
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
run: git config --global --add safe.directory "${PWD}"
- name: Install Ubuntu packages (custom set)
if: ${{ inputs.os-dependencies != '' }}
run: apt-get update && apt-get install -y --no-install-recommends ${{ inputs.os-dependencies }}
- name: Assert loopvar flag does not change loop compilation behavior
run: >-
! go build -gcflags=all=-d=loopvar=2 $(go list -mod=vendor ./...) 2>&1
| grep -Ev 'vendor/|/usr'
| grep 'now per-iteration'
build_code:
needs: assert_pr_branch_is_ahead_of_primary_branch
name: Build codebase
runs-on: ubuntu-latest
# Default: 360 minutes
timeout-minutes: 10
# Don't flag the whole workflow as failed if "experimental" matrix jobs
# fail. This allows unstable image build tasks to fail without marking the
# oldstable and stable image jobs as failed.
continue-on-error: ${{ matrix.experimental }}
strategy:
# Don't stop all workflow jobs if the unstable image build tasks fail.
fail-fast: false
matrix:
container-image: ["go-ci-oldstable", "go-ci-stable"]
experimental: [false]
include:
- container-image: "go-ci-unstable"
experimental: true
container:
image: "ghcr.io/atc0005/go-ci:${{ matrix.container-image }}"
steps:
- name: Print go version
run: go version
- name: Check out code
uses: actions/checkout@v4.2.2
# Mark the current working directory as a safe directory in git to
# resolve "dubious ownership" complaints.
#
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html
# https://github.com/actions/runner-images/issues/6775
# https://github.com/actions/checkout/issues/766
- name: Mark the current working directory as a safe directory in git
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
run: git config --global --add safe.directory "${PWD}"
- name: Install Ubuntu packages (custom set)
if: ${{ inputs.os-dependencies != '' }}
run: apt-get update && apt-get install -y --no-install-recommends ${{ inputs.os-dependencies }}
- name: Build using vendored dependencies
# NOTE: This will fail if there is a doc.go file in the project root
# with a message similar to:
#
# # github.com/atc0005/check-cert
# runtime.main_main·f: function main is undeclared in the main package
run: go build -v -mod=vendor ./...