-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (35 loc) · 1.1 KB
/
keepalive.yml
File metadata and controls
41 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Keep Workflows alive
on:
workflow_dispatch:
schedule:
- cron: '20 21 * * *'
push:
branches:
- 'main'
jobs:
keepalive-job:
name: Keepalive Workflow
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Re-enable all active workflows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
echo "Fetching active workflows for ${GITHUB_REPOSITORY}..."
workflow_ids=$(gh api --paginate \
"repos/${GITHUB_REPOSITORY}/actions/workflows" \
--jq '.workflows[] | select(.state=="active") | .id')
if [ -z "$workflow_ids" ]; then
echo "No active workflows found."
exit 0
fi
echo "$workflow_ids" | while read -r id; do
name=$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/${id}" --jq '.name')
echo "Re-enabling workflow: ${name} (ID: ${id})"
gh api -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/${id}/enable"
done
echo "Done."