Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions .github/scripts/approve-held-runs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Approves the pull_request runs GitHub holds on a pull request the Actions
# bot opened or pushed (release-plz's). Usage: approve-held-runs.sh <pr-number>
set -euo pipefail

pr=$1
sha=$(gh pr view "$pr" -R "$GITHUB_REPOSITORY" --json headRefOid -q .headRefOid)

# The runs are created by the push that opened or updated the pull request;
# give them a moment to appear rather than approving nothing.
deadline=$(( $(date +%s) + 120 ))
until [ "$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=${sha}&event=pull_request" -q '.total_count')" -gt 0 ]; do
if [ "$(date +%s)" -gt "$deadline" ]; then
echo "::error::no pull_request run appeared on #${pr} (${sha})"
exit 1
fi
sleep 5
done

for run in $(gh api "repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=${sha}&event=pull_request" \
-q '.workflow_runs[] | select(.conclusion == "action_required") | .id'); do
gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/${run}/approve" > /dev/null
echo "approved run ${run} on #${pr}"
done
19 changes: 8 additions & 11 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@ jobs:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# A PR pushed with GITHUB_TOKEN triggers no pull_request workflows, so
# the checks run through workflow_dispatch on the PR's head; auto-merge
# lands it once they are green.
- name: Run CI on the release PR and enable auto-merge
# GitHub holds the pull_request runs of a pull request the Actions bot
# opened or pushed until they are approved, and the required check
# reports on the pull request only from those runs; auto-merge lands it
# once they are green.
- name: Approve the release PR's CI and enable auto-merge
if: steps.release-plz.outputs.prs_created == 'true'
env:
PR: ${{ steps.release-plz.outputs.pr }}
GH_TOKEN: ${{ github.token }}
NUMBER: ${{ fromJSON(steps.release-plz.outputs.pr).number }}
run: |
set -euo pipefail
number=$(jq -er '.number' <<<"$PR")
head=$(jq -er '.head_branch' <<<"$PR")
gh workflow run ci.yml --repo "$GITHUB_REPOSITORY" --ref "$head"
gh workflow run linux.yml --repo "$GITHUB_REPOSITORY" --ref "$head"
gh workflow run windows.yml --repo "$GITHUB_REPOSITORY" --ref "$head"
gh pr merge "$number" --repo "$GITHUB_REPOSITORY" --auto --merge
bash .github/scripts/approve-held-runs.sh "$NUMBER"
gh pr merge "$NUMBER" --repo "$GITHUB_REPOSITORY" --auto --merge

release:
name: Tag releases
Expand Down
Loading