Skip to content

Commit aee9014

Browse files
ci(keepalive): Use custom keepalive workflow
1 parent bdf94bf commit aee9014

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

.github/workflows/keepalive.yml

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,65 @@
1-
name: Keep Alive
2-
on:
3-
4-
schedule:
5-
- cron: '0 3 * * 4'
1+
name: Keepalive Workflow
2+
# This workflow is used to keep a workflow alive
3+
# It must be called by a workflow in the same repository as in the example below:
4+
#
5+
# name: Tests
6+
#
7+
# on:
8+
# schedule:
9+
# - cron: "0 0 * * *"
10+
#
11+
# jobs:
12+
# tests:
13+
# name: Run integration tests
14+
# steps:
15+
# # … whatever steps you need to run your tests
16+
#
17+
# workflow-keepalive:
18+
# if: github.event_name == 'schedule'
19+
# runs-on: ubuntu-latest
20+
# permissions:
21+
# actions: write
22+
# uses: ./.github/workflows/keepalive.yml
623

7-
permissions:
8-
actions: write
24+
on:
25+
workflow_call:
926

1027
jobs:
11-
keep-alive:
12-
13-
name: Keep Alive
28+
enable-workflow:
1429
runs-on: ubuntu-latest
15-
30+
permissions:
31+
actions: write
1632
steps:
17-
18-
- name: Clone project files
19-
uses: actions/checkout@v4
20-
21-
# keepalive-workflow keeps GitHub from turning off tests after 60 days
22-
- uses: gautamkrishnar/keepalive-workflow@v2
23-
with:
24-
time_elapsed: 45
25-
workflow_files: "module-with-static-and-unit-tests.yml"
26-
33+
- name: Enable workflow
34+
env:
35+
GITHUB_TOKEN: ${{ github.token }}
36+
GITHUB_WORKFLOW_REF: ${{ github.workflow_ref }}
37+
GITHUB_REPOSITORY: ${{ github.repository }}
38+
run: |
39+
# Ensure the workflow ref is valid and matches the expected format
40+
# owner/repo/.github/workflows/<some_name>.yml@<ref>
41+
case "${GITHUB_WORKFLOW_REF:?}" in
42+
"${GITHUB_REPOSITORY:?}"/.github/workflows/*.y*ml@*) ;;
43+
*)
44+
echo "❌ Invalid workflow ref: ${GITHUB_WORKFLOW_REF}"
45+
exit 1
46+
;;
47+
esac
48+
# Strip the @<ref> from the workflow ref
49+
# owner/repo/.github/workflows/tests.yml@refs/heads/main -> owner/repo/.github/workflows/tests.yml
50+
workflow="${GITHUB_WORKFLOW_REF%%@*}"
51+
# Extract just the filename from the workflow path
52+
# owner/repo/.github/workflows/tests.yml -> tests.yml
53+
workflow="${workflow#${GITHUB_REPOSITORY}/.github/workflows/}"
54+
# Enable the workflow using the GitHub CLI
55+
echo "Enabling workflow: $workflow"
56+
response=$(gh api -X PUT -i "repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow}/enable")
57+
status_code=$(echo "$response" | grep HTTP | awk '{print $2}')
58+
echo "Response status code: $status_code"
59+
if [ "$status_code" = "204" ]; then
60+
echo "✅ Workflow successfully enabled."
61+
else
62+
echo "❌ Failed to enable workflow. Full response:"
63+
echo "$response"
64+
exit 1
65+
fi

.github/workflows/module-with-static-and-unit-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,9 @@ jobs:
106106
run: |
107107
ddev phpunit vendor/${{ env.EXTENSION_PACKAGE_NAME }}/Test/Unit
108108
109+
workflow-keepalive:
110+
name: Keepalive workflow
111+
if: github.event_name == 'schedule'
112+
uses: "./.github/workflows/keepalive.yml"
113+
permissions:
114+
actions: write

0 commit comments

Comments
 (0)