From 786d462eab7bbc53a5cfdbe73042782a438ab569 Mon Sep 17 00:00:00 2001 From: Not Darko <93942788+darkobas2@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:38:56 +0100 Subject: [PATCH 1/2] ci: refuse to publish commits that are not on the release branch Add a first step to the publish job that uses the compare API to check that the commit being released is already contained in `main`. A release or tag pointing at a commit that never landed there now fails before anything is checked out, built or published, regardless of environment approval. --- .github/workflows/publish_npmjs.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/publish_npmjs.yml b/.github/workflows/publish_npmjs.yml index 00e40d5..527b7e8 100644 --- a/.github/workflows/publish_npmjs.yml +++ b/.github/workflows/publish_npmjs.yml @@ -14,6 +14,21 @@ jobs: environment: publish 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 + - name: Checkout uses: actions/checkout@v4 From b347b1dbc0b91990b1e7bad20c36828bda841c92 Mon Sep 17 00:00:00 2001 From: darkobas Date: Tue, 10 Nov 2026 09:36:11 +0100 Subject: [PATCH 2/2] ci: run the release-commit check once, in its own job Move the check out of the publishing job(s) into a verify job they need. A bad commit is now rejected before the environment approval is requested and before any job receives publishing secrets or tokens, and verify only gets contents: read. --- .github/workflows/publish_npmjs.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish_npmjs.yml b/.github/workflows/publish_npmjs.yml index 527b7e8..a0156be 100644 --- a/.github/workflows/publish_npmjs.yml +++ b/.github/workflows/publish_npmjs.yml @@ -9,10 +9,12 @@ permissions: contents: read jobs: - publish: + # 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 - environment: publish - + permissions: + contents: read steps: - name: Verify release commit is on a protected branch if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/') @@ -29,6 +31,12 @@ jobs: done echo "::error::$SHA is not on any of: $BRANCHES. Refusing to publish."; exit 1 + publish: + needs: verify + runs-on: ubuntu-latest + environment: publish + + steps: - name: Checkout uses: actions/checkout@v4