-
Notifications
You must be signed in to change notification settings - Fork 8
227 lines (195 loc) · 9.11 KB
/
Copy pathbuild-and-deploy.yml
File metadata and controls
227 lines (195 loc) · 9.11 KB
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
name: Build and Deploy
on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types: [ published ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
FFMPEG_VERSION: '8.1'
DOTNET_VERSION: '10.0.x'
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-24.04, ubuntu-24.04-arm, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install mkvtoolnix (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends mkvtoolnix
- name: Install ffmpeg ${{ env.FFMPEG_VERSION }} (Linux)
if: runner.os == 'Linux'
run: |
set -euo pipefail
case "$(uname -m)" in
x86_64) btbn_arch=linux64 ;;
aarch64) btbn_arch=linuxarm64 ;;
*) echo "Unsupported arch: $(uname -m)" >&2; exit 1 ;;
esac
url="https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n${FFMPEG_VERSION}-latest-${btbn_arch}-gpl-${FFMPEG_VERSION}.tar.xz"
curl -fsSL "$url" -o /tmp/ffmpeg.tar.xz
sudo tar -xJf /tmp/ffmpeg.tar.xz -C /usr/local/bin --strip-components=2 --wildcards '*/bin/ffmpeg' '*/bin/ffprobe'
ffmpeg -version | head -1
- name: Install mkvtoolnix + ffmpeg (macOS)
if: runner.os == 'macOS'
run: |
set -euo pipefail
brew install mkvtoolnix ffmpeg
# Production and the other runners are on ffmpeg 8.1; fail fast if
# brew is behind (the MP4 udta.name round-trip is broken pre-8.0).
major=$(ffmpeg -version | awk 'NR==1 {split($3,v,"."); print v[1]}')
if [ "$major" -lt 8 ]; then
echo "ffmpeg $major is too old; need >= 8.x for MP4 title round-trip" >&2
exit 1
fi
ffmpeg -version | head -1
- name: Install mkvtoolnix + ffmpeg (Windows)
if: runner.os == 'Windows'
run: |
function Install-WithRetry([string]$Package, [scriptblock]$Verify) {
for ($i = 1; $i -le 3; $i++) {
choco install $Package -y --no-progress
if (& $Verify) { return }
Write-Warning "$Package attempt $i failed, retrying in 10s..."
Start-Sleep -Seconds 10
}
throw "Failed to install $Package after 3 attempts"
}
Install-WithRetry 'mkvtoolnix' { Test-Path "C:\Program Files\MKVToolNix\mkvmerge.exe" }
echo "C:\Program Files\MKVToolNix" >> $env:GITHUB_PATH
Install-WithRetry 'ffmpeg' { Get-Command ffmpeg -ErrorAction SilentlyContinue }
$major = (ffmpeg -version | Select-Object -First 1) -replace '.*ffmpeg version (\d+)\..*','$1'
if ([int]$major -lt 8) { throw "ffmpeg $major is too old; need >= 8.x for MP4 title round-trip" }
ffmpeg -version | Select-Object -First 1
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Run Tests
run: dotnet test --configuration Release
build:
name: build (${{ matrix.arch }})
needs: test
if: github.event_name == 'push' || github.event_name == 'release'
strategy:
matrix:
include:
- platform: linux/amd64
arch: amd64
runner: ubuntu-24.04
- platform: linux/arm64
arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Lowercase image name
run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Checkout code
uses: actions/checkout@v5
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish .NET app
run: dotnet publish Muxarr.Web/Muxarr.Web.csproj -c Release -o Muxarr.Web/publish
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: Muxarr.Web
platforms: ${{ matrix.platform }}
build-args: FFMPEG_VERSION=${{ env.FFMPEG_VERSION }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digests-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
manifest:
needs: build
if: github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Lowercase image name
run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Download digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
docker.io/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev,enable=${{ github.event_name == 'push' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' }}
type=semver,pattern={{major}},enable=${{ github.event_name == 'release' && !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}