-
Notifications
You must be signed in to change notification settings - Fork 1
283 lines (240 loc) · 8.12 KB
/
ci.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
name: CI
on:
push:
branches: ["main"]
tags: ["v*"]
pull_request:
branches: ["main"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CACHE: ${{ (github.event_name == 'push'
|| github.event_name == 'pull_request')
&& github.ref != 'refs/heads/main'
&& !startsWith(github.ref, 'refs/tags/v')
&& !contains(github.event.head_commit.message, '[fresh ci]') }}
RUST_BACKTRACE: 1
RUST_VER: "1.62"
jobs:
################
# Pull Request #
################
pr:
if: ${{ github.event_name == 'pull_request' }}
needs:
- clippy
- docker
- rustdoc
- rustfmt
- test-e2e
- test-unit
runs-on: ubuntu-latest
steps:
- run: true
##########################
# Linting and formatting #
##########################
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
components: clippy
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}
- run: make cargo.lint
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
- run: make cargo.fmt check=yes
###########
# Testing #
###########
test-e2e:
name: E2E tests
needs: ["docker"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}
- uses: satackey/action-docker-layer-caching@v0.0.11
with:
key: test-e2e-{hash}
restore-keys: test-e2e-
continue-on-error: true
timeout-minutes: 10
if: ${{ env.CACHE == 'true' }}
- uses: actions/download-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/
- run: make docker.untar
- run: make test.e2e start-app=yes dockerized=yes
tag=build-${{ github.run_number }}
test-unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}
- run: make test.unit
############
# Building #
############
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- run: make docker.image debug=no no-cache=yes
tag=build-${{ github.run_number }}
- run: make docker.tar
tags=build-${{ github.run_number }}
- uses: actions/upload-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/image.tar
retention-days: 1
rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}
- run: make cargo.doc private=yes open=no
#############
# Releasing #
#############
release-docker:
name: Release Docker image
needs: ["docker", "test-e2e"]
if: ${{ github.event_name == 'push'
&& (github.ref == 'refs/heads/main'
|| startsWith(github.ref, 'refs/tags/v')) }}
strategy:
fail-fast: false
matrix:
registry: ["docker.io", "ghcr.io", "quay.io"]
runs-on: ubuntu-latest
steps:
# Skip if this is fork and no credentials are provided.
- id: skip
run: echo ::set-output name=no::${{ !(
github.repository_owner != 'instrumentisto'
&& ((matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER == '')
|| (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER == ''))
) }}
- uses: actions/checkout@v3
if: ${{ steps.skip.outputs.no == 'true' }}
- uses: actions/download-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/
if: ${{ steps.skip.outputs.no == 'true' }}
- run: make docker.untar
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Login to ${{ matrix.registry }} container registry
uses: docker/login-action@v2
with:
registry: ${{ matrix.registry }}
username: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER)
|| github.repository_owner }}
password: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_PASS)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_TOKEN)
|| secrets.GITHUB_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Parse semver versions from Git tag
id: semver
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/v((([0-9]+)\.[0-9]+)\.[0-9]+(-.+)?)$'
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}
- name: Form version Docker tags
id: tags
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let versions = '${{ steps.semver.outputs.group1 }}';
if ('${{ steps.semver.outputs.group4 }}' === '') {
versions += ',${{ steps.semver.outputs.group2 }}';
if ('${{ steps.semver.outputs.group3 }}' !== '0') {
versions += ',${{ steps.semver.outputs.group3 }}';
}
versions += 'latest';
}
return versions;
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}
- run: make docker.tags
registries=${{ matrix.registry }}
of=build-${{ github.run_number }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}
- run: make docker.push
registries=${{ matrix.registry }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}
# On GitHub Container Registry README is automatically updated on pushes.
- name: Update README on Docker Hub
uses: christian-korneck/update-container-description-action@v1
with:
provider: dockerhub
destination_container_repo: ${{ github.repository }}
readme_file: README.md
env:
DOCKER_USER: ${{ secrets.DOCKERHUB_BOT_USER }}
DOCKER_PASS: ${{ secrets.DOCKERHUB_BOT_PASS }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'docker.io' }}
- name: Update README on Quay.io
uses: christian-korneck/update-container-description-action@v1
with:
provider: quay
destination_container_repo: ${{ matrix.registry }}/${{ github.repository }}
readme_file: README.md
env:
DOCKER_APIKEY: ${{ secrets.QUAYIO_API_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'quay.io' }}