ci: release automatically when the version changes
A push to main whose build.yaml version has no tag yet creates the tag and a release with the plugin zip and an updated repository manifest.
This commit is contained in:
@@ -3,18 +3,56 @@ name: Build
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ['v*']
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: build-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
tag: ${{ steps.version.outputs.tag }}
|
||||
release: ${{ steps.version.outputs.release }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# build.yaml is the source of truth for the plugin version.
|
||||
# A version without a matching tag on main gets released.
|
||||
- name: Read version
|
||||
id: version
|
||||
run: |
|
||||
version="$(sed -n 's/^version:[[:space:]]*"\{0,1\}\([0-9][0-9.]*\)"\{0,1\}[[:space:]]*$/\1/p' build.yaml)"
|
||||
if [ -z "$version" ]; then
|
||||
echo "::error file=build.yaml::could not read the version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
props="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props)"
|
||||
if [ "$props" != "$version" ]; then
|
||||
echo "::error::build.yaml says $version but Directory.Build.props says $props"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tag="v$version"
|
||||
release=false
|
||||
if [ "$GITHUB_EVENT_NAME" != "pull_request" ] && [ "$GITHUB_REF" = "refs/heads/main" ]; then
|
||||
if [ -z "$(git ls-remote --tags origin "refs/tags/$tag")" ]; then
|
||||
release=true
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
echo "release=$release" >> "$GITHUB_OUTPUT"
|
||||
echo "Version $version, tag $tag, release: $release"
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 9.0.x
|
||||
@@ -33,42 +71,57 @@ jobs:
|
||||
run: |
|
||||
pip install jprm
|
||||
mkdir -p artifacts
|
||||
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
|
||||
# v1.2.3 -> 1.2.3.0, Jellyfin wants four parts
|
||||
version="${GITHUB_REF_NAME#v}"
|
||||
case "$version" in *.*.*.*) ;; *) version="$version.0" ;; esac
|
||||
jprm plugin build . --output artifacts --version "$version"
|
||||
else
|
||||
jprm plugin build . --output artifacts
|
||||
fi
|
||||
jprm plugin build . --output artifacts --version "${{ steps.version.outputs.version }}"
|
||||
ls -l artifacts
|
||||
|
||||
# The repository manifest travels with the releases: take the one from the
|
||||
# latest release, add this version, and publish it again as an asset.
|
||||
- name: Update repository manifest
|
||||
if: steps.version.outputs.release == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ steps.version.outputs.tag }}
|
||||
run: |
|
||||
mkdir -p repo
|
||||
if ! gh release download --repo "$GITHUB_REPOSITORY" --pattern manifest.json --dir repo 2>/dev/null; then
|
||||
jprm repo init repo
|
||||
fi
|
||||
zip="$(ls artifacts/*.zip)"
|
||||
jprm repo add \
|
||||
--plugin-url "https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/$(basename "$zip")" \
|
||||
repo "$zip"
|
||||
cp repo/manifest.json artifacts/manifest.json
|
||||
cat artifacts/manifest.json
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: plugin
|
||||
path: artifacts/*.zip
|
||||
path: |
|
||||
artifacts/*.zip
|
||||
artifacts/manifest.json
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
if: github.ref_type == 'tag'
|
||||
if: needs.build.outputs.release == 'true'
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: plugin
|
||||
path: artifacts
|
||||
|
||||
- name: Attach zip to the release
|
||||
- name: Create tag and release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
TAG: ${{ needs.build.outputs.tag }}
|
||||
run: |
|
||||
md5sum artifacts/*.zip
|
||||
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
|
||||
gh release upload "$GITHUB_REF_NAME" artifacts/*.zip --clobber
|
||||
else
|
||||
gh release create "$GITHUB_REF_NAME" artifacts/*.zip --title "$GITHUB_REF_NAME" --generate-notes
|
||||
fi
|
||||
sed -n '/^changelog:/,$p' build.yaml | sed '1d; s/^ //' > notes.md
|
||||
gh release create "$TAG" artifacts/*.zip artifacts/manifest.json \
|
||||
--target "$GITHUB_SHA" \
|
||||
--title "Herald ${TAG#v}" \
|
||||
--notes-file notes.md
|
||||
|
||||
Reference in New Issue
Block a user