|
1 | 1 | name: Keep GitHub Actions Alive |
2 | 2 | on: |
3 | | - # Run once a week, well before the 60-day deadline |
4 | | - schedule: |
5 | | - - cron: '0 0 * * SUN' # Runs every Sunday at 00:00 UTC |
6 | 3 | # Allows manual triggering |
7 | 4 | workflow_dispatch: |
| 5 | + # Run once a week, well before the 60-day deadline |
| 6 | + schedule: |
| 7 | + # Run every Sunday at 00:00 UTC |
| 8 | + - cron: '0 0 * * SUN' |
8 | 9 |
|
9 | 10 | jobs: |
10 | 11 | keep_alive: |
11 | 12 | runs-on: ubuntu-latest |
12 | 13 |
|
13 | 14 | # Required permission to interact with the GitHub API to re-enable workflows |
14 | 15 | permissions: |
| 16 | + # Critical: allows enabling workflows |
15 | 17 | actions: write |
16 | 18 |
|
17 | 19 | steps: |
18 | | - - name: Keepalive Workflow (API Mode - No Commit) |
19 | | - uses: gautamkrishnar/keepalive-workflow@v1 |
20 | | - with: |
21 | | - # This defaults to true, which uses the API to re-enable |
22 | | - use_api: true |
23 | | - # The token needs 'actions:write' permission |
24 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
25 | | - # Recommended: Set a threshold lower than 60 days (e.g., 50 days) |
26 | | - time_elapsed_threshold_in_days: 50 |
| 20 | + # Use API to re-enable workflows (clean, no commit) |
| 21 | + - name: Re-enable workflows via GitHub API |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run: | |
| 25 | + # List all workflows that are disabled (by user or inactivity) |
| 26 | + # Note: GitHub API doesn't have direct ?state=disabled filter, so we fetch all and grep jq |
| 27 | + disabled_workflows=$(gh api \ |
| 28 | + -H "Accept: application/vnd.github+json" \ |
| 29 | + "/repos/${{ github.repository }}/actions/workflows" \ |
| 30 | + | jq -r '.workflows[] | select(.state != "active") | .id') |
| 31 | +
|
| 32 | + if [ -z "$disabled_workflows" ]; then |
| 33 | + echo "No disabled workflows found. This is normal if nothing is disabled yet." |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | +
|
| 37 | + count=0 |
| 38 | + for wf_id in $disabled_workflows; do |
| 39 | + gh api \ |
| 40 | + -X PUT \ |
| 41 | + -H "Accept: application/vnd.github+json" \ |
| 42 | + "/repos/${{ github.repository }}/actions/workflows/$wf_id/enable" |
| 43 | + echo "Enabled workflow ID: $wf_id" |
| 44 | + ((count++)) |
| 45 | + done |
| 46 | +
|
| 47 | + echo "Re-enabled $count workflow(s)." |
0 commit comments