GitHub actions keepalive #770
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: GitHub actions keepalive | |
on: | |
schedule: | |
# Once a day | |
- cron: "0 0 * * *" | |
push: | |
paths: | |
- .github/workflows/keepalive.yaml | |
jobs: | |
keepalive: | |
name: Keepalive | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Prepare git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "github-actions[bot]" | |
- name: Update if necessary | |
run: | | |
LAST_COMMIT=$(git log -1 --pretty=format:"%cd" --date=format:"%Y-%m-%d") | |
OK_AFTER=$(date --date="14 day ago" +%Y-%m-%d) | |
if [[ "${LAST_COMMIT}" < "${OK_AFTER}" ]]; then | |
echo "Last commit ${LAST_COMMIT} is too long ago, trying to update repo." | |
while [[ true ]]; do | |
# Reset repo state | |
git checkout --orphan "${BRANCH}" | |
date +%Y-%m-%dT%H:%M:%S > .github/keepalive.txt | |
git reset | |
git add .github/keepalive.txt | |
git commit --message "${MESSAGE}" | |
git push -f --set-upstream origin "${BRANCH}" | |
if [[ "$?" == "0" ]]; then | |
echo "Keepalive commit successful." | |
break | |
else | |
sleep 1 | |
fi | |
done | |
fi | |
env: | |
BRANCH: keepalive | |
MESSAGE: Keeping GitHub actions alive |