Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 71 additions & 73 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag'
description: 'Release tag (version like 0.0.246 or prerelease name like beta/alpha/rc)'
required: true
type: string
branch:
Expand All @@ -17,95 +17,93 @@ jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # For git push and tagging
id-token: write # For OIDC trusted publishing to npm
contents: write
id-token: write
steps:
- name: Set tag from input (manual trigger)
if: github.event_name == 'workflow_dispatch'
- name: Set tag and version type
run: |
echo "GITHUB_TAG=${{ github.event.inputs.tag }}" >> "$GITHUB_ENV"
# Check if input is a semantic version (e.g., 0.0.242) or a tag name (e.g., beta, scss-deprecation)
if [[ "${{ github.event.inputs.tag }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
echo "IS_VERSION_INPUT=true" >> "$GITHUB_ENV"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="${{ github.event.inputs.tag }}"
REF="${{ github.event.inputs.branch }}"
else
echo "IS_VERSION_INPUT=false" >> "$GITHUB_ENV"
TAG="${GITHUB_REF#refs/tags/}"
REF="${{ github.event.release.target_commitish }}"
fi
- name: Set tag from release (automatic trigger)
if: github.event_name == 'release'
run: |
echo "GITHUB_TAG=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"
echo "IS_VERSION_INPUT=true" >> "$GITHUB_ENV"
- name: Checkout repository (manual trigger)
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
token: ${{secrets.PAT_TOKEN}}
fetch-depth: 0
- name: Checkout repository (automatic release)
if: github.event_name == 'release'
uses: actions/checkout@v4
echo "GITHUB_TAG=$TAG" >> "$GITHUB_ENV"
echo "CHECKOUT_REF=$REF" >> "$GITHUB_ENV"
[[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]] && echo "IS_VERSION_INPUT=true" >> "$GITHUB_ENV" || echo "IS_VERSION_INPUT=false" >> "$GITHUB_ENV"

- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.target_commitish }}
token: ${{secrets.PAT_TOKEN}}
ref: ${{ env.CHECKOUT_REF }}
token: ${{ secrets.PAT_TOKEN }}
fetch-depth: 0
- name: Set up Git
run: |
git config user.email "actions@clickhouse.com"
git config user.name "GitHub Actions"
- name: Bump package version (for version inputs)
if: ${{ env.IS_VERSION_INPUT == 'true' }}
run: |
npm pkg set version=$GITHUB_TAG
- name: Generate prerelease version (for tag inputs)
if: ${{ env.IS_VERSION_INPUT == 'false' }}

- name: Set package version
run: |
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
# Extract base version (remove any existing prerelease suffix)
BASE_VERSION=$(echo $CURRENT_VERSION | cut -d'-' -f1)
# Generate prerelease version: base-tagname.0
NEW_VERSION="${BASE_VERSION}-${GITHUB_TAG}.0"
echo "Generated prerelease version: $NEW_VERSION"
npm pkg set version=$NEW_VERSION --no-git-tag-version
if [[ "$IS_VERSION_INPUT" == "true" ]]; then
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.
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.
if [ -z "$LATEST_VERSION" ]; then
PRERELEASE_NUM=0
else
# Extract base version from latest prerelease
LATEST_BASE=$(echo "$LATEST_VERSION" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+" || echo "")

# If base version changed, reset to 0, otherwise increment
if [[ "$LATEST_BASE" == "$BASE_VERSION" ]]; then
PRERELEASE_NUM=$(echo "$LATEST_VERSION" | grep -oE "\.[0-9]+$" | sed 's/\.//')
PRERELEASE_NUM=$((PRERELEASE_NUM + 1))
else
PRERELEASE_NUM=0
fi
fi

NEW_VERSION="${BASE_VERSION}-${GITHUB_TAG}.${PRERELEASE_NUM}"
echo "Version: $NEW_VERSION"
npm pkg set version=$NEW_VERSION --no-git-tag-version
fi

- uses: actions/setup-node@v4
with:
node-version: '22.x' # Node 22 includes npm >= 11.5.1 with OIDC support
- name: Upgrade npm for OIDC support
node-version: '22.x'

- name: Setup dependencies
run: |
npm install -g npm@latest
echo "npm version: $(npm --version)"
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: yarn install --immutable
corepack enable
yarn install --immutable

- run: yarn test
- run: yarn build
- name: Determine npm tag

- name: Publish to npm
run: |
# If it's a version input (e.g., 0.0.242 or 0.0.242-beta.1), check for prerelease keywords
if [[ "$IS_VERSION_INPUT" == "true" ]]; then
if [[ "$GITHUB_TAG" == *"beta"* ]] || [[ "$GITHUB_TAG" == *"alpha"* ]] || [[ "$GITHUB_TAG" == *"rc"* ]]; then
echo "NPM_TAG=beta" >> "$GITHUB_ENV"
else
echo "NPM_TAG=latest" >> "$GITHUB_ENV"
fi
else
# If it's a tag name input (e.g., scss-deprecation), use it as the npm tag
echo "NPM_TAG=$GITHUB_TAG" >> "$GITHUB_ENV"
fi
- 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 publish --access public --tag $NPM_TAG --provenance

- name: Commit and tag version
if: ${{ env.IS_VERSION_INPUT == 'true' }}
run: |
git config user.email "actions@clickhouse.com"
git config user.name "GitHub Actions"
git add package.json yarn.lock
git commit -m 'bump version to ${{ env.GITHUB_TAG }}'
git commit -m "bump version to $GITHUB_TAG"
git push
- name: Create and push git tag (for version inputs only)
if: ${{ github.event_name == 'workflow_dispatch' && env.IS_VERSION_INPUT == 'true' }}
[[ "${{ github.event_name }}" == "workflow_dispatch" ]] && git tag $GITHUB_TAG && git push origin $GITHUB_TAG || true

Comment on lines +97 to +98
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.
- name: Cleanup failed release
if: ${{ failure() && github.event_name == 'release' }}
run: |
git tag $GITHUB_TAG
git push origin $GITHUB_TAG
echo "::warning::Build failed for release ${{ env.GITHUB_TAG }}"
echo "Cleaning up release and tag..."
gh release delete ${{ env.GITHUB_TAG }} --yes --cleanup-tag || true
echo "::notice::Release deleted. Fix the issue and create a new release."
env:
GH_TOKEN: ${{ github.token }}