Simplify publish workflow and restore auto release

This commit is contained in:
Advait Paliwal
2026-04-15 18:17:28 -07:00
parent 82cafd10cc
commit 080bf8ad2c

View File

@@ -5,62 +5,63 @@ env:
on: on:
push: push:
tags: branches: [main]
- "v*"
workflow_dispatch: workflow_dispatch:
inputs:
tag:
description: Existing git tag to publish and release (for example: v0.2.18)
required: true
type: string
jobs: jobs:
verify: version-check:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
outputs: outputs:
tag: ${{ steps.meta.outputs.tag }} version: ${{ steps.version.outputs.version }}
version: ${{ steps.meta.outputs.version }} should_release: ${{ steps.version.outputs.should_release }}
steps: steps:
- name: Resolve release metadata - uses: actions/checkout@v6
id: meta - uses: actions/setup-node@v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- id: version
shell: bash shell: bash
env: env:
INPUT_TAG: ${{ github.event.inputs.tag }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF_NAME: ${{ github.ref_name }}
run: | run: |
TAG="${INPUT_TAG:-$REF_NAME}" LOCAL=$(node -p "require('./package.json').version")
VERSION="${TAG#v}" echo "version=$LOCAL" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT" if gh release view "v$LOCAL" >/dev/null 2>&1; then
echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
verify:
needs: version-check
if: needs.version-check.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
with:
ref: refs/tags/${{ steps.meta.outputs.tag }}
- uses: actions/setup-node@v6 - uses: actions/setup-node@v6
with: with:
node-version: 24 node-version: 24
registry-url: "https://registry.npmjs.org" registry-url: "https://registry.npmjs.org"
- run: npm ci - run: npm ci
- name: Verify package version matches tag
shell: bash
run: |
ACTUAL="$(node -p "require('./package.json').version")"
EXPECTED="${{ steps.meta.outputs.version }}"
test "$ACTUAL" = "$EXPECTED"
- run: npm test - run: npm test
- run: npm pack - run: npm pack
publish-npm: publish-npm:
needs: verify needs:
- version-check
- verify
if: needs.version-check.outputs.should_release == 'true' && needs.verify.result == 'success'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
id-token: write id-token: write
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
with:
ref: refs/tags/${{ needs.verify.outputs.tag }}
- uses: actions/setup-node@v6 - uses: actions/setup-node@v6
with: with:
node-version: 24 node-version: 24
@@ -69,7 +70,8 @@ jobs:
- run: npm publish --provenance --access public - run: npm publish --provenance --access public
build-native-bundles: build-native-bundles:
needs: verify needs: version-check
if: needs.version-check.outputs.should_release == 'true'
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -87,8 +89,6 @@ jobs:
contents: read contents: read
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
with:
ref: refs/tags/${{ needs.verify.outputs.tag }}
- uses: actions/setup-node@v6 - uses: actions/setup-node@v6
with: with:
node-version: 24 node-version: 24
@@ -121,8 +121,10 @@ jobs:
release-github: release-github:
needs: needs:
- version-check
- publish-npm - publish-npm
- build-native-bundles - build-native-bundles
if: needs.version-check.outputs.should_release == 'true' && needs.publish-npm.result == 'success' && needs.build-native-bundles.result == 'success'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: write
@@ -136,17 +138,18 @@ jobs:
env: env:
GH_REPO: ${{ github.repository }} GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.verify.outputs.tag }} VERSION: ${{ needs.version-check.outputs.version }}
run: | run: |
if gh release view "$TAG" >/dev/null 2>&1; then if gh release view "v$VERSION" >/dev/null 2>&1; then
gh release upload "$TAG" release-assets/* --clobber gh release upload "v$VERSION" release-assets/* --clobber
gh release edit "$TAG" \ gh release edit "v$VERSION" \
--title "$TAG" \ --title "v$VERSION" \
--notes "Standalone Feynman bundles for native installation." \ --notes "Standalone Feynman bundles for native installation." \
--draft=false \ --draft=false \
--latest --latest
else else
gh release create "$TAG" release-assets/* \ gh release create "v$VERSION" release-assets/* \
--title "$TAG" \ --title "v$VERSION" \
--notes "Standalone Feynman bundles for native installation." --notes "Standalone Feynman bundles for native installation." \
--target "$GITHUB_SHA"
fi fi