From bf2c05a368360f2d0dae90f261401661a783872b Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Sun, 16 Nov 2025 18:04:20 +0000 Subject: [PATCH 1/4] feat: add automatic NPM publishing on main branch merges - Add trigger for main branch pushes (in addition to tags) - Generate pre-release versions for main branch: {base}-next.{n}.g{hash} - Use 'next' NPM tag for pre-releases, 'latest' for stable releases - Add version existence check for idempotent publishing - Skip if pre-release already exists (safe for CI re-runs) - Update dist-tag only if stable release already exists - Preserve existing tag validation and CI checks Example versions: - Main branch: 0.1.1-next.6.g9816568 (tagged as 'next') - Tag v0.1.2: 0.1.2 (tagged as 'latest') Follows cmux workflow pattern for automated pre-release publishing. --- .github/workflows/publish.yml | 80 ++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6292e04c..51767394 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,21 +2,26 @@ name: publish on: push: + branches: + - main tags: - - 'v*' + - "v*" + workflow_dispatch: + +permissions: + contents: read + id-token: write # Required for OIDC trusted publishing jobs: publish: name: publish to npm runs-on: ubuntu-latest - permissions: - contents: read - id-token: write # Required for OIDC trusted publishing steps: - - name: Checkout tag + - name: Checkout code uses: actions/checkout@v4 with: ref: ${{ github.ref }} + fetch-depth: 0 # Required for git describe to find tags submodules: recursive - name: Setup Bun @@ -29,7 +34,40 @@ jobs: with: version: 0.15.2 + - name: Generate unique version from git + id: version + run: | + # Get base version from package.json + BASE_VERSION=$(jq -r .version package.json) + + # Generate git describe version + GIT_DESCRIBE=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown") + + if [[ $GITHUB_REF == refs/tags/* ]]; then + # For tags, use the base version as-is (stable release) + NPM_VERSION="${BASE_VERSION}" + NPM_TAG="latest" + echo "Publishing stable release: ${NPM_VERSION}" + else + # For main branch, create a pre-release version using git describe + # Format: 0.3.0-next.5.g1a2b3c4 (base-next.commits.hash) + GIT_COMMIT=$(git rev-parse --short HEAD) + COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^$(git describe --tags --abbrev=0 2>/dev/null || echo HEAD) 2>/dev/null || echo "0") + NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}" + NPM_TAG="next" + echo "Publishing pre-release: ${NPM_VERSION}" + fi + + echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT + echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT + + # Update package.json with the new version + node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.version = '${NPM_VERSION}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');" + + echo "Updated package.json to version ${NPM_VERSION}" + - name: Validate tag matches package.json version + if: github.ref_type == 'tag' run: | # Extract version from package.json PKG_VERSION=$(jq -r .version package.json) @@ -78,5 +116,35 @@ jobs: node-version: '20' registry-url: 'https://registry.npmjs.org' + - name: Check if version exists + id: check-exists + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + VERSION="${{ steps.version.outputs.version }}" + + if npm view "${PACKAGE_NAME}@${VERSION}" version &>/dev/null; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Version ${VERSION} already exists on npm" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Version ${VERSION} does not exist, will publish" + fi + - name: Publish to npm (with OIDC trusted publishing) - run: npm publish --provenance --access public + if: steps.check-exists.outputs.exists == 'false' + run: npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public + + - name: Update dist-tag (version already exists) + if: steps.check-exists.outputs.exists == 'true' && github.ref_type == 'tag' + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + VERSION="${{ steps.version.outputs.version }}" + TAG="${{ steps.version.outputs.tag }}" + + echo "Version ${VERSION} already published, updating dist-tag to ${TAG}" + npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${TAG}" + + - name: Skip (pre-release already exists) + if: steps.check-exists.outputs.exists == 'true' && github.ref_type != 'tag' + run: | + echo "⏭️ Pre-release version already exists, skipping" From 37ff83b97adb7f323e640e859a2b39969aa4a0c9 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Sun, 16 Nov 2025 18:12:01 +0000 Subject: [PATCH 2/4] refactor: extract NPM publishing to reusable action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create .github/actions/npm-publish for reusable publish logic - CI workflow now publishes pre-releases after all checks pass on main - Publish workflow simplified to just run checks + call action for tags - Publishing only happens after fmt, lint, typecheck, test, build succeed Benefits: - DRY: Single source of truth for version generation and publishing - Safe: Pre-releases only published after all CI checks pass - Clear: Separate concerns (CI checks vs publishing) - Consistent: Same publish logic for both main and tags Workflows: - Push to main → CI runs all checks → publishes 'next' tag (if checks pass) - Push tag → Publish runs all checks → publishes 'latest' tag (if checks pass) - Pull requests → CI runs all checks → no publishing --- .github/actions/npm-publish/action.yml | 110 +++++++++++++++++++++++++ .github/workflows/ci.yml | 20 +++++ .github/workflows/publish.yml | 102 ++--------------------- 3 files changed, 135 insertions(+), 97 deletions(-) create mode 100644 .github/actions/npm-publish/action.yml diff --git a/.github/actions/npm-publish/action.yml b/.github/actions/npm-publish/action.yml new file mode 100644 index 00000000..7d2e74ab --- /dev/null +++ b/.github/actions/npm-publish/action.yml @@ -0,0 +1,110 @@ +name: Publish to NPM +description: Publish package to NPM with version generation and idempotent checks + +inputs: + is-tag: + description: 'Whether this is a tag push (true) or main branch push (false)' + required: true + +runs: + using: composite + steps: + - name: Setup Node.js with npm 11+ (for trusted publishing) + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Generate unique version from git + id: version + shell: bash + run: | + # Get base version from package.json + BASE_VERSION=$(jq -r .version package.json) + + # Generate git describe version + GIT_DESCRIBE=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown") + + if [[ "${{ inputs.is-tag }}" == "true" ]]; then + # For tags, use the base version as-is (stable release) + NPM_VERSION="${BASE_VERSION}" + NPM_TAG="latest" + echo "Publishing stable release: ${NPM_VERSION}" + else + # For main branch, create a pre-release version using git describe + # Format: 0.3.0-next.5.g1a2b3c4 (base-next.commits.hash) + GIT_COMMIT=$(git rev-parse --short HEAD) + COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^$(git describe --tags --abbrev=0 2>/dev/null || echo HEAD) 2>/dev/null || echo "0") + NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}" + NPM_TAG="next" + echo "Publishing pre-release: ${NPM_VERSION}" + fi + + echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT + echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT + + # Update package.json with the new version + node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.version = '${NPM_VERSION}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');" + + echo "Updated package.json to version ${NPM_VERSION}" + + - name: Validate tag matches package.json version + if: inputs.is-tag == 'true' + shell: bash + run: | + # Extract version from package.json + PKG_VERSION=$(jq -r .version package.json) + + # Extract version from git tag (strip 'v' prefix) + TAG_VERSION=${GITHUB_REF#refs/tags/v} + + echo "Package version: $PKG_VERSION" + echo "Tag version: $TAG_VERSION" + + if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then + echo "❌ Error: Version mismatch!" + echo " package.json version: $PKG_VERSION" + echo " Git tag version: $TAG_VERSION" + echo "" + echo "Please ensure the git tag matches the version in package.json" + exit 1 + fi + + echo "✅ Version validation passed: $PKG_VERSION" + + - name: Check if version exists + id: check-exists + shell: bash + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + VERSION="${{ steps.version.outputs.version }}" + + if npm view "${PACKAGE_NAME}@${VERSION}" version &>/dev/null; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Version ${VERSION} already exists on npm" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Version ${VERSION} does not exist, will publish" + fi + + - name: Publish to npm (with OIDC trusted publishing) + if: steps.check-exists.outputs.exists == 'false' + shell: bash + run: npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public + + - name: Update dist-tag (version already exists) + if: steps.check-exists.outputs.exists == 'true' && inputs.is-tag == 'true' + shell: bash + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + VERSION="${{ steps.version.outputs.version }}" + TAG="${{ steps.version.outputs.tag }}" + + echo "Version ${VERSION} already published, updating dist-tag to ${TAG}" + npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${TAG}" + + - name: Skip (pre-release already exists) + if: steps.check-exists.outputs.exists == 'true' && inputs.is-tag != 'true' + shell: bash + run: | + echo "⏭️ Pre-release version already exists, skipping" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c86f4298..cbc74610 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,3 +113,23 @@ jobs: - name: Build library run: bun run build + + publish: + name: publish to npm + runs-on: ubuntu-latest + # Only publish on main branch pushes after all checks pass + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + needs: [fmt, lint, typecheck, test, build] + permissions: + contents: read + id-token: write # Required for OIDC trusted publishing + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required for git describe to find tags + + - name: Publish to NPM + uses: ./.github/actions/npm-publish + with: + is-tag: 'false' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 51767394..ff9603f4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,11 +2,8 @@ name: publish on: push: - branches: - - main tags: - - "v*" - workflow_dispatch: + - 'v*' permissions: contents: read @@ -17,7 +14,7 @@ jobs: name: publish to npm runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout tag uses: actions/checkout@v4 with: ref: ${{ github.ref }} @@ -34,61 +31,6 @@ jobs: with: version: 0.15.2 - - name: Generate unique version from git - id: version - run: | - # Get base version from package.json - BASE_VERSION=$(jq -r .version package.json) - - # Generate git describe version - GIT_DESCRIBE=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown") - - if [[ $GITHUB_REF == refs/tags/* ]]; then - # For tags, use the base version as-is (stable release) - NPM_VERSION="${BASE_VERSION}" - NPM_TAG="latest" - echo "Publishing stable release: ${NPM_VERSION}" - else - # For main branch, create a pre-release version using git describe - # Format: 0.3.0-next.5.g1a2b3c4 (base-next.commits.hash) - GIT_COMMIT=$(git rev-parse --short HEAD) - COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^$(git describe --tags --abbrev=0 2>/dev/null || echo HEAD) 2>/dev/null || echo "0") - NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}" - NPM_TAG="next" - echo "Publishing pre-release: ${NPM_VERSION}" - fi - - echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT - echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT - - # Update package.json with the new version - node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.version = '${NPM_VERSION}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');" - - echo "Updated package.json to version ${NPM_VERSION}" - - - name: Validate tag matches package.json version - if: github.ref_type == 'tag' - run: | - # Extract version from package.json - PKG_VERSION=$(jq -r .version package.json) - - # Extract version from git tag (strip 'v' prefix) - TAG_VERSION=${GITHUB_REF#refs/tags/v} - - echo "Package version: $PKG_VERSION" - echo "Tag version: $TAG_VERSION" - - if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then - echo "❌ Error: Version mismatch!" - echo " package.json version: $PKG_VERSION" - echo " Git tag version: $TAG_VERSION" - echo "" - echo "Please ensure the git tag matches the version in package.json" - exit 1 - fi - - echo "✅ Version validation passed: $PKG_VERSION" - - name: Build WASM run: ./scripts/build-wasm.sh @@ -110,41 +52,7 @@ jobs: - name: Build library run: bun run build - - name: Setup Node.js with npm 11+ (for trusted publishing) - uses: actions/setup-node@v4 + - name: Publish to NPM + uses: ./.github/actions/npm-publish with: - node-version: '20' - registry-url: 'https://registry.npmjs.org' - - - name: Check if version exists - id: check-exists - run: | - PACKAGE_NAME=$(node -p "require('./package.json').name") - VERSION="${{ steps.version.outputs.version }}" - - if npm view "${PACKAGE_NAME}@${VERSION}" version &>/dev/null; then - echo "exists=true" >> $GITHUB_OUTPUT - echo "Version ${VERSION} already exists on npm" - else - echo "exists=false" >> $GITHUB_OUTPUT - echo "Version ${VERSION} does not exist, will publish" - fi - - - name: Publish to npm (with OIDC trusted publishing) - if: steps.check-exists.outputs.exists == 'false' - run: npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public - - - name: Update dist-tag (version already exists) - if: steps.check-exists.outputs.exists == 'true' && github.ref_type == 'tag' - run: | - PACKAGE_NAME=$(node -p "require('./package.json').name") - VERSION="${{ steps.version.outputs.version }}" - TAG="${{ steps.version.outputs.tag }}" - - echo "Version ${VERSION} already published, updating dist-tag to ${TAG}" - npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${TAG}" - - - name: Skip (pre-release already exists) - if: steps.check-exists.outputs.exists == 'true' && github.ref_type != 'tag' - run: | - echo "⏭️ Pre-release version already exists, skipping" + is-tag: 'true' From 9b553f695aa31fecc90de7df5bace5ba1aff93f5 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Sun, 16 Nov 2025 18:16:21 +0000 Subject: [PATCH 3/4] refactor: remove is-tag input, action now auto-detects context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The action now automatically detects whether it's publishing a stable release (from tag) or pre-release (from main) by checking $GITHUB_REF. Benefits: - No flimsy boolean flag to pass around - Action is self-contained and context-aware - Less error-prone (can't pass wrong flag) - Cleaner workflow files (no inputs needed) - Better logging (shows trigger source) The action inspects $GITHUB_REF: - refs/tags/* → stable release (latest tag) - refs/heads/main → pre-release (next tag) --- .github/actions/npm-publish/action.yml | 28 ++++++++++++-------------- .github/workflows/ci.yml | 2 -- .github/workflows/publish.yml | 2 -- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/actions/npm-publish/action.yml b/.github/actions/npm-publish/action.yml index 7d2e74ab..8ee7ae8c 100644 --- a/.github/actions/npm-publish/action.yml +++ b/.github/actions/npm-publish/action.yml @@ -1,10 +1,5 @@ name: Publish to NPM -description: Publish package to NPM with version generation and idempotent checks - -inputs: - is-tag: - description: 'Whether this is a tag push (true) or main branch push (false)' - required: true +description: Publish package to NPM with automatic version generation and idempotent checks runs: using: composite @@ -22,26 +17,29 @@ runs: # Get base version from package.json BASE_VERSION=$(jq -r .version package.json) - # Generate git describe version - GIT_DESCRIBE=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown") - - if [[ "${{ inputs.is-tag }}" == "true" ]]; then + # Auto-detect if this is a tag or branch push + if [[ $GITHUB_REF == refs/tags/* ]]; then + IS_TAG=true # For tags, use the base version as-is (stable release) NPM_VERSION="${BASE_VERSION}" NPM_TAG="latest" - echo "Publishing stable release: ${NPM_VERSION}" + echo "📦 Publishing stable release: ${NPM_VERSION}" + echo " Trigger: Tag ${GITHUB_REF#refs/tags/}" else + IS_TAG=false # For main branch, create a pre-release version using git describe # Format: 0.3.0-next.5.g1a2b3c4 (base-next.commits.hash) GIT_COMMIT=$(git rev-parse --short HEAD) COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^$(git describe --tags --abbrev=0 2>/dev/null || echo HEAD) 2>/dev/null || echo "0") NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}" NPM_TAG="next" - echo "Publishing pre-release: ${NPM_VERSION}" + echo "🚧 Publishing pre-release: ${NPM_VERSION}" + echo " Trigger: Branch ${GITHUB_REF#refs/heads/}" fi echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT + echo "is_tag=${IS_TAG}" >> $GITHUB_OUTPUT # Update package.json with the new version node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.version = '${NPM_VERSION}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');" @@ -49,7 +47,7 @@ runs: echo "Updated package.json to version ${NPM_VERSION}" - name: Validate tag matches package.json version - if: inputs.is-tag == 'true' + if: steps.version.outputs.is_tag == 'true' shell: bash run: | # Extract version from package.json @@ -93,7 +91,7 @@ runs: run: npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public - name: Update dist-tag (version already exists) - if: steps.check-exists.outputs.exists == 'true' && inputs.is-tag == 'true' + if: steps.check-exists.outputs.exists == 'true' && steps.version.outputs.is_tag == 'true' shell: bash run: | PACKAGE_NAME=$(node -p "require('./package.json').name") @@ -104,7 +102,7 @@ runs: npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${TAG}" - name: Skip (pre-release already exists) - if: steps.check-exists.outputs.exists == 'true' && inputs.is-tag != 'true' + if: steps.check-exists.outputs.exists == 'true' && steps.version.outputs.is_tag != 'true' shell: bash run: | echo "⏭️ Pre-release version already exists, skipping" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbc74610..328ba1ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,5 +131,3 @@ jobs: - name: Publish to NPM uses: ./.github/actions/npm-publish - with: - is-tag: 'false' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ff9603f4..4b97dec6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,5 +54,3 @@ jobs: - name: Publish to NPM uses: ./.github/actions/npm-publish - with: - is-tag: 'true' From 65ae4e0c5fd9096f8c8418edde292f5ada122324 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Sun, 16 Nov 2025 18:24:58 +0000 Subject: [PATCH 4/4] refactor: separate tag detection into dedicated step Moved trigger detection into its own step for better separation of concerns. Benefits: - Single Responsibility: Detection logic isolated from version generation - Clear outputs: is_tag, trigger_type, trigger_name - Easier to test and debug - Other steps can reference ${{ steps.detect.outputs.is_tag }} - Better GitHub Actions UI (shows detection as separate step) The detect step runs first and outputs: - is_tag: 'true' or 'false' - trigger_type: 'tag' or 'branch' - trigger_name: e.g. 'v0.1.1' or 'main' --- .github/actions/npm-publish/action.yml | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/actions/npm-publish/action.yml b/.github/actions/npm-publish/action.yml index 8ee7ae8c..8f19b417 100644 --- a/.github/actions/npm-publish/action.yml +++ b/.github/actions/npm-publish/action.yml @@ -4,29 +4,41 @@ description: Publish package to NPM with automatic version generation and idempo runs: using: composite steps: + - name: Detect trigger type + id: detect + shell: bash + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo "is_tag=true" >> $GITHUB_OUTPUT + echo "trigger_type=tag" >> $GITHUB_OUTPUT + echo "trigger_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + echo "📦 Detected tag push: ${GITHUB_REF#refs/tags/}" + else + echo "is_tag=false" >> $GITHUB_OUTPUT + echo "trigger_type=branch" >> $GITHUB_OUTPUT + echo "trigger_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT + echo "🚧 Detected branch push: ${GITHUB_REF#refs/heads/}" + fi + - name: Setup Node.js with npm 11+ (for trusted publishing) uses: actions/setup-node@v4 with: node-version: '20' registry-url: 'https://registry.npmjs.org' - - name: Generate unique version from git + - name: Generate version id: version shell: bash run: | # Get base version from package.json BASE_VERSION=$(jq -r .version package.json) - # Auto-detect if this is a tag or branch push - if [[ $GITHUB_REF == refs/tags/* ]]; then - IS_TAG=true + if [[ "${{ steps.detect.outputs.is_tag }}" == "true" ]]; then # For tags, use the base version as-is (stable release) NPM_VERSION="${BASE_VERSION}" NPM_TAG="latest" echo "📦 Publishing stable release: ${NPM_VERSION}" - echo " Trigger: Tag ${GITHUB_REF#refs/tags/}" else - IS_TAG=false # For main branch, create a pre-release version using git describe # Format: 0.3.0-next.5.g1a2b3c4 (base-next.commits.hash) GIT_COMMIT=$(git rev-parse --short HEAD) @@ -34,12 +46,10 @@ runs: NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}" NPM_TAG="next" echo "🚧 Publishing pre-release: ${NPM_VERSION}" - echo " Trigger: Branch ${GITHUB_REF#refs/heads/}" fi echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT - echo "is_tag=${IS_TAG}" >> $GITHUB_OUTPUT # Update package.json with the new version node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.version = '${NPM_VERSION}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');" @@ -47,7 +57,7 @@ runs: echo "Updated package.json to version ${NPM_VERSION}" - name: Validate tag matches package.json version - if: steps.version.outputs.is_tag == 'true' + if: steps.detect.outputs.is_tag == 'true' shell: bash run: | # Extract version from package.json @@ -91,7 +101,7 @@ runs: run: npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public - name: Update dist-tag (version already exists) - if: steps.check-exists.outputs.exists == 'true' && steps.version.outputs.is_tag == 'true' + if: steps.check-exists.outputs.exists == 'true' && steps.detect.outputs.is_tag == 'true' shell: bash run: | PACKAGE_NAME=$(node -p "require('./package.json').name") @@ -102,7 +112,7 @@ runs: npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${TAG}" - name: Skip (pre-release already exists) - if: steps.check-exists.outputs.exists == 'true' && steps.version.outputs.is_tag != 'true' + if: steps.check-exists.outputs.exists == 'true' && steps.detect.outputs.is_tag != 'true' shell: bash run: | echo "⏭️ Pre-release version already exists, skipping"