|
| 1 | +# /.github/workflows/immortal-workflows.yml |
| 2 | +name: Reset workflows timeout |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 1 1 * *" # Every first of the month at 1am |
| 6 | +jobs: |
| 7 | + immortal-workflows: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - uses: actions/checkout@v6 |
| 11 | + |
| 12 | + - name: Use GitHub CLI |
| 13 | + env: |
| 14 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 15 | + run: | |
| 16 | + echo "Checking and resetting workflows timeout for repository ${{ github.repository }}" |
| 17 | +
|
| 18 | + # Taken from https://github.com/PhrozenByte/gh-workflow-immortality/blob/main/gh-workflow-immortality.sh |
| 19 | + # Replacing gh_api function with direct gh api calls for simplicity |
| 20 | +
|
| 21 | + WORKFLOWS_ALIVE=() |
| 22 | + WORKFLOWS_DEAD=() |
| 23 | + WORKFLOWS_DISABLED=() |
| 24 | +
|
| 25 | + API_RESULT=$(gh api \ |
| 26 | + -H "Accept: application/vnd.github+json" \ |
| 27 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 28 | + /repos/${{ github.repository }}/actions/workflows | jq '.workflows') |
| 29 | +
|
| 30 | + [ -n "$API_RESULT" ] || return 1 |
| 31 | +
|
| 32 | + __RESULT_ALIVE="$(jq -r --arg STATE "active" '.[]|select(.state == $STATE).path' <<< "$API_RESULT")" |
| 33 | + __RESULT_ALIVE="$(sed -ne 's#^\.github/workflows/\(.*\)$#\1#p' <<< "$__RESULT_ALIVE")" |
| 34 | + [ -z "$__RESULT_ALIVE" ] || readarray -t WORKFLOWS_ALIVE <<< "$__RESULT_ALIVE" |
| 35 | +
|
| 36 | + __RESULT_DEAD="$(jq -r --arg STATE "disabled_inactivity" '.[]|select(.state == $STATE).path' <<< "$API_RESULT")" |
| 37 | + __RESULT_DEAD="$(sed -ne 's#^\.github/workflows/\(.*\)$#\1#p' <<< "$__RESULT_DEAD")" |
| 38 | + [ -z "$__RESULT_DEAD" ] || readarray -t WORKFLOWS_DEAD <<< "$__RESULT_DEAD" |
| 39 | +
|
| 40 | + __RESULT_DISABLED="$(jq -r --arg STATE "disabled_manually" '.[]|select(.state == $STATE).path' <<< "$API_RESULT")" |
| 41 | + __RESULT_DISABLED="$(sed -ne 's#^\.github/workflows/\(.*\)$#\1#p' <<< "$__RESULT_DISABLED")" |
| 42 | + [ -z "$__RESULT_DISABLED" ] || readarray -t WORKFLOWS_DISABLED <<< "$__RESULT_DISABLED" |
| 43 | +
|
| 44 | + echo "Found ${#WORKFLOWS_ALIVE[@]} active, ${#WORKFLOWS_DEAD[@]} dead, and ${#WORKFLOWS_DISABLED[@]} disabled workflows" |
| 45 | +
|
| 46 | + # enable still active workflows |
| 47 | + for WORKFLOW in "${WORKFLOWS_ALIVE[@]}"; do |
| 48 | + echo "- Enabling still active workflow: $WORKFLOW" |
| 49 | + if [ -z "$DRY_RUN" ]; then |
| 50 | + gh api \ |
| 51 | + --method PUT \ |
| 52 | + -H "Accept: application/vnd.github+json" \ |
| 53 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 54 | + /repos/${{ github.repository }}/actions/workflows/$WORKFLOW/enable \ |
| 55 | + || { EXIT_CODE=1; true; } |
| 56 | + fi |
| 57 | + done |
| 58 | +
|
| 59 | + # enable dead workflows |
| 60 | + for WORKFLOW in "${WORKFLOWS_DEAD[@]}"; do |
| 61 | + echo "- Enabling dead workflow: $WORKFLOW" |
| 62 | + if [ -z "$DRY_RUN" ]; then |
| 63 | + gh api \ |
| 64 | + --method PUT \ |
| 65 | + -H "Accept: application/vnd.github+json" \ |
| 66 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 67 | + /repos/${{ github.repository }}/actions/workflows/$WORKFLOW/enable \ |
| 68 | + || { EXIT_CODE=1; true; } |
| 69 | + fi |
| 70 | + done |
| 71 | +
|
| 72 | + # print disabled workflows |
| 73 | + for WORKFLOW in "${WORKFLOWS_DISABLED[@]}"; do |
| 74 | + echo "- Found disabled workflow: $WORKFLOW" |
| 75 | + done |
0 commit comments