Skip to content

fix(release): gate release pr automation #6

fix(release): gate release pr automation

fix(release): gate release pr automation #6

Workflow file for this run

name: Release
on:
push:
branches:
- main
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
tag:
description: "Existing release tag to publish, such as v0.1.0"
required: true
type: string
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
jobs:
release-pr:
name: Release PR
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.RELEASE_PLEASE_CREATE_PR == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Create or update release PR
id: release
uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
- name: Checkout release commit
if: ${{ steps.release.outputs.release_created == 'true' }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ steps.release.outputs.sha }}
- name: Set up Node.js
if: ${{ steps.release.outputs.release_created == 'true' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
package-manager-cache: false
- name: Set up pnpm
if: ${{ steps.release.outputs.release_created == 'true' }}
run: corepack enable
- name: Show tool versions
if: ${{ steps.release.outputs.release_created == 'true' }}
run: |
node --version
npm --version
pnpm --version
- name: Install dependencies
if: ${{ steps.release.outputs.release_created == 'true' }}
run: pnpm install --frozen-lockfile
- name: Verify release package
if: ${{ steps.release.outputs.release_created == 'true' }}
run: npm run release:check
- name: Pack release tarball
if: ${{ steps.release.outputs.release_created == 'true' }}
id: pack
run: |
npm pack --json > pack.json
TARBALL="$(node -e "console.log(JSON.parse(require('node:fs').readFileSync('pack.json', 'utf8'))[0].filename)")"
echo "tarball=${TARBALL}" >> "$GITHUB_OUTPUT"
- name: Publish to npm
if: ${{ steps.release.outputs.release_created == 'true' }}
run: npm publish --access public "${{ steps.pack.outputs.tarball }}"
- name: Attach package tarball to GitHub Release
if: ${{ steps.release.outputs.release_created == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "${{ steps.release.outputs.tag_name }}" "${{ steps.pack.outputs.tarball }}" --clobber
publish-tag:
name: Publish existing tag
if: ${{ github.event_name == 'workflow_dispatch' || (startsWith(github.ref, 'refs/tags/') && github.actor != 'github-actions[bot]') }}
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
steps:
- name: Checkout release tag
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.RELEASE_TAG }}
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
package-manager-cache: false
- name: Set up pnpm
run: corepack enable
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Validate package version matches tag
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [ "v${PACKAGE_VERSION}" != "${RELEASE_TAG}" ]; then
echo "package.json version ${PACKAGE_VERSION} does not match tag ${RELEASE_TAG}" >&2
exit 1
fi
- name: Verify release package
run: npm run release:check
- name: Pack release tarball
id: pack
run: |
npm pack --json > pack.json
TARBALL="$(node -e "console.log(JSON.parse(require('node:fs').readFileSync('pack.json', 'utf8'))[0].filename)")"
echo "tarball=${TARBALL}" >> "$GITHUB_OUTPUT"
- name: Publish to npm
run: npm publish --access public "${{ steps.pack.outputs.tarball }}"
- name: Ensure GitHub Release exists
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! gh release view "${RELEASE_TAG}" >/dev/null 2>&1; then
gh release create "${RELEASE_TAG}" --verify-tag --generate-notes --title "${RELEASE_TAG}"
fi
- name: Attach package tarball to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "${RELEASE_TAG}" "${{ steps.pack.outputs.tarball }}" --clobber