From ab72c6bd4e3d1e0a23ae18377698bc064c1a0a35 Mon Sep 17 00:00:00 2001 From: SongshGeo Date: Sun, 19 Apr 2026 11:03:28 +0200 Subject: [PATCH] ci: :rocket: add release workflow and version-bump automation - Added .github/workflows/release.yml, triggered on tag push (x.y.z or x.y.z-*); builds the plugin and creates a GitHub release with main.js/manifest.json/styles.css as assets. - Auto-detects pre-release by tag suffix (e.g. -alpha, -beta, -rc) and sets --prerelease accordingly so BRAT beta channel picks it up. - Verifies manifest.json version matches the pushed tag before publishing to prevent out-of-sync releases. - Added version-bump.mjs to keep manifest.json and versions.json in sync with package.json whenever `npm version` runs, reading minAppVersion from the existing manifest. - Wired the version-bump script into package.json's `version` lifecycle, auto-staging manifest.json and versions.json. - Added .npmrc with tag-version-prefix="" so `npm version` produces bare tags (e.g. 2.2.0-beta.1), matching upstream convention. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/release.yml | 54 +++++++++++++++++++++++++++++++++++ .npmrc | 1 + package.json | 3 +- version-bump.mjs | 21 ++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .npmrc create mode 100644 version-bump.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..87ff93e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +name: Release + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+-*" + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: "20.x" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Build plugin + run: npm run build + + - name: Verify manifest version matches tag + run: | + tag="${GITHUB_REF#refs/tags/}" + manifest_version=$(node -p "require('./manifest.json').version") + if [ "$tag" != "$manifest_version" ]; then + echo "::error::Tag '$tag' does not match manifest.json version '$manifest_version'." + echo "Run 'npm version $tag' locally to bump all files in sync, then push the tag." + exit 1 + fi + + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + tag="${GITHUB_REF#refs/tags/}" + if [[ "$tag" == *-* ]]; then + prerelease_flag="--prerelease" + else + prerelease_flag="" + fi + gh release create "$tag" \ + --title "$tag" \ + --notes "Release $tag" \ + $prerelease_flag \ + main.js manifest.json styles.css diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..07baf5b --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +tag-version-prefix= diff --git a/package.json b/package.json index 35f8a8b..e497f78 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "lint": "svelte-check --tsconfig tsconfig.json --fail-on-hints && eslint . --ext .ts", "test:unit": "vitest", "dev": "rollup --config rollup.config.js -w", - "build": "npm run lint && rollup --config rollup.config.js --environment BUILD:production" + "build": "npm run lint && rollup --config rollup.config.js --environment BUILD:production", + "version": "node version-bump.mjs && git add manifest.json versions.json" }, "keywords": [], "author": "", diff --git a/version-bump.mjs b/version-bump.mjs new file mode 100644 index 0000000..b363727 --- /dev/null +++ b/version-bump.mjs @@ -0,0 +1,21 @@ +import { readFileSync, writeFileSync } from "fs"; + +const targetVersion = process.env.npm_package_version; +if (!targetVersion) { + throw new Error( + "npm_package_version is not set; run this via `npm version `." + ); +} + +const manifest = JSON.parse(readFileSync("manifest.json", "utf8")); +const { minAppVersion } = manifest; +manifest.version = targetVersion; +writeFileSync("manifest.json", JSON.stringify(manifest, null, 2) + "\n"); + +const versions = JSON.parse(readFileSync("versions.json", "utf8")); +versions[targetVersion] = minAppVersion; +writeFileSync("versions.json", JSON.stringify(versions, null, 2) + "\n"); + +console.log( + `Synced manifest.json and versions.json to ${targetVersion} (minAppVersion ${minAppVersion}).` +);