Skip to content

Commit f71c801

Browse files
committed
Combine release and prerelease GH Actions workflows into one
The rationale is that npmjs.org only allows a single Trusted Publisher workflow to be configured on a given npm package.
1 parent a3ac7cc commit f71c801

2 files changed

Lines changed: 32 additions & 58 deletions

File tree

.github/workflows/prerelease.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# Stable packages are published to the npm registry by pushing a tag matching the pattern 'v*.*.*'
2-
name: Publish stable release package
1+
# Unified workflow for both prerelease and stable releases
2+
# Prerelease: triggered on push to main
3+
# Stable: triggered on push of tag matching 'v*.*.*'
4+
# NOTE: The reason this is all done in one workflow is because npmjs.com only
5+
# allows one GH Actions file to be setup as a trusted publisher.
6+
name: Publish npm package
37

48
on:
59
push:
10+
branches:
11+
- main
612
tags:
713
- 'v[0-9]+.[0-9]+.[0-9]+'
814

915
permissions:
1016
id-token: write
1117

1218
jobs:
13-
release:
19+
publish:
1420
runs-on: ubuntu-latest
1521
steps:
1622
- uses: actions/checkout@v4
@@ -25,19 +31,31 @@ jobs:
2531
- name: Install dependencies
2632
run: npm ci
2733

28-
- run: npm run postinstall
29-
30-
- name: Set version from tag
34+
- name: Determine version and tag
35+
id: version
3136
run: |
32-
# Strip prefix from current tag to get version number
33-
VERSION=${GITHUB_REF#refs/tags/v}
34-
npm version "$VERSION" --no-git-tag-version
35-
echo "Setting version to $VERSION"
37+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
38+
# Stable release: use tag version
39+
VERSION=${GITHUB_REF#refs/tags/v}
40+
npm version "$VERSION" --no-git-tag-version
41+
TAG="latest"
42+
echo "version=$VERSION" >> $GITHUB_OUTPUT
43+
echo "tag=$TAG" >> $GITHUB_OUTPUT
44+
echo "Setting version to $VERSION for stable release"
45+
else
46+
# Prerelease: bump from latest stable tag
47+
LATEST_TAG=$(git tag --list "v*.*.*" --sort=-v:refname | grep -v '-' | head -n1)
48+
npm version "${LATEST_TAG#v}" --no-git-tag-version
49+
npm version prerelease --preid="dev.${{ github.sha }}" --no-git-tag-version
50+
VERSION=$(node -p "require('./package.json').version")
51+
TAG="dev"
52+
echo "version=$VERSION" >> $GITHUB_OUTPUT
53+
echo "tag=$TAG" >> $GITHUB_OUTPUT
54+
echo "Setting version to $VERSION for prerelease"
55+
fi
3656
3757
- name: Build with remote save enabled
3858
run: VITE_REMOTE_SERVER_URL= VITE_ENABLE_REMOTE_SAVE=true npm run build
3959

40-
- name: Publish stable version to npm
41-
env:
42-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43-
run: npm publish --access public --provenance
60+
- name: Publish to npm
61+
run: npm publish --tag ${{ steps.version.outputs.tag }} --access public --provenance

0 commit comments

Comments
 (0)