forked from music-assistant/server
-
Notifications
You must be signed in to change notification settings - Fork 2
540 lines (467 loc) · 17.4 KB
/
release.yml
File metadata and controls
540 lines (467 loc) · 17.4 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
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
name: Create Release
on:
workflow_dispatch:
inputs:
version:
description: "Version number (e.g., 1.2.3, 1.2.3b1, or 1.2.3.dev1)"
required: true
type: string
channel:
description: "Release channel"
required: true
type: choice
options:
- stable
- beta
- nightly
important_notes:
description: "Important notes (breaking changes, critical info, etc.)"
required: false
workflow_call:
inputs:
version:
description: "Version number (e.g., 1.2.3, 1.2.3b1, or 1.2.3.dev1)"
required: true
type: string
channel:
description: "Release channel"
required: true
type: string
important_notes:
description: "Important notes (breaking changes, critical info, etc.)"
required: false
type: string
secrets:
PYPI_TOKEN:
required: true
PRIVILEGED_GITHUB_TOKEN:
required: true
env:
PYTHON_VERSION: "3.12"
BASE_IMAGE_VERSION_STABLE: "1.4.11"
BASE_IMAGE_VERSION_BETA: "1.4.12"
BASE_IMAGE_VERSION_NIGHTLY: "1.4.12"
permissions:
contents: read
jobs:
determine-branch:
name: Determine release branch
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.branch.outputs.branch }}
steps:
- name: Determine branch to use
id: branch
run: |
CHANNEL="${{ inputs.channel }}"
if [ "$CHANNEL" = "stable" ]; then
echo "branch=stable" >> $GITHUB_OUTPUT
echo "Using stable branch for stable release"
else
echo "branch=dev" >> $GITHUB_OUTPUT
echo "Using dev branch for $CHANNEL release"
fi
preflight-checks:
name: Run tests and linting before release
needs: determine-branch
uses: ./.github/workflows/test.yml
with:
ref: ${{ needs.determine-branch.outputs.branch }}
validate-and-build:
name: Validate version and build Python artifact
runs-on: ubuntu-latest
needs: [determine-branch, preflight-checks]
outputs:
version: ${{ inputs.version }}
is_prerelease: ${{ steps.validate.outputs.is_prerelease }}
base_image_version: ${{ steps.validate.outputs.base_image_version }}
branch: ${{ needs.determine-branch.outputs.branch }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.determine-branch.outputs.branch }}
fetch-depth: 0
- name: Validate version number format
id: validate
run: |
VERSION="${{ inputs.version }}"
CHANNEL="${{ inputs.channel }}"
# Regex patterns for each channel
STABLE_PATTERN='^[0-9]+\.[0-9]+\.[0-9]+$'
BETA_PATTERN='^[0-9]+\.[0-9]+\.[0-9]+b[0-9]+$'
NIGHTLY_PATTERN='^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+$'
# Validate version format matches channel
case "$CHANNEL" in
stable)
if ! [[ "$VERSION" =~ $STABLE_PATTERN ]]; then
echo "Error: Stable channel requires version format: X.Y.Z (e.g., 1.2.3)"
exit 1
fi
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_STABLE }}" >> $GITHUB_OUTPUT
;;
beta)
if ! [[ "$VERSION" =~ $BETA_PATTERN ]]; then
echo "Error: Beta channel requires version format: X.Y.ZbN (e.g., 1.2.3b1)"
exit 1
fi
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_BETA }}" >> $GITHUB_OUTPUT
;;
nightly)
if ! [[ "$VERSION" =~ $NIGHTLY_PATTERN ]]; then
echo "Error: Nightly channel requires version format: X.Y.Z.devN (e.g., 1.2.3.dev1)"
exit 1
fi
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_NIGHTLY }}" >> $GITHUB_OUTPUT
;;
*)
echo "Error: Invalid channel: $CHANNEL"
exit 1
;;
esac
echo "✅ Version $VERSION is valid for $CHANNEL channel"
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6.2.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build dependencies
run: >-
pip install build tomli tomli-w
- name: Update version in pyproject.toml
shell: python
run: |-
import tomli
import tomli_w
with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)
pyproject["project"]["version"] = "${{ inputs.version }}"
with open("pyproject.toml", "wb") as f:
tomli_w.dump(pyproject, f)
print(f"✅ Updated pyproject.toml version to ${{ inputs.version }}")
- name: Build python package
run: >-
python3 -m build
- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: release-dists
path: dist/
create-release:
name: Create GitHub Release with Release Drafter
runs-on: ubuntu-latest
needs: validate-and-build
permissions:
contents: write
pull-requests: read
outputs:
release_id: ${{ steps.create_release.outputs.id }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.validate-and-build.outputs.branch }}
fetch-depth: 0
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: release-dists
path: dist/
- name: Determine previous version tag
id: prev_version
run: |
CHANNEL="${{ inputs.channel }}"
# Find the previous tag of this channel
case "$CHANNEL" in
stable)
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
;;
beta)
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+b[0-9]+$' | head -n 1)
;;
nightly)
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+$' | head -n 1)
;;
esac
if [ -z "$PREV_TAG" ]; then
echo "⚠️ No previous $CHANNEL release found"
echo "prev_tag=" >> $GITHUB_OUTPUT
echo "has_prev_tag=false" >> $GITHUB_OUTPUT
else
echo "✅ Previous $CHANNEL release: $PREV_TAG"
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "has_prev_tag=true" >> $GITHUB_OUTPUT
fi
- name: Generate complete release notes
id: generate_notes
uses: ./.github/actions/generate-release-notes
with:
version: ${{ inputs.version }}
previous-tag: ${{ steps.prev_version.outputs.prev_tag }}
branch: ${{ needs.validate-and-build.outputs.branch }}
channel: ${{ inputs.channel }}
github-token: ${{ secrets.GITHUB_TOKEN }}
important-notes: ${{ inputs.important_notes }}
- name: Format release title
id: format_title
run: |
VERSION="${{ inputs.version }}"
CHANNEL="${{ inputs.channel }}"
if [[ "$CHANNEL" == "nightly" ]]; then
# Extract base version and date from X.Y.Z.devYYYYMMDD
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.dev([0-9]+)$ ]]; then
BASE="${BASH_REMATCH[1]}"
DATE="${BASH_REMATCH[2]}"
TITLE="$BASE NIGHTLY $DATE"
else
TITLE="$VERSION NIGHTLY"
fi
elif [[ "$CHANNEL" == "beta" ]]; then
# Extract base version and beta number from X.Y.ZbN
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)b([0-9]+)$ ]]; then
BASE="${BASH_REMATCH[1]}"
BETA_NUM="${BASH_REMATCH[2]}"
TITLE="$BASE BETA $BETA_NUM"
else
TITLE="$VERSION BETA"
fi
else
# Stable release - just use the version
TITLE="$VERSION"
fi
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "Release title: $TITLE"
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.version }}
name: ${{ steps.format_title.outputs.title }}
body: ${{ steps.generate_notes.outputs.release-notes }}
prerelease: ${{ needs.validate-and-build.outputs.is_prerelease }}
target_commitish: ${{ needs.validate-and-build.outputs.branch }}
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Output release info
run: |
echo "✅ Created release ${{ inputs.version }}"
echo "Release URL: ${{ steps.create_release.outputs.url }}"
pypi-publish:
name: Publish release to PyPI (stable releases only)
runs-on: ubuntu-latest
needs: create-release
if: inputs.channel == 'stable'
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: release-dists
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
build-and-push-container-image:
name: Build and push Music Assistant Server container to ghcr.io
runs-on: ubuntu-latest
permissions:
packages: write
needs:
- validate-and-build
- create-release
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.validate-and-build.outputs.branch }}
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: release-dists
path: dist/
- name: Log in to the GitHub container registry
uses: docker/login-action@v4.0.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.0.0
- name: Generate Docker tags
id: tags
run: |
VERSION="${{ inputs.version }}"
CHANNEL="${{ inputs.channel }}"
# Extract version components
if [[ "$VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
fi
TAGS="ghcr.io/${{ github.repository_owner }}/server:$VERSION"
case "$CHANNEL" in
stable)
# For stable: add major, minor, major.minor, stable, and latest tags
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:$MAJOR.$MINOR.$PATCH"
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:$MAJOR.$MINOR"
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:$MAJOR"
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:stable"
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:latest"
;;
beta)
# For beta: add beta tag
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:beta"
;;
nightly)
# For nightly: add nightly tag
TAGS="$TAGS,ghcr.io/${{ github.repository_owner }}/server:nightly"
;;
esac
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "Docker tags: $TAGS"
- name: Build and push Docker image
uses: docker/build-push-action@v7.0.0
with:
context: .
platforms: linux/amd64,linux/arm64
file: Dockerfile
tags: ${{ steps.tags.outputs.tags }}
push: true
build-args: |
MASS_VERSION=${{ inputs.version }}
BASE_IMAGE_VERSION=${{ needs.validate-and-build.outputs.base_image_version }}
update-addon-repository:
name: Update Home Assistant Add-on Repository
runs-on: ubuntu-latest
needs:
- validate-and-build
- create-release
- build-and-push-container-image
steps:
- name: Determine addon folder
id: addon_folder
run: |
CHANNEL="${{ inputs.channel }}"
case "$CHANNEL" in
stable)
echo "folder=music_assistant" >> $GITHUB_OUTPUT
echo "Updating stable add-on"
;;
beta)
echo "folder=music_assistant_beta" >> $GITHUB_OUTPUT
echo "Updating beta add-on"
;;
nightly)
echo "folder=music_assistant_nightly" >> $GITHUB_OUTPUT
echo "Updating nightly add-on"
;;
esac
- name: Checkout add-on repository
uses: actions/checkout@v6
with:
repository: music-assistant/home-assistant-addon
token: ${{ secrets.PRIVILEGED_GITHUB_TOKEN }}
path: addon-repo
- name: Get release notes
id: get_notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd addon-repo
# Get the release body from the server repository
RELEASE_NOTES=$(gh release view "${{ inputs.version }}" --repo music-assistant/server --json body --jq .body)
# Save to file for processing
echo "$RELEASE_NOTES" > /tmp/release_notes.md
- name: Update config.yaml version
run: |
ADDON_FOLDER="${{ steps.addon_folder.outputs.folder }}"
VERSION="${{ inputs.version }}"
cd addon-repo/$ADDON_FOLDER
# Update version in config.yaml using sed
sed -i "s/^version: .*/version: $VERSION/" config.yaml
echo "✅ Updated config.yaml to version $VERSION"
- name: Update CHANGELOG.md
run: |
ADDON_FOLDER="${{ steps.addon_folder.outputs.folder }}"
VERSION="${{ inputs.version }}"
cd addon-repo/$ADDON_FOLDER
# Get current date
RELEASE_DATE=$(date +"%d.%m.%Y")
# Read the new release notes
NEW_NOTES=$(cat /tmp/release_notes.md)
# Create new changelog entry
{
echo "# [$VERSION] - $RELEASE_DATE"
echo ""
echo "$NEW_NOTES"
echo ""
echo ""
} > /tmp/new_changelog.md
# If CHANGELOG.md exists, keep only the last 2 versions
if [ -f CHANGELOG.md ]; then
# Extract headers to count versions
VERSION_COUNT=$(grep -c "^# \[" CHANGELOG.md || echo "0")
if [ "$VERSION_COUNT" -ge 2 ]; then
# Keep only first 2 versions (extract everything before the 3rd version header)
awk '/^# \[/{i++}i==3{exit}1' CHANGELOG.md > /tmp/old_changelog.md
# Combine new entry with trimmed old changelog
cat /tmp/new_changelog.md /tmp/old_changelog.md > CHANGELOG.md
else
# Less than 2 versions, just prepend
cat /tmp/new_changelog.md CHANGELOG.md > /tmp/combined_changelog.md
mv /tmp/combined_changelog.md CHANGELOG.md
fi
else
# No existing changelog, create new
mv /tmp/new_changelog.md CHANGELOG.md
fi
echo "✅ Updated CHANGELOG.md with new release"
- name: Commit and push changes
run: |
ADDON_FOLDER="${{ steps.addon_folder.outputs.folder }}"
VERSION="${{ inputs.version }}"
CHANNEL="${{ inputs.channel }}"
cd addon-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$ADDON_FOLDER/config.yaml" "$ADDON_FOLDER/CHANGELOG.md"
git commit -m "🤖 Bump $CHANNEL add-on to version $VERSION" || {
echo "No changes to commit"
exit 0
}
git push
echo "✅ Successfully updated add-on repository"
update-remote-app:
name: Update app.music-assistant.io frontend
runs-on: ubuntu-latest
needs:
- validate-and-build
- create-release
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.validate-and-build.outputs.branch }}
- name: Extract frontend version from pyproject.toml
id: frontend
run: |
# Extract frontend version from pyproject.toml
FRONTEND_VERSION=$(grep 'music-assistant-frontend==' pyproject.toml | sed 's/.*==\([^"]*\).*/\1/')
echo "version=${FRONTEND_VERSION}" >> $GITHUB_OUTPUT
echo "Frontend version: ${FRONTEND_VERSION}"
- name: Trigger app.music-assistant.io update
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.PRIVILEGED_GITHUB_TOKEN }}
repository: music-assistant/app.music-assistant.io
event-type: frontend-update
client-payload: |
{
"channel": "${{ inputs.channel }}",
"frontend_version": "${{ steps.frontend.outputs.version }}"
}
- name: Output update info
run: |
echo "✅ Triggered app.music-assistant.io update"
echo "Channel: ${{ inputs.channel }}"
echo "Frontend version: ${{ steps.frontend.outputs.version }}"