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