-
Notifications
You must be signed in to change notification settings - Fork 1
285 lines (249 loc) · 7.79 KB
/
ci.yaml
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
name: Build and test components
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
tags:
- v*
# Cancel any running jobs for PRs on a new commit
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
strategy:
fail-fast: false
matrix:
goos:
- linux
- darwin
- windows
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Avoid running against a shallow clone
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }} # We plan to run only against internal pull requests
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0 # Avoid running against a shallow clone
- name: Force fetch upstream tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.23"
- name: Print environment
id: vars
run: |
printf "Using Go at $(which go) (version $(go version))\n"
printf "\n\nGo environment:\n\n"
go env
printf "\n\nSystem environment:\n\n"
env
- name: Build the make/make tool
run: go build -o make/make make/main.go
- name: Build
env:
GOOS: ${{ matrix.goos }}
CGO_ENABLED: 0
shell: bash
run: |
make/make GOOS=$GOOS lstn
- name: Generate docs
if: ${{ github.event_name == 'pull_request' && matrix.goos == 'linux' }}
run: |
GITHUB_ACTIONS= GITHUB_EVENT_PATH= ./lstn manual 2> docs/cheatsheet.md
./lstn config 2> docs/configuration.md
./lstn env 2> docs/environment.md
./lstn exit 2> docs/exitcodes.md
./lstn reporters 2> docs/reporters.md
- name: Update docs
if: ${{ github.event_name == 'pull_request' && matrix.goos == 'linux' }}
uses: EndBug/add-and-commit@v9
with:
default_author: github_actor
commit: --signoff
add: "docs"
message: "docs: update autogenerated docs"
push: true
- name: Archive the artifact(s) for ${{ matrix.goos }}
uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.goos }}
path: |
./lstn
./lstn.exe
retention-days: 1
if-no-files-found: error
version-darwin:
name: "check version (darwin)"
needs: build
runs-on: macos-latest
steps:
- name: Check out the source code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Avoid running against a shallow clone
- name: Get binaries
uses: actions/download-artifact@v4
with:
name: artifact-darwin
path: .
- name: Check short version
shell: bash
run: |
file lstn
chmod +x lstn
./lstn version
latest_tag=$(git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/v*")
[[ "lstn ${latest_tag}" == $(./lstn version 2>&1) ]]
version-linux:
name: "check version (linux)"
needs: build
runs-on: ubuntu-latest
steps:
- name: Check out the source code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Avoid running against a shallow clone
- name: Get binaries
uses: actions/download-artifact@v4
with:
name: artifact-linux
path: .
- name: Check short version
shell: bash
run: |
file lstn
chmod +x lstn
./lstn version
latest_tag=$(git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/v*")
[[ "lstn ${latest_tag}" == $(./lstn version 2>&1) ]]
version-windows:
name: "check version (windows)"
needs: build
runs-on: windows-latest
steps:
- name: Check out the source code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Avoid running against a shallow clone
- name: Get binaries
uses: actions/download-artifact@v4
with:
name: artifact-windows
path: .
# TODO: equality
- name: Check short version
run: |
file lstn.exe
.\lstn.exe version
test:
name: test
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Check out the source code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.23"
- name: Build code
run: go build ./...
shell: bash
- name: Run tests
run: go test -v -race -cover -covermode=atomic -coverprofile=coverage.txt ./...
shell: bash
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: unit-test-coverage-${{ matrix.os }}
path: coverage.txt
if-no-files-found: error
retention-days: 1
test-e2e:
name: Run e2e tests
needs:
- build
uses: ./.github/workflows/call-run-e2e.yaml
with:
# The Github ref to checkout for the listen-e2e repo.
ref: main
# We want to use binaries built here.
lstn-use-release: false
# The artifact to use we built previously.
lstn-binary-artefact: artifact-linux
secrets:
# We have to use a PAT to ensure we can checkout the other repo and access containers from other repos.
github-token: ${{ secrets.CI_PAT }}
release:
name: Create official release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Avoid running against a shallow clone
- name: Force fetch upstream tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.23"
- name: Install cosign
uses: sigstore/cosign-installer@v3.4.0
with:
cosign-release: "v2.2.3"
- name: Install syft
uses: anchore/sbom-action/download-syft@v0.13.3
- name: Release
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COSIGN_EXPERIMENTAL: 1
- name: Create release for tag
uses: softprops/action-gh-release@v2
id: release
with:
generate_release_notes: true
make_latest: true
# This job provides the single required status for PRs to be merged into main.
# Instead of updating the protected branch status in github, we can just update the "needs" section below
# to require additional/remove existing status checks to protect main via a simple GitOps process.
# We can use the alls-green action to get around the github assumption that a "skipped" required status check
# counts as passed.
test-required-checks-complete:
# This step always has to run in order to check if the dependent jobs passed even if upstream jobs are skipped.
if: always()
needs:
- build
- test
- test-e2e
name: Build checks complete
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}