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
38 changes: 36 additions & 2 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down