Skip to content

Commit a4b5ea5

Browse files
committed
feat(gha): check if release tag is for a pre-release and handle accordingly
1 parent e4fbfbf commit a4b5ea5

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

.github/workflows/release.yaml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ jobs:
4040
- name: Install dependencies
4141
run: pnpm install
4242

43+
- name: Check if tag is for a pre-release
44+
id: check-prerelease
45+
run: |
46+
IFS=$' \t\n'; set -ux
47+
48+
# Get clean version from the tag name
49+
version="${GITHUB_REF_NAME#v}"
50+
51+
# Check for hyphen in the version
52+
if [[ "${version}" == *-* ]]; then
53+
: 'Tag is for a pre-release (contains hyphen)'
54+
echo 'prerelease=true' >> "${GITHUB_OUTPUT}"
55+
exit 0
56+
fi
57+
58+
# Extract major, minor, patch
59+
IFS='.' read -r major minor patch <<< "${version%%-*}"
60+
61+
# Fallback in case parts are missing or invalid
62+
major="${major:-0}"
63+
minor="${minor:-0}"
64+
patch="${patch:-0}"
65+
66+
# Check if major version is less than 1
67+
if (( major < 1 )); then
68+
: 'Tag is for a pre-release (major version < 1)'
69+
echo 'prerelease=true' >> "${GITHUB_OUTPUT}"
70+
exit 0
71+
fi
72+
73+
: 'Tag is for a normal release'
74+
echo 'prerelease=false' >> "${GITHUB_OUTPUT}"
75+
4376
- name: Replace GitHub-flavored Markdown alerts with standard Markdown
4477
run: sed -i 's/^> *\[\!\([a-zA-Z]\)\([a-zA-Z]*\)\] */> **\U\1\L\2** /g' ./*.md
4578
# Basically replaces:
@@ -50,7 +83,13 @@ jobs:
5083
- name: Publish to npmjs.com
5184
env:
5285
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
53-
run: pnpm publish --provenance --access=public --no-git-checks
86+
PRERELEASE: ${{ steps.check-prerelease.outputs.prerelease }}
87+
run: |
88+
if [[ "${PRERELEASE}" == 'true' ]]; then
89+
pnpm publish --provenance --access=public --no-git-checks --tag=next
90+
else
91+
pnpm publish --provenance --access=public --no-git-checks
92+
fi
5493
5594
- name: Create a tarball for the GitHub release
5695
run: pnpm pack
@@ -59,6 +98,7 @@ jobs:
5998
uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # v2.0.9
6099
with:
61100
draft: true
101+
prerelease: ${{ steps.check-prerelease.outputs.prerelease }}
62102
generate_release_notes: true
63103
fail_on_unmatched_files: true
64104
files: |

0 commit comments

Comments
 (0)