Skip to content

Commit 6975d74

Browse files
committed
Add checks for prerelease tags to release workflow and tag prereleases appropriately
1 parent 372dac9 commit 6975d74

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11

22
name: Publish To NPM
33

4-
# This workflow publishes releases to NPM and teh GitHUb package registry
5-
# when releases are published in GitHub.
6-
74
on:
85
release:
96
types: [published]
@@ -17,6 +14,9 @@ jobs:
1714
build_and_pack:
1815
name: Build and pack workspaces (once)
1916
runs-on: ubuntu-latest
17+
outputs:
18+
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
19+
publish_tag: ${{ steps.version.outputs.publish_tag }}
2020
steps:
2121
- name: Checkout repo
2222
uses: actions/checkout@v4
@@ -38,11 +38,29 @@ jobs:
3838
- name: Build
3939
run: npm run build
4040

41+
# Compute prerelease flag & desired dist-tag from top-level package.json version
42+
- name: Determine prerelease tag
43+
id: version
44+
run: |
45+
set -euo pipefail
46+
VERSION="$(node -p 'require("./package.json").version')"
47+
echo "Detected version: $VERSION"
48+
49+
# If version contains a hyphen, it's a prerelease (e.g., 1.2.3-alpha.1)
50+
if [[ "$VERSION" == *-* ]]; then
51+
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
52+
echo "publish_tag=prerelease" >> "$GITHUB_OUTPUT"
53+
echo "This is a prerelease. Will use tag 'prerelease'."
54+
else
55+
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
56+
echo "publish_tag=latest" >> "$GITHUB_OUTPUT"
57+
echo "This is a stable release. Will use tag 'latest'."
58+
fi
59+
4160
# Create tarballs for each workspace so we can publish the exact same artifacts twice
4261
- name: Pack workspaces
4362
run: |
4463
set -euo pipefail
45-
# This produces one .tgz per workspace in the repo root
4664
npm pack --workspaces
4765
echo "Packed tarballs:"
4866
ls -1 *.tgz
@@ -74,15 +92,17 @@ jobs:
7492
registry-url: https://registry.npmjs.org
7593
always-auth: true
7694

77-
- name: Publish tarballs to npmjs.org (with provenance)
95+
- name: Publish tarballs to npmjs.org (with provenance and dist-tag)
7896
env:
7997
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # npm automation token
98+
PUBLISH_TAG: ${{ needs.build_and_pack.outputs.publish_tag }}
8099
run: |
81100
set -euo pipefail
82101
shopt -s nullglob
83102
for tgz in dist-tarballs/*.tgz; do
84-
echo "Publishing $tgz to npmjs.org ..."
85-
npm publish "$tgz" --provenance --access public
103+
echo "Publishing $tgz to npmjs.org with tag '${PUBLISH_TAG}' ..."
104+
# --access public needed for first publish of public packages
105+
npm publish "$tgz" --provenance --access public --tag "${PUBLISH_TAG}"
86106
done
87107
88108
publish_github:
@@ -104,14 +124,14 @@ jobs:
104124
scope: '@finos'
105125
always-auth: true
106126

107-
- name: Publish tarballs to GitHub Packages
127+
- name: Publish tarballs to GitHub Packages (with dist-tag)
108128
env:
109129
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has packages: write via permissions
130+
PUBLISH_TAG: ${{ needs.build_and_pack.outputs.publish_tag }}
110131
run: |
111132
set -euo pipefail
112133
shopt -s nullglob
113134
for tgz in dist-tarballs/*.tgz; do
114-
echo "Publishing $tgz to GitHub Packages ..."
115-
# No --provenance or --access here
116-
npm publish "$tgz"
117-
done
135+
echo "Publishing $tgz to GitHub Packages with tag '${PUBLISH_TAG}' ..."
136+
# GitHub Packages does not support npm provenance; omit --provenance and --access
137+
npm publish "$tgz" --tag "${PUBLISH_TAG}"

0 commit comments

Comments
 (0)