From 7f357cb46c961f0310b29b255c8a7f41349f1882 Mon Sep 17 00:00:00 2001 From: JoshiCodes <55353244+JoshiCodes@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:16:22 +0100 Subject: [PATCH] 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. --- .github/workflows/build.yaml | 91 ++++++++++++++++++++++++++++-------- DECISIONS.md | 1 + README.md | 19 +++++--- SUMMARY.md | 4 +- 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b16751a..f3ff2a4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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:.*\(.*\).*:\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 diff --git a/DECISIONS.md b/DECISIONS.md index 9ad893a..93a41d3 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -7,6 +7,7 @@ One line per decision, with the reason. - Target Jellyfin **10.11.11** (`Jellyfin.Controller` / `Jellyfin.Model` 10.11.11, `net9.0`): it is the last 10.11 release on NuGet; the nuspec of that package lists `net9.0` as its only framework. Versions live in `Directory.Build.props`. - `targetAbi` is `10.11.0.0`: the plugin only uses APIs that exist across 10.11, so it should not be pinned to the patch release it was compiled against. - Removed the template's `.github` workflows and Renovate preset: they call reusable workflows and secrets of the Jellyfin organisation and cannot run elsewhere. Replaced by one self-contained workflow. +- Releases are driven by the version, not by hand-made tags: a push to `main` whose `build.yaml` version has no `v` tag is tagged and released by the workflow. The plugin repository manifest is a release asset carried forward from release to release, so nothing has to be committed back by CI. - Removed the template's `.vscode` folder: it assumes a local checkout of the Jellyfin server and web client next to the repo. - No analyzer warnings are suppressed project-wide. The only suppressions are three `CA2100` pragmas in `Storage/` where a command text is assigned from a constant string, which the analyzer cannot see through a helper. - The test project does not reference the StyleCop/`AllEnabledByDefault` analyzer set: XML docs and naming rules on test methods add noise without value. It still builds with warnings as errors. diff --git a/README.md b/README.md index dfb4398..8c48e9a 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,8 @@ Watch-time stats are collected on the server and cover all clients. ### From a plugin repository -1. Host the plugin zip and a `manifest.json` somewhere your server can reach (see [Hosting your own repository](#hosting-your-own-repository)). -2. In Jellyfin: **Dashboard → Plugins → Manage Repositories → New Repository**, enter the URL of your `manifest.json`. -3. Install **Herald** from the catalogue and restart the server. +1. In Jellyfin: **Dashboard → Plugins → Manage Repositories → New Repository**, enter `https://github.com/JoshiCodes/jellyfin-Herald/releases/latest/download/manifest.json`. +2. Install **Herald** from the catalogue and restart the server. ### Manually @@ -178,18 +177,24 @@ jprm plugin build . --output artifacts This writes `artifacts/herald_.zip`. The Jellyfin version, target framework and SQLite version are set in `Directory.Build.props`; `targetAbi` is in `build.yaml`. -Pushing a tag such as `v1.0.0` runs the GitHub Actions workflow, which builds, tests, packages and attaches the zip to the release of that tag. +## Releasing + +The version lives in `build.yaml` (`version`) and `Directory.Build.props` (`Version`, `AssemblyVersion`, `FileVersion`); keep them equal, the workflow fails otherwise. Put the release notes in `changelog` in `build.yaml`. + +Every push to `main` builds and tests. If the version has no `v` tag yet, the workflow also creates that tag and a GitHub release with two assets: the plugin zip and a `manifest.json` that lists this and all earlier releases. So a release is: bump the version, push. ## Hosting your own repository -`manifest.json` in this repository is a sample. Replace the checksum (MD5 of the zip) and the timestamp, or let jprm write it: +The `manifest.json` attached to the latest release is a complete plugin repository; the URL under [Installation](#installation) always points at it. The `manifest.json` in the source tree is only a sample of the format. + +To host it elsewhere, build the manifest yourself: ```sh jprm repo init ./repo -jprm repo add --plugin-url https://github.com/JoshiCodes/jellyfin-Herald/releases/download/v1.0.0/herald_1.0.0.0.zip ./repo artifacts/herald_1.0.0.0.zip +jprm repo add --plugin-url https://example.org/herald/herald_1.0.0.0.zip ./repo artifacts/herald_1.0.0.0.zip ``` -Serve the resulting `manifest.json` over HTTP(S) and add its URL in Jellyfin as described above. +Serve the resulting `manifest.json` and the zip over HTTP(S) and add the manifest URL in Jellyfin. ## License diff --git a/SUMMARY.md b/SUMMARY.md index 440e8c4..c187a67 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -8,7 +8,7 @@ - **Client injection**: registered with the File Transformation plugin by reflection at startup; a warning is logged when that plugin is missing. Manual fallbacks are documented. - **Watch-time stats**: playback start/progress/stop events are turned into daily per-user aggregates; `GET /Herald/Stats` and a sortable "Stats" tab show them; a daily scheduled task drops rows older than 90 days. - **Storage**: one SQLite database in Jellyfin's data directory, using the `Microsoft.Data.Sqlite` that the server ships. Versioned migrations, serialized writes. -- **Project plumbing**: xUnit test project (56 tests), `build.yaml` for jprm, a GitHub Actions workflow (build, test, package, attach zip to the release on tag push), a sample `manifest.json`, `README.md`, `DECISIONS.md`. +- **Project plumbing**: xUnit test project (56 tests), `build.yaml` for jprm, a GitHub Actions workflow (build, test, package; tags and releases automatically when the version changes), a sample `manifest.json`, `README.md`, `DECISIONS.md`. ## What was verified, and how @@ -35,7 +35,6 @@ Two bugs were found and fixed through the container test: the unanchored File Tr - File Transformation was tested in version 3.0.3.0 only. Its registration API is found by reflection, so a rename on their side turns into the logged warning, not a crash. - Stats were verified with simulated reports, not with a real player. The systematic inaccuracies are listed in the README. - The UI is English only. -- The release part of the GitHub workflow (tag push) has not run yet. - Must-accept is a record of consent, not an access gate: nothing on the server is blocked for users who have not accepted. ## Environment notes @@ -46,6 +45,5 @@ Two bugs were found and fixed through the container test: the unanchored File Tr ## Next steps -- Push a `v1.0.0` tag, check the release workflow, and put the real checksum and timestamp into `manifest.json`. - Try the popup on the themes and devices your users actually have. - Optional: start/end dates for notices, a history of earlier rounds in the responses view, translations.