-
Notifications
You must be signed in to change notification settings - Fork 0
429 lines (353 loc) · 11.7 KB
/
main.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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
name: Go CI
on:
workflow_dispatch:
push:
tags:
- '*'
branches:
- 'main'
- 'release/*'
paths:
- '**.go'
- '**.c'
- '**.h'
- 'Dockerfile*'
- '.github/workflows/main.yaml'
- 'go.*'
- 'Makefile'
pull_request:
branches:
- 'main'
- 'release/*'
jobs:
lint:
name: Lint withny-dl
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build-essential
run: |
sudo apt update -y
sudo apt install -y build-essential libavformat-dev libavcodec-dev libavutil-dev
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
cache-dependency-path: go.sum
- name: Download all Go modules
run: |
go mod download
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout 5m
skip-cache: true
test:
name: Test withny-dl
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build-essential
run: |
sudo apt update -y
sudo apt install -y build-essential libavformat-dev libavcodec-dev libavutil-dev
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
cache-dependency-path: go.sum
- name: Download all Go modules
run: |
go mod download
- name: test
run: go test -v -race -covermode=atomic -tags=unit -timeout=30s ./...
build-export-static:
name: Build and export withny-dl static Docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write # needed for signing the images with GitHub OIDC Token
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Context for Buildx
run: |
docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders
- name: Install Cosign
if: startsWith(github.ref, 'refs/tags')
uses: sigstore/cosign-installer@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: docker_meta_dev
uses: docker/metadata-action@v5
with:
images: ghcr.io/darkness4/withny-dl
tags: |
dev
- name: Build and export dev
uses: docker/build-push-action@v6
id: build-and-push-dev
with:
file: Dockerfile.static
platforms: linux/amd64,linux/arm64,linux/riscv64
push: true
build-args: |
VERSION=dev
tags: ${{ steps.docker_meta_dev.outputs.tags }}
labels: ${{ steps.docker_meta_dev.outputs.labels }}
annotations: ${{ steps.docker_meta_dev.outputs.annotations }}
- id: docker_meta
uses: docker/metadata-action@v5
if: startsWith(github.ref, 'refs/tags')
with:
images: ghcr.io/darkness4/withny-dl
tags: |
latest
type=semver,pattern={{version}}
- name: Build and export
if: startsWith(github.ref, 'refs/tags')
uses: docker/build-push-action@v6
id: build-and-push
with:
file: Dockerfile.static
platforms: linux/amd64,linux/arm64,linux/riscv64
push: true
build-args: |
VERSION=v${{ steps.docker_meta.outputs.version }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
annotations: ${{ steps.docker_meta.outputs.annotations }}
- name: Sign the images with GitHub OIDC Token
if: startsWith(github.ref, 'refs/tags')
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.docker_meta.outputs.tags }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
- name: Extract artifacts
if: startsWith(github.ref, 'refs/tags') || github.event_name == 'workflow_dispatch'
uses: docker/build-push-action@v6
with:
file: Dockerfile.static
platforms: linux/amd64,linux/arm64,linux/riscv64
push: false
outputs: |
type=local,dest=/tmp/out
target: export
build-args: |
VERSION=v${{ steps.docker_meta.outputs.version }}
- name: Move files
if: startsWith(github.ref, 'refs/tags') || github.event_name == 'workflow_dispatch'
run: |
mkdir -p /tmp/artifacts
mv /tmp/out/linux_amd64/withny-dl-linux-amd64 /tmp/artifacts/withny-dl-linux-amd64
mv /tmp/out/linux_arm64/withny-dl-linux-arm64 /tmp/artifacts/withny-dl-linux-arm64
mv /tmp/out/linux_riscv64/withny-dl-linux-riscv64 /tmp/artifacts/withny-dl-linux-riscv64
- name: Upload artifacts
if: startsWith(github.ref, 'refs/tags') || github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: linux-binaries
path: /tmp/artifacts
if-no-files-found: error
retention-days: 1
build-windows:
name: Test Build withny-dl static windows binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Context for Buildx
run: |
docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders
- id: docker_meta
uses: docker/metadata-action@v5
if: startsWith(github.ref, 'refs/tags')
with:
images: ghcr.io/darkness4/withny-dl
tags: |
type=semver,pattern={{version}}
- name: Build & Extract artifacts
uses: docker/build-push-action@v6
with:
file: Dockerfile.static-windows
platforms: linux/amd64
push: false
outputs: |
type=local,dest=/tmp/out
target: export
build-args: |
VERSION=v${{ steps.docker_meta.outputs.version }}
- name: Move files
run: |
mkdir -p /tmp/artifacts
mv /tmp/out/withny-dl-windows-amd64.exe /tmp/artifacts/withny-dl-windows-amd64.exe
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-binaries
path: /tmp/artifacts
if-no-files-found: error
retention-days: 1
build-darwin:
name: Test Build withny-dl darwin binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Context for Buildx
run: |
docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders
- id: docker_meta
uses: docker/metadata-action@v5
if: startsWith(github.ref, 'refs/tags')
with:
images: ghcr.io/darkness4/withny-dl
tags: |
type=semver,pattern={{version}}
- name: Build & Extract artifacts
uses: docker/build-push-action@v6
with:
file: Dockerfile.darwin
platforms: linux/amd64,linux/arm64
push: false
outputs: |
type=local,dest=/tmp/out
target: export
build-args: |
VERSION=v${{ steps.docker_meta.outputs.version }}
- name: Move files
run: |
mkdir -p /tmp/artifacts
mv /tmp/out/linux_amd64/withny-dl-darwin-amd64 /tmp/artifacts/withny-dl-darwin-amd64
mv /tmp/out/linux_arm64/withny-dl-darwin-arm64 /tmp/artifacts/withny-dl-darwin-arm64
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: osx-binaries
path: /tmp/artifacts
if-no-files-found: error
retention-days: 1
test-darwin:
name: Test running darwin to see any linking errors
strategy:
fail-fast: true
matrix:
os: [macos-12, macos-13, macos-14]
runs-on: ${{ matrix.os }}
needs: [build-darwin]
steps:
- uses: actions/download-artifact@v4
with:
name: osx-binaries
- name: Execute binaries
run: |
chmod +x ./withny-dl-darwin-amd64
./withny-dl-darwin-amd64 --help
test-windows:
name: Test running windows to see any linking errors
strategy:
fail-fast: true
matrix:
os: [windows-2019, windows-2022]
runs-on: ${{ matrix.os }}
needs: [build-windows]
steps:
- uses: actions/download-artifact@v4
with:
name: windows-binaries
- name: Execute binaries
run: |
.\withny-dl-windows-amd64.exe --help
test-memleaks:
name: Run memleak tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run memleak tests
run: |
docker run --rm \
-v $(pwd):/in \
-w /in \
ghcr.io/darkness4/fc2-live-dl-go:valgrind \
make memleaks
release:
name: Release withny-dl
needs: [build-export-static, test-darwin, test-windows, test-memleaks]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v4
- name: Fetch tag annotations
run: |
# https://github.com/actions/checkout/issues/1467
git fetch --force --tags --depth 1
- name: Download linux artifacts
uses: actions/download-artifact@v4
with:
name: linux-binaries
path: target
- name: Download windows artifacts
uses: actions/download-artifact@v4
with:
name: windows-binaries
path: target
- name: Download osx artifacts
uses: actions/download-artifact@v4
with:
name: osx-binaries
path: target
- name: Run checksum and generate release notes
run: make package
- name: Branch name
id: branch_name
run: |
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "TAG_MESSAGE=$(git tag -l --format='%(contents:subject)' ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
- uses: sersoft-gmbh/setup-gh-cli-action@v2
if: startsWith(github.ref, 'refs/tags/cli')
with:
version: stable
- name: Create release
id: create_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ steps.branch_name.outputs.TAG_NAME }}
TAG_MESSAGE: ${{ steps.branch_name.outputs.TAG_MESSAGE }}
IS_PRERELEASE: ${{ contains(steps.branch_name.outputs.TAG_NAME, '-') }}
run: |
RELEASE_URL=$(gh release create "$TAG_NAME" --repo Darkness4/withny-dl -t "$TAG_MESSAGE" -F target/release.md --generate-notes --draft --prerelease="$IS_PRERELEASE" target/withny-* target/checksums.txt)
echo "RELEASE_URL=$RELEASE_URL" >> $GITHUB_OUTPUT
- name: Notify release
env:
RELEASE_URL: ${{ steps.create_release.outputs.RELEASE_URL }}
GOTIFY_URL: ${{ secrets.GOTIFY_URL }}
TAG_NAME: ${{ steps.branch_name.outputs.TAG_NAME }}
run: |
curl -X POST "$GOTIFY_URL" -F "title=New Release: $TAG_NAME" -F "message=Release $RELEASE_URL"