diff --git a/.github/workflows/publish-approved-releases.yml b/.github/workflows/publish-approved-releases.yml new file mode 100644 index 00000000..99257d47 --- /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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ef217cf..99ce402f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,8 +70,10 @@ npm stage download # optional: inspect the tarball npm stage approve ``` -Then publish the draft release at -https://github.com/commitizen/cz-cli/releases. +You don't need to publish the draft GitHub release yourself. The "Publish +approved releases" workflow checks npm every 15 minutes and publishes the draft +once its version is on npm. To publish it right away, run +`gh workflow run publish-approved-releases.yml -R commitizen/cz-cli`. To abandon a staged version instead, run `npm stage reject `, delete the draft release, and delete its tag (`git push origin :refs/tags/vX.Y.Z`)