Skip to content

Add version bump option to publish workflow#748

Open
vineethasok wants to merge 2 commits intomainfrom
fix-publish-workflow
Open

Add version bump option to publish workflow#748
vineethasok wants to merge 2 commits intomainfrom
fix-publish-workflow

Conversation

@vineethasok
Copy link
Collaborator

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

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.
@vineethasok vineethasok self-assigned this Jan 8, 2026
@vercel
Copy link

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
click-ui Ready Ready Preview, Comment Jan 9, 2026 2:43pm

@vineethasok vineethasok requested a review from ariser January 8, 2026 10:44
Comment on lines 78 to 128
# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just npm version $BUMP_TYPE?

done

echo "Generated prerelease version: $NEW_VERSION"
npm pkg set version=$NEW_VERSION --no-git-tag-version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Suggested change
[[ "$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

Copilot uses AI. Check for mistakes.
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}"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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"

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +98
[[ "${{ github.event_name }}" == "workflow_dispatch" ]] && git tag $GITHUB_TAG && git push origin $GITHUB_TAG || true

Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
[[ "${{ 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

Copilot uses AI. Check for mistakes.
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 "")
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 "")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants