2.9.0 #32
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to NPM | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (optional)' | |
| required: false | |
| default: '' | |
| jobs: | |
| publish: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Checkout publish branch | |
| if: github.event_name == 'release' || github.ref_type == 'tag' | |
| shell: bash | |
| run: | | |
| TARGET_BRANCH="${{ github.event.release.target_commitish || github.event.repository.default_branch }}" | |
| if [[ -z "$TARGET_BRANCH" || "$TARGET_BRANCH" == refs/tags/* || "$TARGET_BRANCH" =~ ^[0-9a-f]{40}$ ]]; then | |
| TARGET_BRANCH="${{ github.event.repository.default_branch }}" | |
| fi | |
| git fetch origin "$TARGET_BRANCH" | |
| git checkout "$TARGET_BRANCH" | |
| - name: Resolve release version | |
| id: release_version | |
| shell: bash | |
| run: | | |
| VERSION="${{ github.event.inputs.version || github.event.release.tag_name || github.ref_name }}" | |
| VERSION="${VERSION#v}" | |
| if [[ -z "$VERSION" ]]; then | |
| echo "Unable to resolve a release version. Provide workflow_dispatch input 'version' or run from a release/tag." >&2 | |
| exit 1 | |
| fi | |
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then | |
| echo "Invalid semver version: $VERSION" >&2 | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Install dependencies | |
| run: pnpm install --no-frozen-lockfile | |
| - name: Build project | |
| run: pnpm build | |
| - name: Run linter | |
| run: pnpm lint | |
| - name: Run tests | |
| run: pnpm test | |
| - name: Set version from input | |
| if: steps.release_version.outputs.version != '' | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| TARGET_VERSION="${{ steps.release_version.outputs.version }}" | |
| if [ "$CURRENT_VERSION" != "$TARGET_VERSION" ]; then | |
| echo "Bumping version from $CURRENT_VERSION to $TARGET_VERSION" | |
| pnpm version "$TARGET_VERSION" --no-git-tag-version | |
| git add package.json | |
| git commit -m "chore: set version to $TARGET_VERSION [skip ci]" | |
| git push origin HEAD:main | |
| else | |
| echo "Version is already $CURRENT_VERSION, skipping bump" | |
| fi | |
| echo "version_bumped=true" >> $GITHUB_OUTPUT | |
| echo "new_version=$TARGET_VERSION" >> $GITHUB_OUTPUT | |
| - name: Publish to NPM | |
| run: pnpm publish --no-git-checks | |
| if: steps.release_version.outputs.version != '' | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish summary | |
| if: steps.release_version.outputs.version | |
| run: | | |
| echo "Published version ${{ steps.release_version.outputs.version }} to npm" >> $GITHUB_STEP_SUMMARY | |
| echo "Publish reason: ${{ steps.release_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "Auto-bumped from published version" >> $GITHUB_STEP_SUMMARY |