diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3c5b2af6..f372bb17 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,6 +11,9 @@ name: Publish # release with the notes of its commits. One Slack message per released package. # A push with nothing to release ends after the plan. # +# Nothing is released unless every other workflow of the commit (Verify, +# Integration, CodeQL, …) succeeded: the plan waits for them first. +# # npm authentication is OIDC trusted publishing, no NPM_TOKEN: each package's # trusted publisher must name the repository commercelayer/commercelayer-cli # and this workflow file (publish.yml). Run it by hand to resume a release @@ -31,8 +34,40 @@ permissions: id-token: write jobs: + checks: + name: Checks of the commit + runs-on: ubuntu-latest + timeout-minutes: 60 + permissions: + actions: read + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + steps: + - name: Wait for the other workflows of the commit, all green + # The workflow runs of this commit but Publish's own (this one, or an + # earlier failed one that a manual run resumes) + run: | + set -euo pipefail + sleep 30 + while true; do + runs=$(gh run list --commit "$GITHUB_SHA" --limit 100 --json workflowName,status,conclusion \ + --jq '[.[] | select(.workflowName != "Publish")]') + pending=$(jq -r '[.[] | select(.status != "completed") | .workflowName] | join(", ")' <<<"$runs") + if [ -z "$pending" ]; then break; fi + echo "Waiting for: $pending" + sleep 30 + done + jq -r '.[] | "\(.workflowName): \(.conclusion)"' <<<"$runs" + failed=$(jq -r '[.[] | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral") | "\(.workflowName) (\(.conclusion))"] | join(", ")' <<<"$runs") + if [ -n "$failed" ]; then + echo "::error::Not released: $failed did not succeed on $GITHUB_SHA. Fix it, then run Publish by hand (or push the fix)." + exit 1 + fi + plan: name: Versions to release + needs: checks runs-on: ubuntu-latest outputs: commit: ${{ steps.plan.outputs.commit }}