Skip to content

Rerun CI

Rerun CI #5065

Workflow file for this run

name: "Rerun CI"
on:
workflow_run:
workflows:
- "Server Memory CI"
- "License Checker"
types:
- completed
permissions: {}
env:
MAX_RERUNS: '2'
RETRY_DELAY_SECONDS: '180'
jobs:
decide-rerun-action:
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'push' }}
runs-on: ubuntu-latest
outputs:
action: ${{ steps.decision.outputs.action }}
steps:
- name: Decide rerun action
id: decision
env:
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
EVENT_NAME: ${{ github.event.workflow_run.event }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
set -euo pipefail
action="skip"
reason="unsupported event: $EVENT_NAME"
if [[ "$EVENT_NAME" == "push" ]]; then
if (( RUN_ATTEMPT > MAX_RERUNS )); then
reason="retry limit reached"
else
action="rerun"
reason="within retry limit"
fi
fi
{
echo "action=$action"
echo "reason=$reason"
} >> "$GITHUB_OUTPUT"
{
echo "### Rerun CI decision"
echo ""
echo "- Workflow: $WORKFLOW_NAME"
echo "- Source event: $EVENT_NAME"
echo "- Head branch: $HEAD_BRANCH"
echo "- Run ID: $RUN_ID"
echo "- Current attempt: $RUN_ATTEMPT"
echo "- Max automatic reruns: $MAX_RERUNS"
echo "- Delay seconds: $RETRY_DELAY_SECONDS"
echo "- Action: $action"
echo "- Reason: $reason"
} >> "$GITHUB_STEP_SUMMARY"
rerun-failed-jobs:
needs: decide-rerun-action
if: needs.decide-rerun-action.outputs.action == 'rerun'
permissions:
actions: write
contents: read
runs-on: ubuntu-latest
steps:
# workflow_run is privileged: only load code from the default-branch commit.
- name: Checkout trusted retry checker
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: .github/scripts
- name: Check source freshness before waiting
id: initial-freshness
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
run: |
python3 .github/scripts/check-rerun.py \
--repository "$GH_REPO" --run-id "$RUN_ID" \
--run-attempt "$RUN_ATTEMPT" --max-reruns "$MAX_RERUNS"
- name: Wait before rerun
if: steps.initial-freshness.outputs.action == 'rerun'
run: sleep "$RETRY_DELAY_SECONDS"
- name: Check source freshness after waiting
id: freshness
if: steps.initial-freshness.outputs.action == 'rerun'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
run: |
python3 .github/scripts/check-rerun.py \
--repository "$GH_REPO" --run-id "$RUN_ID" \
--run-attempt "$RUN_ATTEMPT" --max-reruns "$MAX_RERUNS"
- name: Rerun failed jobs
if: steps.freshness.outputs.action == 'rerun'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh run rerun ${{ github.event.workflow_run.id }} --failed