Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/publish_npmjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ permissions:
contents: read

jobs:
# Runs before the job that waits on the publish approval and gets the OIDC token,
# so a commit that is not on a protected branch is rejected up front.
verify:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Verify release commit is on a protected branch
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.sha }}
BRANCHES: "main"
run: |
set -euo pipefail
for b in $BRANCHES; do
st=$(gh api "repos/$REPO/compare/$b...$SHA" --jq .status 2>/dev/null || echo error)
if [ "$st" = identical ] || [ "$st" = behind ]; then echo "OK: $SHA is on $b"; exit 0; fi
done
echo "::error::$SHA is not on any of: $BRANCHES. Refusing to publish."; exit 1

publish:
needs: verify
runs-on: ubuntu-latest
environment: publish

Expand Down
Loading