Add version bump option to publish workflow#748
Conversation
Introduces a 'version_bump' input to the publish GitHub Actions workflow, allowing selection of patch, minor, or major version increments before prerelease generation. The script now applies the specified version bump to the base version before determining the next available prerelease version.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
.github/workflows/publish.yml
Outdated
| # Apply version bump if requested | ||
| BUMP_TYPE="${{ github.event.inputs.version_bump || 'none' }}" | ||
| if [ "$BUMP_TYPE" != "none" ]; then | ||
| echo "Applying $BUMP_TYPE version bump to $BASE_VERSION" | ||
|
|
||
| # Split version into major.minor.patch | ||
| IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION" | ||
|
|
||
| case "$BUMP_TYPE" in | ||
| patch) | ||
| PATCH=$((PATCH + 1)) | ||
| ;; | ||
| minor) | ||
| MINOR=$((MINOR + 1)) | ||
| PATCH=0 | ||
| ;; | ||
| major) | ||
| MAJOR=$((MAJOR + 1)) | ||
| MINOR=0 | ||
| PATCH=0 | ||
| ;; | ||
| esac | ||
|
|
||
| BASE_VERSION="${MAJOR}.${MINOR}.${PATCH}" | ||
| echo "New base version after bump: $BASE_VERSION" | ||
| fi | ||
|
|
||
| # Find the next available prerelease number | ||
| PRERELEASE_NUM=0 | ||
| while true; do | ||
| TEST_VERSION="${BASE_VERSION}-${GITHUB_TAG}.${PRERELEASE_NUM}" | ||
|
|
||
| # Check if this version exists on npm | ||
| if npm view @clickhouse/click-ui@${TEST_VERSION} version 2>/dev/null; then | ||
| echo "Version ${TEST_VERSION} already exists, trying next number..." | ||
| PRERELEASE_NUM=$((PRERELEASE_NUM + 1)) | ||
| else | ||
| # Version doesn't exist, we can use it | ||
| NEW_VERSION="${TEST_VERSION}" | ||
| break | ||
| fi | ||
|
|
||
| # Safety limit to prevent infinite loops | ||
| if [ $PRERELEASE_NUM -gt 100 ]; then | ||
| echo "Error: Too many prerelease versions (>100)" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| echo "Generated prerelease version: $NEW_VERSION" | ||
| npm pkg set version=$NEW_VERSION --no-git-tag-version |
There was a problem hiding this comment.
can't we just npm version $BUMP_TYPE?
.github/workflows/publish.yml
Outdated
| done | ||
|
|
||
| echo "Generated prerelease version: $NEW_VERSION" | ||
| npm pkg set version=$NEW_VERSION --no-git-tag-version |
There was a problem hiding this comment.
I think NEW_VERSION isn't always defined here
Streamlines the publish.yml workflow by removing the version_bump input, consolidating version/tag handling, and improving prerelease version generation. The workflow now auto-increments patch versions for prereleases, sets npm tags more consistently, and adds cleanup for failed releases. This reduces complexity and improves maintainability for both manual and release-triggered publishing.
There was a problem hiding this comment.
Pull request overview
This PR enhances the publish workflow by simplifying tag/version handling and improving prerelease version generation. The workflow now automatically increments patch versions for prerelease tags and ensures unique prerelease numbers to prevent publishing conflicts.
Changes:
- Consolidated tag handling logic for both workflow_dispatch and release triggers
- Improved prerelease version generation to auto-increment patch and track prerelease numbers
- Added cleanup step for failed releases
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Publish to npm with OIDC | ||
| run: npm publish --access public --tag $NPM_TAG --provenance | ||
| - name: update package version (for version inputs only) | ||
| [[ "$IS_VERSION_INPUT" == "false" || "$GITHUB_TAG" =~ (beta|alpha|rc) ]] && NPM_TAG="$GITHUB_TAG" || NPM_TAG="latest" |
There was a problem hiding this comment.
The NPM_TAG logic is incorrect when IS_VERSION_INPUT is false. For prerelease tags like 'beta', NPM_TAG will be set to the tag name (e.g., 'beta'), but for version inputs containing 'beta' (e.g., '0.0.246-beta.1'), it will also set NPM_TAG to the full version string instead of just 'beta'. The condition should be: if IS_VERSION_INPUT is false, use GITHUB_TAG as the npm tag; if IS_VERSION_INPUT is true and contains beta/alpha/rc, use 'beta' (not the full version); otherwise use 'latest'.
| [[ "$IS_VERSION_INPUT" == "false" || "$GITHUB_TAG" =~ (beta|alpha|rc) ]] && NPM_TAG="$GITHUB_TAG" || NPM_TAG="latest" | |
| if [[ "$IS_VERSION_INPUT" == "false" ]]; then | |
| NPM_TAG="$GITHUB_TAG" | |
| elif [[ "$GITHUB_TAG" =~ (beta|alpha|rc) ]]; then | |
| NPM_TAG="beta" | |
| else | |
| NPM_TAG="latest" | |
| fi |
| npm pkg set version=$GITHUB_TAG | ||
| else | ||
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | ||
| IFS='.' read -r MAJOR MINOR PATCH <<< "${LAST_TAG#v}" |
There was a problem hiding this comment.
The PATCH extraction will fail if LAST_TAG contains a prerelease suffix (e.g., 'v0.0.246-beta.1'). The code should strip any prerelease suffix before parsing the version components, similar to how it's done on line 56 for LATEST_VERSION.
| IFS='.' read -r MAJOR MINOR PATCH <<< "${LAST_TAG#v}" | |
| VERSION_NO_V="${LAST_TAG#v}" | |
| VERSION_BASE="${VERSION_NO_V%%-*}" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_BASE" |
| [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && git tag $GITHUB_TAG && git push origin $GITHUB_TAG || true | ||
|
|
There was a problem hiding this comment.
The || true silently ignores all errors including genuine failures like network issues or permission problems. Consider making the tag push conditional with a proper if statement instead of using || true to mask failures.
| [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && git tag $GITHUB_TAG && git push origin $GITHUB_TAG || true | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| if ! git tag "$GITHUB_TAG"; then | |
| echo "::warning::Failed to create git tag $GITHUB_TAG" | |
| elif ! git push origin "$GITHUB_TAG"; then | |
| echo "::warning::Failed to push git tag $GITHUB_TAG" | |
| fi | |
| fi |
| IFS='.' read -r MAJOR MINOR PATCH <<< "${LAST_TAG#v}" | ||
| BASE_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" | ||
|
|
||
| LATEST_VERSION=$(npm view @clickhouse/click-ui@${GITHUB_TAG} version 2>/dev/null || echo "") |
There was a problem hiding this comment.
The package name '@clickhouse/click-ui' is hardcoded. Consider extracting this from package.json using node -p \"require('./package.json').name\" to ensure consistency and avoid maintenance issues if the package name changes.
| LATEST_VERSION=$(npm view @clickhouse/click-ui@${GITHUB_TAG} version 2>/dev/null || echo "") | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| LATEST_VERSION=$(npm view "${PACKAGE_NAME}@${GITHUB_TAG}" version 2>/dev/null || echo "") |
Introduces a 'version_bump' input to the publish GitHub Actions workflow, allowing selection of patch, minor, or major version increments before prerelease generation. The script now applies the specified version bump to the base version before determining the next available prerelease version.
There was also an issue with publishing the same beta version on the same version, so added a fix to move the count up so it won't break