Skip to content

Commit 772b761

Browse files
committed
ci: add Maintenance: Watchdog workflow
Mirrors the Maintenance: Watchdog workflow from armbian/armbian.github.io. Runs every 15 minutes (and on workflow_dispatch), iterates over a matrix of workflow basenames, and re-runs failed jobs on the most recent run up to 3 attempts. Anything past attempt 3 is left alone. Watched workflows: - build-docker-images (daily 'Docker Images For Repo Handling') - update_docker ('Docker Images for Framework') Catches transient registry / network / runner failures during the nightly image refresh without manual re-runs. Restricted to the Armbian org via the existing repository_owner check pattern from armbian.github.io.
1 parent d2f6b83 commit 772b761

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: "Maintenance: Watchdog"
2+
on:
3+
schedule:
4+
- cron: '*/15 * * * *'
5+
workflow_dispatch:
6+
7+
env:
8+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9+
10+
concurrency:
11+
group: watchdog-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
16+
watchdog:
17+
strategy:
18+
fail-fast: false
19+
max-parallel: 8
20+
matrix:
21+
22+
# list scripts you want to watch and execute failed jobs x-times
23+
script:
24+
- build-docker-images
25+
- update_docker
26+
27+
name: "${{ matrix.script }}"
28+
runs-on: ubuntu-24.04
29+
if: ${{ github.repository_owner == 'Armbian' }}
30+
steps:
31+
32+
- name: "Restart ${{ matrix.script }}.yml"
33+
run: |
34+
set -euo pipefail
35+
36+
# Define variables here
37+
ATTEMPTS="3"
38+
SCRIPT="${{ matrix.script }}"
39+
40+
# Get workflow ID
41+
WORKFLOW=$(gh api "/repos/${{ github.repository }}/actions/workflows" | jq -r --arg path ".github/workflows/${SCRIPT}.yml" '.workflows[] | select(.path==$path) | .id')
42+
43+
if [ -z "$WORKFLOW" ]; then
44+
echo "Error: Workflow ${SCRIPT}.yml not found"
45+
exit 1
46+
fi
47+
48+
# Get the most recent workflow run (sorted by created, descending)
49+
RUN_DATA=$(gh api "/repos/${{ github.repository }}/actions/workflows/${WORKFLOW}/runs?per_page=1" | jq '.workflow_runs[0] | {id: .id, conclusion: .conclusion, attempt: .run_attempt}')
50+
51+
ID=$(echo "$RUN_DATA" | jq -r '.id')
52+
STATUS=$(echo "$RUN_DATA" | jq -r '.conclusion')
53+
ATTEMPT=$(echo "$RUN_DATA" | jq -r '.attempt')
54+
55+
if [ -z "$ID" ] || [ "$ID" == "null" ]; then
56+
echo "No workflow runs found for ${SCRIPT}.yml"
57+
exit 0
58+
fi
59+
60+
# if attempt is lower than 3 and status is "failure", rerun failed jobs
61+
if [ "${ATTEMPT}" -lt "${ATTEMPTS}" ] && [ "$STATUS" == "failure" ]; then
62+
echo "Rerunning failed jobs for ${SCRIPT}.yml (attempt ${ATTEMPT}/${ATTEMPTS}, status: ${STATUS})"
63+
gh api --method POST \
64+
-H "Accept: application/vnd.github+json" \
65+
-H "X-GitHub-Api-Version: 2022-11-28" \
66+
"/repos/${{ github.repository }}/actions/runs/${ID}/rerun-failed-jobs"
67+
else
68+
echo "No rerun needed for ${SCRIPT}.yml (attempt ${ATTEMPT}/${ATTEMPTS}, status: ${STATUS})"
69+
fi

0 commit comments

Comments
 (0)