-
-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (148 loc) · 5.52 KB
/
Copy pathci.yml
File metadata and controls
167 lines (148 loc) · 5.52 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
name: CI
on:
workflow_call:
inputs:
excluding_versions:
description: 'List of Go versions to not run against, in a JSON array (e.g. ["1.21", "1.22"])'
required: false
type: string
default: "[]"
lint_versions:
description: 'List of Go versions to lint against, in a JSON array (e.g. ["1.25"]). If empty, uses the same versions as the other jobs.'
required: false
type: string
default: ""
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
go-versions: ${{ steps.versions.outputs.matrix }}
lint-versions: ${{ steps.versions.outputs.lint_matrix }}
steps:
- id: versions
run: |
# versions of Go that this module can still be built with (and therefore are "supported" by this project) and actively supported versions of Go
all_versions='["1.25", "1.26"]'
excluding='${{ inputs.excluding_versions }}'
# Filter out excluded versions using jq
filtered=$(jq -c --argjson exclude "$excluding" '[.[] | select(. as $v | $exclude | index($v) | not)]' <<< "$all_versions")
echo "matrix=$filtered" >> $GITHUB_OUTPUT
# Use lint-specific versions if provided, otherwise fall back to the filtered matrix
lint_override='${{ inputs.lint_versions }}'
if [ -n "$lint_override" ]; then
echo "lint_matrix=$lint_override" >> $GITHUB_OUTPUT
else
echo "lint_matrix=$filtered" >> $GITHUB_OUTPUT
fi
build:
name: Build
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
# perform matrix testing to give us an earlier insight into issues with different versions of supported major versions of Go
matrix:
version: ${{ fromJSON(needs.setup.outputs.go-versions) }}
steps:
- name: Check out source code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ matrix.version }}
- name: Test
run: make test
env:
# A combination of our GitHub Actions setup, with the Go toolchain, leads to inconsistencies in calling `go env`, in particular with Go 1.21, where having (the default) `GOTOOLCHAIN=auto` results in build failures
GOTOOLCHAIN: local
lint:
name: Lint
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.lint-versions) }}
steps:
- name: Check out source code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ matrix.version }}
- name: Run `make lint-ci`
run: make lint-ci
env:
# A combination of our GitHub Actions setup, with the Go toolchain, leads to inconsistencies in calling `go env`, in particular with Go 1.21, where having (the default) `GOTOOLCHAIN=auto` results in build failures
GOTOOLCHAIN: local
tidy:
name: Go mod tidy
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.go-versions) }}
steps:
- name: Check out source code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ matrix.version }}
- name: Install `tidied`
run: go install gitlab.com/jamietanna/tidied@latest
- name: Run `make tidy-ci`
run: make tidy-ci
generate:
name: Generated files
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.go-versions) }}
steps:
- name: Check out source code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ matrix.version }}
- name: Run `make generate`
run: make generate
env:
# A combination of our GitHub Actions setup, with the Go toolchain, leads to inconsistencies in calling `go env`, in particular with Go 1.21, where having (the default) `GOTOOLCHAIN=auto` results in build failures
GOTOOLCHAIN: local
- name: Check for no untracked files
run: git status && git diff-index --quiet HEAD --
check:
name: CI
runs-on: ubuntu-latest
needs:
- build
- lint
- tidy
- generate
if: always()
steps:
- name: Check all jobs status
run: |
if [ "${{ needs.build.result }}" != "success" ]; then
echo "Build job failed or was cancelled"
exit 1
fi
if [ "${{ needs.lint.result }}" != "success" ]; then
echo "Lint job failed or was cancelled"
exit 1
fi
if [ "${{ needs.tidy.result }}" != "success" ]; then
echo "Tidy job failed or was cancelled"
exit 1
fi
if [ "${{ needs.generate.result }}" != "success" ]; then
echo "Generate job failed or was cancelled"
exit 1
fi
echo "All CI jobs passed"