Release automatically when the version on main changes
A new auto-release workflow runs the tests, tags v<version>, publishes a release with that version's changelog section and starts the deploy from the tag. It skips versions that are already tagged and refuses older versions or ones without notes.
This commit is contained in:
parent
37a83c2b3f
commit
c59be2d16d
3 changed files with 92 additions and 9 deletions
75
.github/workflows/auto-release.yml
vendored
Normal file
75
.github/workflows/auto-release.yml
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
name: Auto-release
|
||||
|
||||
# Bumping "version" in package.json on main is the release button: this tags
|
||||
# v<version>, publishes a GitHub release with that version's CHANGELOG section
|
||||
# as notes, and starts the deploy. Releases created with the workflow token do
|
||||
# not fire the "released" event, so the deploy is started explicitly, from the
|
||||
# tag, which keeps the github-pages environment's v* tag rule happy.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths: [package.json]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write # create the tag and the release
|
||||
actions: write # start the deploy workflow
|
||||
|
||||
concurrency:
|
||||
group: auto-release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: 24
|
||||
cache: npm
|
||||
|
||||
- name: Work out the version and whether it is new
|
||||
id: v
|
||||
run: |
|
||||
set -euo pipefail
|
||||
ver=$(node -p "require('./package.json').version")
|
||||
tag="v$ver"
|
||||
echo "ver=$ver" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null; then
|
||||
echo "$tag already exists, nothing to release."
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0
|
||||
fi
|
||||
latest=$(gh release list --repo "$GITHUB_REPOSITORY" --exclude-pre-releases --limit 1 --json tagName -q '.[0].tagName' || true)
|
||||
latest="${latest#v}"
|
||||
if [ -n "$latest" ] && [ "$(printf '%s\n%s\n' "$latest" "$ver" | sort -V | tail -n1)" != "$ver" ]; then
|
||||
echo "::error::$ver is not newer than the latest release $latest"; exit 1
|
||||
fi
|
||||
awk -v v="$ver" 'index($0,"## ["v"]")==1{f=1;next} /^## \[/{f=0} f' CHANGELOG.md | sed -e '/./,$!d' > notes.md
|
||||
if ! grep -q '[^[:space:]]' notes.md; then
|
||||
echo "::error::CHANGELOG.md has no notes under ## [$ver]"; exit 1
|
||||
fi
|
||||
case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Test before releasing
|
||||
if: steps.v.outputs.skip == 'false'
|
||||
run: npm ci && npm test
|
||||
|
||||
- name: Publish the release
|
||||
if: steps.v.outputs.skip == 'false'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
pre=(); [ "${{ steps.v.outputs.pre }}" = "true" ] && pre=(--prerelease)
|
||||
gh release create "${{ steps.v.outputs.tag }}" --repo "$GITHUB_REPOSITORY" \
|
||||
--target "$GITHUB_SHA" --title "${{ steps.v.outputs.ver }}" --notes-file notes.md "${pre[@]}"
|
||||
|
||||
- name: Deploy it
|
||||
# Pre-releases are for testing and never go live.
|
||||
if: steps.v.outputs.skip == 'false' && steps.v.outputs.pre == 'false'
|
||||
run: gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "${{ steps.v.outputs.tag }}" -f tag="${{ steps.v.outputs.tag }}"
|
||||
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
|
|
@ -2,8 +2,9 @@ name: Release to GitHub Pages
|
|||
|
||||
# The live site at https://seriesoftub.es only ever serves a published release.
|
||||
# Pushes to main run CI but never deploy. To ship: bump "version" in
|
||||
# package.json, add a CHANGELOG entry, merge, then publish a GitHub release
|
||||
# tagged v<version>.
|
||||
# package.json and date its CHANGELOG section; auto-release.yml then tags,
|
||||
# publishes the release and starts this workflow from the tag. Publishing a
|
||||
# release by hand works too.
|
||||
on:
|
||||
release:
|
||||
# "released" also fires when a pre-release is promoted to a full release.
|
||||
|
|
|
|||
21
README.md
21
README.md
|
|
@ -55,14 +55,21 @@ tests/ node:test + jsdom
|
|||
|
||||
## Releasing
|
||||
|
||||
Only published releases reach [seriesoftub.es](https://seriesoftub.es). Pushes to
|
||||
`main` run CI and nothing else.
|
||||
Only published releases reach [seriesoftub.es](https://seriesoftub.es). Ordinary
|
||||
pushes to `main` run CI and nothing else; a version bump is the release button.
|
||||
|
||||
1. Bump `version` in `package.json` (semver) and add a `CHANGELOG.md` entry.
|
||||
Write the bullets for players: the build turns that section into the in-game
|
||||
"What's new" card and into `/version.json`, which open games poll to offer a reload.
|
||||
2. Merge to `main`.
|
||||
3. Publish a GitHub release tagged `v<version>`, e.g. `gh release create v1.1.0 --generate-notes`.
|
||||
1. Bump `version` in `package.json` (semver) and rename the changelog's
|
||||
`[Unreleased]` section to `## [<version>] — <date>`. Write the bullets for
|
||||
players: the build turns that section into the in-game "What's new" card and
|
||||
into `/version.json`, which open games poll to offer a reload.
|
||||
2. Push or merge to `main`.
|
||||
|
||||
The **Auto-release** workflow then runs the tests, tags `v<version>`, publishes a
|
||||
GitHub release with that changelog section as notes, and starts the deploy. It
|
||||
does nothing when the tag already exists, and refuses a version older than the
|
||||
latest release or one without changelog notes. A version with a pre-release
|
||||
suffix (`1.2.0-beta.1`) becomes a pre-release and is not deployed. You can still
|
||||
publish a release by hand; the deploy runs the same way.
|
||||
|
||||
The release workflow checks that the tag matches `package.json`, runs the tests,
|
||||
builds, deploys to GitHub Pages and pings IndexNow. It refuses to build when the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue