From c8cdbedbd6db4e30cb32d54dfe0797efb56c4162 Mon Sep 17 00:00:00 2001 From: log0u7 <70974447+log0u7@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:28:26 +0100 Subject: [PATCH] ci: gate the npm publish on the CI workflow + a release environment - a ci-gate job waits for the CI workflow (both quality jobs) to be green on the exact tag commit before the publish job runs; no CI run on the commit = publish refused. - the publish job now runs in the 'release' environment (tag policy v*, required reviewer log0u7, admin bypass disabled): every publish waits for the explicit approval, no silent releases. --- .github/workflows/publish-npm.yml | 38 +++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index c8832ba..a43dadf 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -4,10 +4,44 @@ on: push: tags: ["v*"] -permissions: {} - +# the tag cannot publish while the CI workflow (both quality jobs) is not +# green on the exact tag commit: the gate polls the Actions API until the +# runs complete, then fails if any of them is not success. jobs: + ci-gate: + name: CI green on the tag commit + runs-on: ubuntu-latest + permissions: + contents: read + actions: read + steps: + - name: Wait for CI on ${{ github.sha }} to complete + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + data='' + total=0 + for i in $(seq 1 90); do + data=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs?head_sha=$GITHUB_SHA" --jq '[.workflow_runs[] | select(.name == "CI")]') + total=$(echo "$data" | jq length) + if [ "$total" -gt 0 ] && [ "$(echo "$data" | jq '[.[] | select(.status != "completed")] | length')" -eq 0 ]; then + break + fi + sleep 10 + done + if [ "$total" -eq 0 ]; then + echo "::error::no CI run found on $GITHUB_SHA — the tag must not publish" + exit 1 + fi + echo "$data" | jq -r '.[] | "\(.name): \(.conclusion // .status)"' + if [ "$(echo "$data" | jq '[.[] | select(.status == "completed" and .conclusion != "success")] | length')" -gt 0 ]; then + echo "::error::CI is not green on $GITHUB_SHA — the tag must not publish" + exit 1 + fi + publish: + needs: ci-gate + environment: release runs-on: ubuntu-latest permissions: contents: read