Files
hermes-agent/.github/workflows/label-rerun.yml
2026-10-15 05:23:51 -07:00

70 lines
2.8 KiB
YAML

name: Label rerun
# When the ``run-e2e`` label is added, rerun the head commit's CI, Docker and
# Nix runs in full. Their ``detect`` job reads the PR's labels through the API
# (a rerun replays the original event payload), so the rerun turns the Docker
# and Nix slow lanes on (scripts/ci/classify_changes.py). The E2E suites stay
# off on pull requests either way: they run only on release builds.
#
# The review comment updates without help. The poller in
# ci-review-comment.yml watches the CI run through the API. It gets the
# rerun results.
on:
pull_request:
types: [labeled]
permissions:
actions: write
pull-requests: read
concurrency:
group: label-rerun-${{ github.event.pull_request.number }}-${{ github.event.label.name }}
cancel-in-progress: true
jobs:
rerun-with-e2e:
name: Rerun CI with every E2E lane
if: github.event.label.name == 'run-e2e'
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15
steps:
- name: Cancel and rerun the head commit's CI, Docker and Nix runs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR: ${{ github.event.pull_request.number }}
run: |
set -uo pipefail
for workflow in ci.yaml docker.yml nix.yml; do
RUN_ID=$(gh run list --repo "$REPO" --commit "$HEAD_SHA" --workflow "$workflow" \
--event pull_request --limit 1 --json databaseId --jq '.[0].databaseId // empty' || true)
if [ -z "$RUN_ID" ]; then
echo "$workflow: no run for $HEAD_SHA"
continue
fi
# A run in progress was classified without the label: stop it,
# then rerun it once GitHub marks it completed.
STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq .status || echo unknown)
if [ "$STATUS" != completed ]; then
gh run cancel "$RUN_ID" --repo "$REPO" || true
for _ in $(seq 60); do
STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq .status || echo unknown)
[ "$STATUS" = completed ] && break
sleep 5
done
fi
# Same supersede guard as above: never rerun a run for an old head.
CURRENT_HEAD=$(gh pr view "$PR" --repo "$REPO" --json headRefOid --jq .headRefOid || true)
if [ "$CURRENT_HEAD" != "$HEAD_SHA" ]; then
echo "PR head moved to $CURRENT_HEAD; not rerunning superseded $workflow run $RUN_ID."
exit 0
fi
if gh run rerun "$RUN_ID" --repo "$REPO"; then
echo "$workflow: rerunning $RUN_ID"
else
echo "::warning::$workflow: could not rerun $RUN_ID (status $STATUS)"
fi
done