From 7f435ff70b2076e2d4288ab7656414190aaaf855 Mon Sep 17 00:00:00 2001 From: wudidapaopao Date: Thu, 21 May 2026 10:58:27 +0800 Subject: [PATCH] ci: publish to npm on tag push and derive version from tag Replace the manual main-branch publish flow with tag-driven releases. Pushing a tag like `v2.0.0` now triggers the workflow, writes the stripped tag (e.g. `2.0.0`) into package.json via `npm pkg set` at run time, and publishes. Tags containing a hyphen (e.g. `v2.0.0-beta.1`) are treated as prereleases and published under the `next` dist-tag so they do not move `latest`. This removes the need to bump the version in package.json by hand before each release. --- .github/workflows/chdb-node-test.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/chdb-node-test.yml b/.github/workflows/chdb-node-test.yml index c2790bc..d5f7a58 100644 --- a/.github/workflows/chdb-node-test.yml +++ b/.github/workflows/chdb-node-test.yml @@ -9,6 +9,8 @@ on: branches: [ "main" ] paths-ignore: - '**/.md' + tags: + - 'v*' jobs: @@ -33,8 +35,19 @@ jobs: run: npm install - name: Run tests run: npm run test + - name: Set version from tag + if: startsWith(github.ref, 'refs/tags/v') && matrix.node-version == '18.x' && matrix.os == 'ubuntu-latest' + run: | + VERSION="${GITHUB_REF_NAME#v}" + echo "Publishing version: $VERSION" + npm pkg set version="$VERSION" + if [[ "$VERSION" == *-* ]]; then + echo "NPM_DIST_TAG=next" >> "$GITHUB_ENV" + else + echo "NPM_DIST_TAG=latest" >> "$GITHUB_ENV" + fi - name: Publish to npm - if: github.ref == 'refs/heads/main' && matrix.node-version == '18.x' && matrix.os == 'ubuntu-latest' - run: npm publish + if: startsWith(github.ref, 'refs/tags/v') && matrix.node-version == '18.x' && matrix.os == 'ubuntu-latest' + run: npm publish --tag "$NPM_DIST_TAG" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}