-
Notifications
You must be signed in to change notification settings - Fork 1
354 lines (331 loc) · 11.5 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
---
name: CI
"on":
push:
branches:
- "main"
tags:
- "v*.*.*"
pull_request:
branches:
- "main"
permissions:
contents: read
jobs:
meta:
name: Derive Build Metadata
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Derive version string
id: bin_version
run: echo "bin_version=$(./.version.sh)" >> "$GITHUB_OUTPUT"
- name: bin_version
run: "echo bin_version: ${{ steps.bin_version.outputs.bin_version }}"
- name: Check if this is a running version tag update
id: running_version_tag
run: |
if [ -z "${{ github.event.ref }}" ]; then
echo "is_running_version_tag_update=false" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+$ ]]; then
echo "is_running_version_tag_update=true" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+$ ]]; then
echo "is_running_version_tag_update=true" >> "$GITHUB_OUTPUT"
else
echo "is_running_version_tag_update=false" >> "$GITHUB_OUTPUT"
fi
- name: is_running_version_tag
run: "echo is_running_version_tag_update: ${{ steps.running_version_tag.outputs.is_running_version_tag_update }}"
outputs:
project_name: ${{ github.event.repository.name }}
bin_version: ${{ steps.bin_version.outputs.bin_version }}
dockerhub_owner: ${{ github.repository_owner }}
is_prerelease: >-
${{
steps.running_version_tag.outputs.is_running_version_tag_update != 'true' &&
startsWith(github.ref, 'refs/tags/v') &&
(contains(github.ref, '-alpha.')
|| contains(github.ref, '-beta.')
|| contains(github.ref, '-rc.'))
}}
is_release: >-
${{
steps.running_version_tag.outputs.is_running_version_tag_update != 'true' &&
startsWith(github.ref, 'refs/tags/v') &&
!(contains(github.ref, '-alpha.')
|| contains(github.ref, '-beta.')
|| contains(github.ref, '-rc.'))
}}
is_pull_request: ${{ github.event_name == 'pull_request' }}
is_running_version_tag_update: ${{ steps.running_version_tag.outputs.is_running_version_tag_update }}
lint:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Ruff
run: |
ruff format --check .
ruff check --output-format=github .
- name: Install Prettier
run: npm install -g prettier
- name: Prettier
run: prettier --check .
- name: Actionlint
uses: raven-actions/[email protected]
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: Python tests
run: |
python -m unittest tests/*.py
docker-amd64-cuda:
name: Docker Image (amd64-cuda)
needs: [meta, lint, test]
if: needs.meta.outputs.is_running_version_tag_update != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
if: needs.meta.outputs.is_pull_request != 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: "Meta"
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
${{ needs.meta.outputs.dockerhub_owner }}/${{ needs.meta.outputs.project_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=false
suffix=-amd64-cuda
- name: "Build & Push"
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile-amd64-cuda
platforms: amd64
builder: ${{ steps.buildx.outputs.name }}
push: ${{ needs.meta.outputs.is_pull_request != 'true' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
build-args: |
BIN_VERSION=${{ needs.meta.outputs.bin_version }}
docker-amd64-cpu:
name: Docker Image (amd64-cpu)
needs: [meta, lint, test]
if: needs.meta.outputs.is_running_version_tag_update != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
if: needs.meta.outputs.is_pull_request != 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: "Meta"
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
${{ needs.meta.outputs.dockerhub_owner }}/${{ needs.meta.outputs.project_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=false
suffix=-amd64-cpu
- name: "Build & Push"
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile-amd64-cpu
platforms: amd64
builder: ${{ steps.buildx.outputs.name }}
push: ${{ needs.meta.outputs.is_pull_request != 'true' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
build-args: |
BIN_VERSION=${{ needs.meta.outputs.bin_version }}
docker-arm64:
name: Docker Image (arm64)
needs: [meta, lint, test]
if: needs.meta.outputs.is_running_version_tag_update != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
if: needs.meta.outputs.is_pull_request != 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: "Meta"
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
${{ needs.meta.outputs.dockerhub_owner }}/${{ needs.meta.outputs.project_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=false
suffix=-arm64
- name: "Build & Push"
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile-arm64
platforms: arm64
builder: ${{ steps.buildx.outputs.name }}
push: ${{ needs.meta.outputs.is_pull_request != 'true' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
build-args: |
BIN_VERSION=${{ needs.meta.outputs.bin_version }}
release:
name: (Pre)Release
needs: [meta, lint, test, docker-amd64-cuda, docker-amd64-cpu, docker-arm64]
if: >-
needs.meta.outputs.is_release == 'true' ||
needs.meta.outputs.is_prerelease == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ needs.meta.outputs.is_prerelease == 'true' }}
generate_release_notes: true
- name: Update Docker Hub description
if: needs.meta.outputs.is_release == 'true'
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ needs.meta.outputs.dockerhub_owner }}/${{ needs.meta.outputs.project_name }}
readme-filepath: ./README.md
short-description: ${{ github.event.repository.description }}
tags:
name: Update Release Tags
needs: [meta, release]
if: needs.meta.outputs.is_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update running major/minor version tags
uses: sersoft-gmbh/running-release-tags-action@v3
with:
fail-on-non-semver-tag: true
create-release: false
update-full-release: false
ntfy:
name: Ntfy
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
needs:
[
meta,
lint,
test,
docker-amd64-cuda,
docker-amd64-cpu,
docker-arm64,
release,
tags,
]
steps:
- name: Send success notification
uses: niniyas/ntfy-action@master
if: ${{ !contains(needs.*.result, 'failure') && (needs.meta.outputs.is_release == 'true' || needs.meta.outputs.is_prerelease == 'true') }}
with:
url: "https://ntfy.cdzombak.net"
topic: "gha-builds"
priority: 3
headers: '{"authorization": "Bearer ${{ secrets.NTFY_TOKEN }}"}'
tags: white_check_mark
title: ${{ github.event.repository.name }} ${{ needs.meta.outputs.bin_version }} available
details: ${{ github.event.repository.name }} version ${{ needs.meta.outputs.bin_version }} is now available.
- name: Send failure notification
uses: niniyas/ntfy-action@master
if: ${{ contains(needs.*.result, 'failure') }}
with:
url: "https://ntfy.cdzombak.net"
topic: "gha-builds"
priority: 3
headers: '{"authorization": "Bearer ${{ secrets.NTFY_TOKEN }}"}'
tags: no_entry
title: ${{ github.event.repository.name }} ${{ needs.meta.outputs.bin_version }} build failed
details: Build failed for ${{ github.event.repository.name }} version ${{ needs.meta.outputs.bin_version }}.