Skip to content

Commit 79f7b18

Browse files
authored
Enhance keepalive workflow to re-enable active workflows
Updated the workflow to re-enable all active workflows with improved error handling and logging.
1 parent 5ca4883 commit 79f7b18

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

.github/workflows/keepalive.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Keep Workflows alive
2-
32
on:
43
workflow_dispatch:
54
schedule:
@@ -15,16 +14,28 @@ jobs:
1514
permissions:
1615
actions: write
1716
steps:
18-
- uses: actions/checkout@v6
19-
- name: Re-enable workflow
17+
- name: Re-enable all active workflows
2018
env:
21-
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN || github.token }}
22-
shell: sh
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
shell: bash
2321
run: |
24-
case "${GITHUB_WORKFLOW_REF:?}" in
25-
"${GITHUB_REPOSITORY:?}"/.github/workflows/*.y*ml@*) ;;
26-
*) false ;;
27-
esac
28-
workflow="${GITHUB_WORKFLOW_REF%%@*}"
29-
workflow="${workflow#${GITHUB_REPOSITORY}/.github/workflows/}"
30-
gh api -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow}/enable"
22+
set -euo pipefail
23+
24+
echo "Fetching active workflows for ${GITHUB_REPOSITORY}..."
25+
26+
workflow_ids=$(gh api --paginate \
27+
"repos/${GITHUB_REPOSITORY}/actions/workflows" \
28+
--jq '.workflows[] | select(.state=="active") | .id')
29+
30+
if [ -z "$workflow_ids" ]; then
31+
echo "No active workflows found."
32+
exit 0
33+
fi
34+
35+
echo "$workflow_ids" | while read -r id; do
36+
name=$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/${id}" --jq '.name')
37+
echo "Re-enabling workflow: ${name} (ID: ${id})"
38+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/${id}/enable"
39+
done
40+
41+
echo "Done."

0 commit comments

Comments
 (0)