generated from hotio/bazarr
-
-
Notifications
You must be signed in to change notification settings - Fork 1
378 lines (350 loc) · 16 KB
/
build.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: build
on: push
jobs:
check:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Shellcheck
run: |
for file in $(find ./root/etc -type f); do
echo "Checking: $file"
shellcheck "$file"
done
build:
runs-on: ubuntu-20.04
strategy:
matrix:
architecture: [linux-arm64, linux-amd64]
needs: [check]
outputs:
version: ${{ steps.prep.outputs.version }}
branch: ${{ steps.prep.outputs.branch }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check if architecture exists
id: arch_check
run: |
(test -f ${{ matrix.architecture }}.Dockerfile && echo "check=passed" >> $GITHUB_OUTPUT) || echo "check=failed" >> $GITHUB_OUTPUT
- name: Set up QEMU
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/setup-buildx-action@v2
with:
install: true
version: latest
driver-opts: image=moby/buildkit:v0.10.6
- name: Login to docker.io
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to ghcr.io
if: "contains(steps.arch_check.outputs.check, 'passed')"
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.PERSONAL_TOKEN }}
- name: Prepare
if: "contains(steps.arch_check.outputs.check, 'passed')"
id: prep
run: |
ARCHITECTURE=${{ matrix.architecture }}
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "title=${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}" >> $GITHUB_OUTPUT
echo "revision=${GITHUB_SHA}" >> $GITHUB_OUTPUT
echo "source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/${GITHUB_REF//refs\/heads\//}" >> $GITHUB_OUTPUT
echo "vendor=${{ github.repository_owner }}" >> $GITHUB_OUTPUT
echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/blob/master/README.md" >> $GITHUB_OUTPUT
echo "platform=${ARCHITECTURE//-/\/}" >> $GITHUB_OUTPUT
echo "cache=${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-cache-${{ matrix.architecture }}" >> $GITHUB_OUTPUT
echo "tag=${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}-${{ matrix.architecture }}" >> $GITHUB_OUTPUT
VERSION=$(jq -r '.version // empty' < VERSION.json)
if [[ -z ${VERSION} ]]; then
VERSION=$(date --utc --date=@$(git show -s --format=%ct $(git rev-parse --short HEAD)) +'%Y%m%d%H%M%S')
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
BRANCH=$(jq -r '.branch // empty' < VERSION.json)
if [[ -n ${BRANCH} ]]; then
echo "branch=-${BRANCH}" >> $GITHUB_OUTPUT
fi
echo 'build-args<<EOF' >> $GITHUB_OUTPUT
jq -r 'to_entries[] | [(.key | ascii_upcase),.value] | join("=")' < VERSION.json >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
echo "package-version=${GITHUB_REF//refs\/heads\//}-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Build and push - Attempt 1
continue-on-error: true
if: "contains(steps.arch_check.outputs.check, 'passed')"
id: build_attempt1
uses: docker/build-push-action@v4
with:
push: true
platforms: ${{ steps.prep.outputs.platform }}
file: ./${{ matrix.architecture }}.Dockerfile
cache-from: docker.io/${{ steps.prep.outputs.cache }}
cache-to: docker.io/${{ steps.prep.outputs.cache }}
tags: |
docker.io/${{ steps.prep.outputs.tag }}
ghcr.io/${{ steps.prep.outputs.tag }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.title=${{ steps.prep.outputs.title }}
org.opencontainers.image.revision=${{ steps.prep.outputs.revision }}
org.opencontainers.image.source=${{ steps.prep.outputs.source }}
org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }}
org.opencontainers.image.url=${{ steps.prep.outputs.url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
build-args: |
GITHUB_TOKEN=${{ secrets.PERSONAL_TOKEN }}
BUILD_ARCHITECTURE=${{ matrix.architecture }}
PACKAGE_VERSION=${{ steps.prep.outputs.package-version }}
${{ steps.prep.outputs.build-args }}
- name: Sleep
if: (steps.build_attempt1.outcome == 'failure')
run: |
sleep 30
- name: Build and push - Attempt 2
if: (steps.build_attempt1.outcome == 'failure')
uses: docker/build-push-action@v4
with:
push: true
platforms: ${{ steps.prep.outputs.platform }}
file: ./${{ matrix.architecture }}.Dockerfile
cache-from: docker.io/${{ steps.prep.outputs.cache }}
cache-to: docker.io/${{ steps.prep.outputs.cache }}
tags: |
docker.io/${{ steps.prep.outputs.tag }}
ghcr.io/${{ steps.prep.outputs.tag }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.title=${{ steps.prep.outputs.title }}
org.opencontainers.image.revision=${{ steps.prep.outputs.revision }}
org.opencontainers.image.source=${{ steps.prep.outputs.source }}
org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }}
org.opencontainers.image.url=${{ steps.prep.outputs.url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
build-args: |
GITHUB_TOKEN=${{ secrets.PERSONAL_TOKEN }}
BUILD_ARCHITECTURE=${{ matrix.architecture }}
PACKAGE_VERSION=${{ steps.prep.outputs.package-version }}
${{ steps.prep.outputs.build-args }}
- name: Show installed packages
if: |
contains(steps.arch_check.outputs.check, 'passed')
run: |
version_json=$(cat ./VERSION.json)
upstream_tag=$(jq -r '.upstream_tag' <<< "${version_json}")
upstream_image=$(jq -r '.upstream_image' <<< "${version_json}")
if [[ ${upstream_tag} == alpine || ${upstream_image} == alpine ]]; then
docker run --rm --entrypoint="" "docker.io/${{ steps.prep.outputs.tag }}" apk -vv info | sort
else
docker run --rm --entrypoint="" "docker.io/${{ steps.prep.outputs.tag }}" apt list --installed
fi
- name: Prepare for test
if: |
contains(steps.arch_check.outputs.check, 'passed') &&
contains(matrix.architecture, 'amd64')
id: prep_test
run: |
version_json=$(cat ./VERSION.json)
test_url=$(jq -r '.test_url' <<< "${version_json}")
if [[ ${test_url} != null ]]; then
echo "url=${test_url}" >> $GITHUB_OUTPUT
echo "check=passed" >> $GITHUB_OUTPUT
else
echo "check=failed" >> $GITHUB_OUTPUT
fi
- name: Run test
if: |
contains(steps.arch_check.outputs.check, 'passed') &&
contains(steps.prep_test.outputs.check, 'passed') &&
contains(matrix.architecture, 'amd64')
run: |
test_url=${{ steps.prep_test.outputs.url }}
docker run --network host -d --name service "docker.io/${{ steps.prep.outputs.tag }}"
currenttime=$(date +%s); maxtime=$((currenttime+120)); while (! curl -fsSL -m 10 -b /dev/shm/cookie "${test_url}" > /dev/null) && [[ "$currenttime" -lt "$maxtime" ]]; do sleep 1; currenttime=$(date +%s); done
if curl -fsSL -m 10 -b /dev/shm/cookie "${test_url}" > /dev/null; then
docker logs service
exit 0
else
docker logs service
exit 1
fi
- name: Take screenshot
continue-on-error: true
if: |
contains(steps.arch_check.outputs.check, 'passed') &&
contains(steps.prep_test.outputs.check, 'passed') &&
contains(matrix.architecture, 'amd64')
uses: swinton/[email protected]
with:
source: ${{ steps.prep_test.outputs.url }}
destination: screenshot.png
delay: 5
publish:
runs-on: ubuntu-20.04
strategy:
matrix:
registry: [docker.io, ghcr.io]
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to docker.io
if: matrix.registry == 'docker.io'
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to ghcr.io
if: matrix.registry == 'ghcr.io'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.PERSONAL_TOKEN }}
- name: Create manifests - Attempt 1
continue-on-error: true
id: manifest_attempt1
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
IMAGE=${{ matrix.registry }}/${GITHUB_REPOSITORY}
TAG=${GITHUB_REF//refs\/heads\//}
SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
VERSION=${{ needs.build.outputs.version }}
BRANCH=${{ needs.build.outputs.branch }}
[[ -f linux-amd64.Dockerfile ]] && AMD64=${SOURCE}-linux-amd64
[[ -f linux-arm64.Dockerfile ]] && ARM64=${SOURCE}-linux-arm64
[[ -f linux-arm-v7.Dockerfile ]] && ARMV7=${SOURCE}-linux-arm-v7
docker manifest create ${IMAGE}:${TAG}${BRANCH} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}${BRANCH}
docker manifest create ${IMAGE}:${TAG}${BRANCH}-${VERSION//\~/-} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}${BRANCH}-${VERSION//\~/-}
docker manifest create ${IMAGE}:${TAG}-${GITHUB_SHA:0:7} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}-${GITHUB_SHA:0:7}
IS_LATEST=$(jq -r '.latest // empty' < VERSION.json)
if [[ ${IS_LATEST} == true ]]; then
docker manifest create ${IMAGE}:latest ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:latest
fi
- name: Sleep
if: (steps.manifest_attempt1.outcome == 'failure')
run: |
sleep 30
- name: Create manifests - Attempt 2
if: (steps.manifest_attempt1.outcome == 'failure')
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
IMAGE=${{ matrix.registry }}/${GITHUB_REPOSITORY}
TAG=${GITHUB_REF//refs\/heads\//}
SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
VERSION=${{ needs.build.outputs.version }}
BRANCH=${{ needs.build.outputs.branch }}
[[ -f linux-amd64.Dockerfile ]] && AMD64=${SOURCE}-linux-amd64
[[ -f linux-arm64.Dockerfile ]] && ARM64=${SOURCE}-linux-arm64
[[ -f linux-arm-v7.Dockerfile ]] && ARMV7=${SOURCE}-linux-arm-v7
docker manifest rm ${IMAGE}:${TAG}${BRANCH} || true
docker manifest create ${IMAGE}:${TAG}${BRANCH} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}${BRANCH}
docker manifest rm ${IMAGE}:${TAG}${BRANCH}-${VERSION//\~/-} || true
docker manifest create ${IMAGE}:${TAG}${BRANCH}-${VERSION//\~/-} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}${BRANCH}-${VERSION//\~/-}
docker manifest rm ${IMAGE}:${TAG}-${GITHUB_SHA:0:7} || true
docker manifest create ${IMAGE}:${TAG}-${GITHUB_SHA:0:7} ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:${TAG}-${GITHUB_SHA:0:7}
IS_LATEST=$(jq -r '.latest // empty' < VERSION.json)
if [[ ${IS_LATEST} == true ]]; then
docker manifest rm ${IMAGE}:latest || true
docker manifest create ${IMAGE}:latest ${AMD64} ${ARM64} ${ARMV7}
docker manifest push ${IMAGE}:latest
fi
notify:
runs-on: ubuntu-20.04
if: always()
needs: [build, publish]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download screenshot
continue-on-error: true
uses: actions/download-artifact@v3
with:
name: screenshot
- name: Login to docker.io
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Send discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
EXTRA_DISCORD_WEBHOOK: ${{ secrets.EXTRA_DISCORD_WEBHOOK }}
GITHUB_OWNER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
BRANCH: ${{ needs.build.outputs.branch }}
STATUS: ${{ needs.publish.result }}
shell: bash
run: |
export DOCKER_CLI_EXPERIMENTAL=enabled
[[ "${STATUS}" == "success" ]] && DIGESTS=$(docker manifest inspect docker.io/${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-${GITHUB_SHA:0:7} | jq -r '.manifests[] | "\(.digest | .[7:19]) \(.platform.os)/\(.platform.architecture)\(.platform.variant // "")"')
COMMIT_MESSAGE="$(curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" -fsSL --retry 5 "https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}" | jq -r .commit.message | head -1)"
[[ "${STATUS}" == "success" ]] && COLOR="3066993"
CHANGELOG=$(jq -r '.changelog' < VERSION.json)
if [[ ${CHANGELOG} != null ]]; then
VERSION="[${VERSION:----}](${CHANGELOG})"
fi
if [[ ! -f "screenshot.png" ]]; then
curl -fsSL --retry 5 "https://hotio.dev/img/pullio-background.png" > screenshot.png
fi
json='{
"embeds": [
{
"title": "'${GITHUB_REPOSITORY}':'${GITHUB_REF//refs\/heads\//}${BRANCH}'",
"url": "https://github.com/'${GITHUB_REPOSITORY}'/actions/runs/'${GITHUB_RUN_ID}'",
"color": '${COLOR:-15158332}',
"fields": [
{
"name": "Commit Message",
"value": "```'${COMMIT_MESSAGE//\"/\\\"}'```"
},
{
"name": "Commit SHA",
"value": "['${GITHUB_SHA:0:7}'](https://github.com/'${GITHUB_REPOSITORY}'/commit/'${GITHUB_SHA}')",
"inline": true
},
{
"name": "Version",
"value": "'${VERSION:----}'",
"inline": true
},
{
"name": "Digests",
"value": "```'"$(echo "${DIGESTS:----}" | tr '\n' '#' | sed 's/#/\\n/g')"'```"
}
],
"footer": {
"text": "Powered by GitHub Actions"
},
"timestamp": "'$(date -u +'%FT%T.%3NZ')'",
"image": {
"url": "attachment://screenshot.png"
}
}
]
}'
curl -fsSL --retry 5 -H "Content-Type: multipart/form-data" -F "[email protected]" -F "payload_json=${json}" "${DISCORD_WEBHOOK}" > /dev/null
if [[ -n ${EXTRA_DISCORD_WEBHOOK} ]]; then
curl -fsSL --retry 5 -H "Content-Type: multipart/form-data" -F "[email protected]" -F "payload_json=${json}" "${EXTRA_DISCORD_WEBHOOK}" > /dev/null
fi