Skip to content

Keep scheduled workflows alive #5

Keep scheduled workflows alive

Keep scheduled workflows alive #5

Workflow file for this run

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@v5
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
}