You can augment your GitHub Actions workflows to report success and failure to Cron HealthChecks service:
name: Hourly Housekeeping
on:
schedule:
- cron: '15 * * * *'
jobs:
Main-Job:
runs-on: ubuntu-latest
steps:
- run: echo "Running housekeeping tasks..."
Ping-Success:
runs-on: ubuntu-latest
needs: [Main-Job]
steps:
- run: curl -m 10 --retry 5 ${{ secrets.ping_url }}
Ping-Failure:
runs-on: ubuntu-latest
if: ${{ failure() }}
needs: [Main-Job]
steps:
- run: curl -m 10 --retry 5 ${{ secrets.ping_url }}/fail
Note how the jobs Ping-Success
and Ping-Failure
define Main-Job
as
their dependency. Ping-Success
runs only if Main-Job
completes
successfully, and Ping-Failure
runs when Main-Job
fails.
To avoid exposing the ping URL, it is a good idea to define it
as a secret
and access it via the secrets
context.
workflow_run
TriggerAlternatively, you can put the pinging logic in a separate workflow, and configure it to trigger every time your main workflow finishes. The main workflow:
name: Hourly Housekeeping
on:
schedule:
- cron: '15 * * * *'
jobs:
Main-Job:
runs-on: ubuntu-latest
steps:
- run: echo "Running housekeeping tasks..."
And the monitoring workflow:
name: Ping Cron HealthChecks service
on:
workflow_run:
workflows: ['Hourly Housekeeping']
types: [completed]
jobs:
Ping-Success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: curl -m 10 --retry 5 ${{ secrets.ping_url }}
Ping-Failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: curl -m 10 --retry 5 ${{ secrets.ping_url }}/fail