-
Notifications
You must be signed in to change notification settings - Fork 4
59 lines (56 loc) · 1.9 KB
/
keepalive.yml
File metadata and controls
59 lines (56 loc) · 1.9 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Keep scheduled workflows alive
on:
schedule:
- cron: "23 19 3,17 * *" # 7:23pm on every 3rd and 17th of the month
workflow_dispatch:
env:
GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@github'"
jobs:
job:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: 'true'
- name: Merge the upstream default branch
id: merge
if: github.event.repository.fork == true
run: |
git fetch --unshallow origin &&
git fetch https://github.com/gitgitgadget/gitgitgadget-workflows HEAD &&
if test 0 = $(git rev-list --count HEAD..FETCH_HEAD)
then
exit 0 # let the next step create a commit
fi &&
git merge --no-edit FETCH_HEAD &&
echo "result=merged" >>$GITHUB_OUTPUT
- name: Create a commit
id: commit
if: steps.merge.outputs.result != 'merged'
run: |
if test workflow_dispatch != '${{ github.event_name }}' &&
test 0 -lt $(git rev-list --count --since=3.weeks.ago HEAD)
then
echo "::notice::No need to keep alive, there were commits in the last three weeks"
echo "result=skip-push" >>$GITHUB_OUTPUT
exit 0
fi &&
mkdir -p .github/cached
file='.github/cached/keepalive.txt'
date >$file
git add "$file"
git commit -m "workflow keepalive"
- name: Push changes
if: steps.commit.outputs.result != 'skip-push'
run: |
git push origin HEAD </dev/null || {
for i in 1 2 3 4 5
do
# In case of concurrent pushes, let's pull and push
git pull origin $GITHUB_REF </dev/null || exit 1
git push origin HEAD </dev/null && exit 0
done
exit 1
}