-
Notifications
You must be signed in to change notification settings - Fork 13
287 lines (240 loc) · 10.8 KB
/
BuildDockerPush.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
name: Build and push docker images
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
schedule:
- cron: '0 2 * * MON'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
# https://github.com/marketplace/actions/setup-net-core-sdk
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"
# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v4
# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test
- name: Run unit tests
run: dotnet test ./PlexCleanerTests/PlexCleanerTests.csproj
version:
name: Version
runs-on: ubuntu-latest
needs: test
outputs:
SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}
AssemblyVersion: ${{ steps.nbgv.outputs.AssemblyVersion }}
AssemblyFileVersion: ${{ steps.nbgv.outputs.AssemblyFileVersion }}
AssemblyInformationalVersion: ${{ steps.nbgv.outputs.AssemblyInformationalVersion }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# https://github.com/marketplace/actions/nerdbank-gitversioning
- name: Run Nerdbank.GitVersioning tool
id: nbgv
uses: dotnet/nbgv@master
buildpush:
name: Build and push
runs-on: ubuntu-latest
needs: version
strategy:
fail-fast: false
max-parallel: 4
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
matrix:
include:
- file: ./Docker/Debian.Stable.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-scope: debian
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'debian' || 'debian-develop' }}
- file: ./Docker/Debian.Testing.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-scope: debian-testing
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'debian-testing' || 'debian-testing-develop' }}
- file: ./Docker/Alpine.Stable.Dockerfile
platforms: linux/amd64,linux/arm64
cache-scope: alpine
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'alpine' || 'alpine-develop' }}
- file: ./Docker/Alpine.Edge.Dockerfile
platforms: linux/amd64,linux/arm64
cache-scope: alpine-edge
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'alpine-edge' || 'alpine-edge-develop' }}
- file: ./Docker/Ubuntu.Savoury.Dockerfile
platforms: linux/amd64
cache-scope: savoury
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'savoury' || 'savoury-develop' }}
- file: ./Docker/Ubuntu.Rolling.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-scope: ubuntu
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'ubuntu' || 'ubuntu-develop' }}
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'latest' || 'develop' }}
docker.io/ptr727/plexcleaner:${{ needs.version.outputs.SemVer2 }}
- file: ./Docker/Ubuntu.Devel.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-scope: ubuntu-devel
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'ubuntu-devel' || 'ubuntu-devel-develop' }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v4
# https://github.com/marketplace/actions/docker-setup-qemu
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Setup Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
# https://github.com/marketplace/actions/docker-login
- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Docker build and push
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.file }}
push: ${{ (github.event_name != 'pull_request') }}
# TODO: How to test for secret not null and avoid "null= is not a valid secret"
secrets: ${{ matrix.secrets }}=${{ secrets[matrix.secrets] }}
tags: ${{ matrix.tags }}
platforms: ${{ matrix.platforms }}
build-args: |
LABEL_VERSION=${{ needs.version.outputs.SemVer2 }}
BUILD_CONFIGURATION=${{ endsWith(github.ref, 'refs/heads/main') && 'Release' || 'Debug' }}
BUILD_VERSION=${{ needs.version.outputs.AssemblyVersion }}
BUILD_FILE_VERSION=${{ needs.version.outputs.AssemblyFileVersion }}
BUILD_ASSEMBLY_VERSION=${{ needs.version.outputs.AssemblyFileVersion }}
BUILD_INFORMATION_VERSION=${{ needs.version.outputs.AssemblyInformationalVersion }}
BUILD_PACKAGE_VERSION=${{ needs.version.outputs.SemVer2 }}
toolversions:
name: Tool versions
runs-on: ubuntu-latest
needs: buildpush
if: ${{ github.event_name != 'pull_request' }}
strategy:
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
matrix:
include:
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'debian' || 'debian-develop' }}
file: debian.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'debian-testing' || 'debian-testing-develop' }}
file: debian-testing.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'alpine' || 'alpine-develop' }}
file: alpine.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'alpine-edge' || 'alpine-edge-develop' }}
file: alpine-edge.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'ubuntu' || 'ubuntu-develop' }}
file: ubuntu.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'ubuntu-devel' || 'ubuntu-devel-develop' }}
file: ubuntu-devel.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'savoury' || 'savoury-develop' }}
file: savoury.ver
steps:
- name: Get image size
run: |
mkdir -p ${{ runner.temp }}/versions
touch ${{ runner.temp }}/versions/${{ matrix.file }}
echo Image: docker.io/ptr727/plexcleaner:${{ matrix.tag }} >> ${{ runner.temp }}/versions/${{ matrix.file }}
echo Size: $(docker manifest inspect -v docker.io/ptr727/plexcleaner:${{ matrix.tag }} | jq '.[] | select(.Descriptor.platform.architecture=="amd64") | [.OCIManifest.layers[].size] | add' | numfmt --to=iec) >> ${{ runner.temp }}/versions/${{ matrix.file }}
# https://github.com/marketplace/actions/docker-run-action
- name: Write tool versions to file
uses: addnab/docker-run-action@v3
with:
image: docker.io/ptr727/plexcleaner:${{ matrix.tag }}
options: --volume ${{ runner.temp }}/versions:/versions
run: |
echo OS: $(. /etc/os-release; echo $PRETTY_NAME) >> /versions/${{ matrix.file }}
echo dotNET: $(dotnet --info) >> /versions/${{ matrix.file }}
echo PlexCleaner: $(/PlexCleaner/PlexCleaner --version) >> /versions/${{ matrix.file }}
echo HandBrakeCLI: $(HandBrakeCLI --version) >> /versions/${{ matrix.file }}
echo MediaInfo: $(mediainfo --version) >> /versions/${{ matrix.file }}
echo MkvMerge: $(mkvmerge --version) >> /versions/${{ matrix.file }}
echo FfMpeg: $(ffmpeg -version) >> /versions/${{ matrix.file }}
- name: Print versions
run: cat ${{ runner.temp }}/versions/${{ matrix.file }}
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload version artifacts
uses: actions/upload-artifact@v4
with:
name: versions-${{ matrix.file }}
path: ${{ runner.temp }}/versions/${{ matrix.file }}
updatereadme:
name: Create Docker README.md
runs-on: ubuntu-latest
needs: toolversions
if: ${{ (github.event_name != 'pull_request') && (endsWith(github.ref, 'refs/heads/main')) }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v4
# https://github.com/marketplace/actions/download-a-build-artifact
- name: Download version artifacts
uses: actions/download-artifact@v4
with:
pattern: versions-*
merge-multiple: true
path: ${{ runner.temp }}/versions
- name: Create README.md from README.m4
run: m4 --include=${{ runner.temp }}/versions ./Docker/README.m4 > ${{ runner.temp }}/README.md
# https://github.com/marketplace/actions/docker-hub-description
- name: Update Docker Hub README.md
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ptr727/plexcleaner
short-description: ${{ github.event.repository.description }}
readme-filepath: ${{ runner.temp }}/README.md
datebadge:
name: Date badge
runs-on: ubuntu-latest
needs: buildpush
if: ${{ (github.event_name != 'pull_request') && (endsWith(github.ref, 'refs/heads/main')) }}
steps:
- id: date
run: |
echo "date=$(date)" >> $GITHUB_OUTPUT
# https://github.com/marketplace/actions/bring-your-own-badge
- name: Build date badge
uses: RubbaBoy/BYOB@v1
with:
name: lastbuild
label: "Last Build"
icon: "github"
status: ${{ steps.date.outputs.date }}
color: "blue"
github_token: ${{ secrets.GITHUB_TOKEN }}