Skip to content

Merge pull request #43 from bardesss/dependabot/nuget/tests/CustomCov… #43

Merge pull request #43 from bardesss/dependabot/nuget/tests/CustomCov…

Merge pull request #43 from bardesss/dependabot/nuget/tests/CustomCov… #43

Workflow file for this run

name: Release
# Releases on every push to main (i.e. when a PR is merged), but only when the
# <Version> in the csproj has not been released yet. To ship a new version:
# bump <Version> in a PR and merge it.
on:
push:
branches: [ main ]
permissions:
contents: write
pull-requests: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
- uses: actions/setup-dotnet@v6
with:
dotnet-version: '10.0.x'
- name: Read version from csproj
id: ver
run: |
VER=$(grep -oPm1 '(?<=<Version>)[^<]+' CustomCoverArt.csproj)
if [ -z "$VER" ]; then echo "No <Version> found in csproj"; exit 1; fi
echo "ver=$VER" >> "$GITHUB_OUTPUT"
echo "tag=v$VER" >> "$GITHUB_OUTPUT"
- name: Already released?
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ steps.ver.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Release ${{ steps.ver.outputs.tag }} already exists — nothing to do."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Build
if: steps.check.outputs.exists == 'false'
run: dotnet build -c Release
- name: Package
if: steps.check.outputs.exists == 'false'
id: pkg
run: |
VER="${{ steps.ver.outputs.ver }}"
mkdir -p dist/stage
cp bin/Release/net10.0/CustomCoverArt.dll dist/stage/
cp bin/Release/net10.0/SixLabors.*.dll dist/stage/
cat > dist/stage/meta.json <<EOF
{
"category": "General",
"guid": "b8f4e2a1-7c3d-4e5f-9a2b-1d6c8e0f3a4b",
"name": "Custom Cover Art",
"description": "Create and manage custom cover art for Jellyfin libraries with advanced text effects and presets.",
"overview": "Generate custom library cover art with text, gradients, blur and custom backgrounds.",
"owner": "Bardesss",
"targetAbi": "12.0.0.0",
"framework": "net10.0",
"version": "$VER",
"timestamp": "$(date -u +%FT%TZ)",
"status": "Active",
"autoUpdate": true
}
EOF
ZIP="customcoverart_${VER}.zip"
(cd dist/stage && zip -r "../$ZIP" .)
echo "zip=$ZIP" >> "$GITHUB_OUTPUT"
echo "chk=$(md5sum "dist/$ZIP" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- name: Create GitHub release
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: >
gh release create "${{ steps.ver.outputs.tag }}"
"dist/${{ steps.pkg.outputs.zip }}"
--title "${{ steps.ver.outputs.tag }}"
--generate-notes
--target "$GITHUB_SHA"
# Opens a PR rather than pushing to main. The branch ruleset on main requires
# changes to go through a pull request and a passing "test" check, so the old
# direct `git push origin HEAD:main` is rejected with GH013 — which fails the
# workflow AFTER the release is already published, leaving the release live but
# invisible to Jellyfin (which reads manifest.json). Merging the PR this opens
# is the last step of a release.
- name: Open manifest.json PR
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
VER="${{ steps.ver.outputs.ver }}"
URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${{ steps.ver.outputs.tag }}/${{ steps.pkg.outputs.zip }}"
# Changelog for this version comes from the matching CHANGELOG.md section.
CHANGELOG=$(awk -v ver="$VER" '$0=="## "ver{f=1;next} /^## /{f=0} f{print}' CHANGELOG.md | sed '/^[[:space:]]*$/d')
NEW=$(jq -n \
--arg v "$VER" \
--arg cl "$CHANGELOG" \
--arg abi "12.0.0.0" \
--arg url "$URL" \
--arg chk "${{ steps.pkg.outputs.chk }}" \
--arg ts "$(date -u +%FT%TZ)" \
'{version:$v, changelog:$cl, targetAbi:$abi, sourceUrl:$url, checksum:$chk, timestamp:$ts}')
# Idempotent: drop any existing entry for this version, then prepend.
jq --argjson e "$NEW" \
'.[0].versions = ([$e] + [ (.[0].versions // [])[] | select(.version != $e.version) ])' \
manifest.json > manifest.tmp
mv manifest.tmp manifest.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add manifest.json
if git diff --cached --quiet; then
echo "manifest already up to date"
exit 0
fi
BRANCH="chore/manifest-$VER"
# Re-running a release must not fail on an existing branch from a prior attempt.
git checkout -b "$BRANCH"
git commit -m "chore: manifest $VER"
git push --force-with-lease origin "$BRANCH"
if gh pr view "$BRANCH" --json number >/dev/null 2>&1; then
echo "PR for $BRANCH already open — the push above updated it."
exit 0
fi
# Body via a heredoc into a file: a multi-line --body argument would have to
# dedent to column 0, which ends the YAML block scalar and breaks the workflow.
TAG="${{ steps.ver.outputs.tag }}"
cat > /tmp/pr-body.md <<EOF
Adds the \`$VER\` entry to \`manifest.json\`, so Jellyfin instances can see the release.
Generated automatically by the Release workflow after publishing [\`$TAG\`](https://github.com/${GITHUB_REPOSITORY}/releases/tag/$TAG). The checksum is the MD5 of the published asset.
**Merging this is the final step of the release** — until it lands, the release exists on GitHub but no Jellyfin server will offer it.
EOF
gh pr create --base main --head "$BRANCH" \
--title "chore: manifest $VER" \
--body-file /tmp/pr-body.md