Skip to content

Commit 3360cda

Browse files
authored
Merge pull request #20 from dscho/fix-keepalive-in-forks-again
keepalive: avoid diverging commits in forks
2 parents b0e9f79 + 7f46067 commit 3360cda

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

.github/cached/keepalive.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/keepalive.yml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,12 @@ jobs:
2525
git fetch https://github.com/gitgitgadget/gitgitgadget-workflows HEAD &&
2626
if test 0 = $(git rev-list --count HEAD..FETCH_HEAD)
2727
then
28-
exit 0 # let the next step create a commit
28+
exit 0 # nothing to merge
2929
fi &&
3030
git merge --no-edit FETCH_HEAD &&
3131
echo "result=merged" >>$GITHUB_OUTPUT
32-
- name: Create a commit
33-
id: commit
34-
if: steps.merge.outputs.result != 'merged'
35-
run: |
36-
if test workflow_dispatch != '${{ github.event_name }}' &&
37-
test 0 -lt $(git rev-list --count --since=3.weeks.ago HEAD)
38-
then
39-
echo "::notice::No need to keep alive, there were commits in the last three weeks"
40-
echo "result=skip-push" >>$GITHUB_OUTPUT
41-
exit 0
42-
fi &&
43-
mkdir -p .github/cached
44-
file='.github/cached/keepalive.txt'
45-
date >$file
46-
git add "$file"
47-
git commit -m "workflow keepalive"
4832
- name: Push changes
49-
if: steps.commit.outputs.result != 'skip-push'
33+
if: steps.merge.outputs.result == 'merged'
5034
run: |
5135
git push origin HEAD </dev/null || {
5236
for i in 1 2 3 4 5
@@ -57,3 +41,28 @@ jobs:
5741
done
5842
exit 1
5943
}
44+
- name: Obtain a token to reset the inactivity timer
45+
uses: actions/create-github-app-token@v3
46+
id: token
47+
with:
48+
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
49+
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
50+
- name: Reset the 60-day inactivity timer of every active workflow
51+
env:
52+
GH_TOKEN: ${{ steps.token.outputs.token }}
53+
REPO: ${{ github.repository }}
54+
run: |
55+
ret=0
56+
gh api "/repos/$REPO/actions/workflows" --paginate \
57+
--jq '.workflows[] | select(.state == "active") | .path' |
58+
while read -r path
59+
do
60+
name=${path##*/}
61+
echo "Refreshing $name"
62+
gh workflow -R "$REPO" disable "$name" &&
63+
gh workflow -R "$REPO" enable "$name" || {
64+
echo "::error::could not refresh $name; please ensure that it is enabled!" >&2
65+
ret=1
66+
}
67+
done
68+
exit $ret

0 commit comments

Comments
 (0)