Skip to content

v5.27.4

v5.27.4 #1102

Workflow file for this run

name: Release Package to npm
# This workflow handles stable releases, prereleases, and deprecation:
# - Stable: triggered by release event or manual dispatch with 'stable' type
# - Prerelease: triggered by manual dispatch with 'prerelease' type (only from non-protected branches)
# - Deprecate: triggered by manual dispatch with 'deprecate' type (marks a version as deprecated)
on:
release:
types: [published]
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'prerelease'
type: choice
options:
- prerelease
- stable
- deprecate
deprecate_version:
description: 'Version to deprecate (only for deprecate type)'
required: false
type: string
deprecate_message:
description: 'Deprecation message (only for deprecate type)'
required: false
type: string
deprecate_new_latest:
description: 'New latest version (required when deprecating current latest)'
required: false
type: string
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
# For prerelease - only from non-protected branches
# For deprecate - always allowed
if: |
github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'stable') ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease' && github.ref_protected != true) ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- uses: codex-team/action-nodejs-package-info@v1
id: package
- name: Install latest npm (>= 11.5.1)
run: |
[ "$(printf '%s\n' "11.5.1" "$(npm -v)" | sort -V | head -n1)" = "11.5.1" ] || npm install -g npm@latest
shell: bash
- name: Install dependencies
if: inputs.release_type != 'deprecate'
run: npm ci
- name: Run tests
if: inputs.release_type != 'deprecate'
run: npm test
- name: Run type check
if: inputs.release_type != 'deprecate'
run: npm run typecheck
- name: Build package
if: inputs.release_type != 'deprecate'
run: npm run build
# === STABLE RELEASE STEPS ===
- name: Check version matches release tag
if: github.event_name == 'release'
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
RELEASE_TAG=${GITHUB_REF#refs/tags/}
RELEASE_VERSION=${RELEASE_TAG#v}
if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then
echo "Error: package.json version ($PACKAGE_VERSION) does not match release tag ($RELEASE_TAG -> $RELEASE_VERSION)"
exit 1
fi
echo "Version check passed: $PACKAGE_VERSION (from tag $RELEASE_TAG)"
- name: Skip if draft release
if: github.event.release.draft == true
run: |
echo "Skipping publish for draft release"
exit 0
- name: Publish stable to npm
if: (github.event_name == 'release' && github.event.release.draft == false) || (github.event_name == 'workflow_dispatch' && inputs.release_type == 'stable')
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish stable tests to npm
working-directory: tests
if: (github.event_name == 'release' && github.event.release.draft == false) || (github.event_name == 'workflow_dispatch' && inputs.release_type == 'stable')
run: |
npm version ${{steps.package.outputs.version}}
npm ci
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# === PRERELEASE STEPS ===
- name: Set prerelease version
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: npm version --no-git-tag-version 0.0.0-rc-$(git branch --show-current)-${{github.run_id}}
- name: Publish prerelease to npm
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: npm publish --tag $(git branch --show-current) --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Set prerelease version for tests
working-directory: tests
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: |
npm ci
npm version --no-git-tag-version 0.0.0-rc-$(git branch --show-current)-${{github.run_id}}
- name: Publish prerelease tests to npm
working-directory: tests
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: npm publish --tag $(git branch --show-current) --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# === DEPRECATE STEPS ===
- name: Validate deprecate inputs
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate'
run: |
if [[ -z "${{ inputs.deprecate_version }}" ]]; then
echo "::error::deprecate_version is required for deprecate action"
exit 1
fi
if [[ -z "${{ inputs.deprecate_message }}" ]]; then
echo "::error::deprecate_message is required for deprecate action"
exit 1
fi
- name: Deprecate version
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -e
PACKAGE="${{ steps.package.outputs.name }}"
LATEST="$(npm view $PACKAGE@latest version 2>/dev/null || echo '')"
VERSION="${{ inputs.deprecate_version }}"
MESSAGE="${{ inputs.deprecate_message }}"
TARGET="$PACKAGE@$VERSION"
if [[ "$LATEST" == "$VERSION" ]]; then
if [[ -z "${{ inputs.deprecate_new_latest }}" ]]; then
echo "::error::deprecate_new_latest is required when deprecating the current latest version ($LATEST)"
exit 1
fi
echo "::notice::Setting new latest tag to $PACKAGE@${{ inputs.deprecate_new_latest }}"
npm dist-tag add "$PACKAGE@${{ inputs.deprecate_new_latest }}" latest
fi
echo "::notice::Deprecating $TARGET. Reason: $MESSAGE"
npm deprecate "$TARGET" "$MESSAGE"