From 14bd42311621f8254e5633c726dab9c8ecc0921269f7ea7961300f83bc00090d Mon Sep 17 00:00:00 2001 From: Jim Cummins Date: Sat, 5 Dec 2026 12:28:06 -0600 Subject: [PATCH] ci: publish the draft GitHub release once its staged npm version is approved --- .../workflows/publish-approved-releases.yml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/publish-approved-releases.yml diff --git a/.github/workflows/publish-approved-releases.yml b/.github/workflows/publish-approved-releases.yml new file mode 100644 index 0000000..cf80509 --- /dev/null +++ b/.github/workflows/publish-approved-releases.yml @@ -0,0 +1,42 @@ +name: Publish approved releases +# The release workflow stages each version on npm and creates a draft GitHub +# release. A staged version can't be installed until a maintainer runs +# `npm stage approve`. npm doesn't notify GitHub when that happens, so this +# checks npm on a schedule and publishes each draft release whose version is +# now on npm. Run it by hand to publish right after approving: +# gh workflow run publish-approved-releases.yml +# A rejected stage never reaches npm, so its draft stays a draft. Delete that +# draft and its tag by hand. +"on": + schedule: + - cron: "*/15 * * * *" + workflow_dispatch: +permissions: + contents: write +concurrency: + group: publish-approved-releases +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + sparse-checkout: package.json + sparse-checkout-cone-mode: false + - name: Publish drafts whose version is on npm + env: + GH_TOKEN: ${{ github.token }} + run: | + package=$(jq -r .name package.json) + # Oldest first, so the newest release ends up marked "Latest". + gh release list --limit 50 --json tagName,isDraft \ + --jq '[.[] | select(.isDraft)] | reverse | .[].tagName' | + while read -r tag; do + version=${tag#v} + if [ "$(npm view "$package@$version" version 2>/dev/null)" = "$version" ]; then + echo "$package@$version is on npm: publishing release $tag" + gh release edit "$tag" --draft=false + else + echo "$package@$version is not on npm yet: leaving $tag as a draft" + fi + done