We are using github to backup configuration files automatically from our servers.
To check that the cron job is working correctly is there a way to have an action failing if there is a no commit for the last 24 hours ?
We are using github to backup configuration files automatically from our servers.
To check that the cron job is working correctly is there a way to have an action failing if there is a no commit for the last 24 hours ?
You can use action with below structure
git log -1 --format=%cd
//Outputs: time of last commitgit log -1 --format=%cr
//Output: X days ago
Eventually that the action to check we are using
name: CheckBackup
on:
workflow_dispatch:
schedule:
- cron: '0 1 * * *' # every day at 1:00am
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Check dates difference
run: |
echo "Github last update : " + `git log -1 --format=%cd$`
echo "Now : " + `date`
let now=`date +%s`
let backupTime=`git log -1 --format=%cd$ --date=raw | grep -o "^\w*\b"`
deltaHours=$((now-backupTime))
deltaHours=$((deltaHours/3600))
if [ $deltaHours -ge 8 ]; then
echo 'failed : ' + $deltaHours + ' hours'
exit 1
else
echo 'ok : ' + $deltaHours
exit 0
fi