Maintenance: Watchdog #2992
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Maintenance: Watchdog" | |
| on: | |
| schedule: | |
| - cron: '*/15 * * * *' | |
| workflow_dispatch: | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| concurrency: | |
| group: watchdog-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| watchdog: | |
| strategy: | |
| fail-fast: false | |
| max-parallel: 8 | |
| matrix: | |
| # list scripts you want to watch and execute failed jobs x-times | |
| script: | |
| - infrastructure-update-redirector-config | |
| - data-update-base-files-info | |
| - infrastructure-mirror-repository-artifacts | |
| - infrastructure-repository-update | |
| - generate-servers-jsons | |
| name: "${{ matrix.script }}" | |
| runs-on: ubuntu-24.04 | |
| if: ${{ github.repository_owner == 'Armbian' }} | |
| steps: | |
| - name: "Restart ${{ matrix.script }}.yml" | |
| run: | | |
| set -euo pipefail | |
| # Define variables here | |
| ATTEMPTS="3" | |
| SCRIPT="${{ matrix.script }}" | |
| # Get workflow ID | |
| WORKFLOW=$(gh api "/repos/${{ github.repository }}/actions/workflows" | jq -r --arg path ".github/workflows/${SCRIPT}.yml" '.workflows[] | select(.path==$path) | .id') | |
| if [ -z "$WORKFLOW" ]; then | |
| echo "Error: Workflow ${SCRIPT}.yml not found" | |
| exit 1 | |
| fi | |
| # Get the most recent workflow run (sorted by created, descending) | |
| 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}') | |
| ID=$(echo "$RUN_DATA" | jq -r '.id') | |
| STATUS=$(echo "$RUN_DATA" | jq -r '.conclusion') | |
| ATTEMPT=$(echo "$RUN_DATA" | jq -r '.attempt') | |
| if [ -z "$ID" ] || [ "$ID" == "null" ]; then | |
| echo "No workflow runs found for ${SCRIPT}.yml" | |
| exit 0 | |
| fi | |
| # if attempt is lower than 3 and status is "failure", rerun failed jobs | |
| if [ "${ATTEMPT}" -lt "${ATTEMPTS}" ] && [ "$STATUS" == "failure" ]; then | |
| echo "Rerunning failed jobs for ${SCRIPT}.yml (attempt ${ATTEMPT}/${ATTEMPTS}, status: ${STATUS})" | |
| gh api --method POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| "/repos/${{ github.repository }}/actions/runs/${ID}/rerun-failed-jobs" | |
| else | |
| echo "No rerun needed for ${SCRIPT}.yml (attempt ${ATTEMPT}/${ATTEMPTS}, status: ${STATUS})" | |
| fi |