Skip to content

Commit b22e5fb

Browse files
devm33Copilot
andcommitted
Address PR review feedback
- Use semver package for robust version incrementing - Filter out drafts and pre-releases when finding previous tag - Add concurrency guard to prevent publish races - Enable npm caching in setup-node Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 274890d commit b22e5fb

1 file changed

Lines changed: 13 additions & 22 deletions

File tree

.github/workflows/publish.yml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
publish:
2222
runs-on: ubuntu-latest
2323
environment: npm-publish
24+
concurrency:
25+
group: publish-npm
26+
cancel-in-progress: false
2427
steps:
2528
- name: Checkout repository
2629
uses: actions/checkout@v4
@@ -32,6 +35,7 @@ jobs:
3235
with:
3336
node-version: 22
3437
registry-url: "https://registry.npmjs.org"
38+
cache: npm
3539

3640
- name: Get current npm version
3741
id: current_version
@@ -43,31 +47,18 @@ jobs:
4347
4448
- name: Calculate next version
4549
id: next_version
46-
env:
47-
CURRENT: ${{ steps.current_version.outputs.version }}
48-
VERSION_TYPE: ${{ inputs.version_type }}
4950
run: |
50-
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
51-
52-
case "$VERSION_TYPE" in
53-
major)
54-
MAJOR=$((MAJOR + 1))
55-
MINOR=0
56-
PATCH=0
57-
;;
58-
minor)
59-
MINOR=$((MINOR + 1))
60-
PATCH=0
61-
;;
62-
patch)
63-
PATCH=$((PATCH + 1))
64-
;;
65-
esac
66-
67-
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
51+
CURRENT="${{ steps.current_version.outputs.version }}"
52+
NEXT_VERSION=$(npx --yes semver "$CURRENT" -i "$VERSION_TYPE")
53+
if [ -z "$NEXT_VERSION" ]; then
54+
echo "Failed to calculate next version from $CURRENT using increment $VERSION_TYPE" >&2
55+
exit 1
56+
fi
6857
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
6958
echo "Next version: $NEXT_VERSION (incremented $VERSION_TYPE from $CURRENT)"
7059
echo "- Next version: \`$NEXT_VERSION\` (incremented $VERSION_TYPE from \`$CURRENT\`)" >> "$GITHUB_STEP_SUMMARY"
60+
env:
61+
VERSION_TYPE: ${{ inputs.version_type }}
7162

7263
- name: Set package version
7364
env:
@@ -89,7 +80,7 @@ jobs:
8980
- name: Determine previous release tag
9081
id: previous_tag
9182
run: |
92-
PREVIOUS_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName // empty' 2>/dev/null || echo "")
83+
PREVIOUS_TAG=$(gh release list --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName // empty' 2>/dev/null || echo "")
9384
echo "tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT"
9485
if [ -n "$PREVIOUS_TAG" ]; then
9586
echo "Previous release tag: $PREVIOUS_TAG"

0 commit comments

Comments
 (0)