Monitor GitHub Actions scheduled workflows
A scheduled workflow can fail, run late, get dropped or be switched off by GitHub, and none of that reaches you unless you go and look at the Actions tab. A Tissue Mast heartbeat expects a beat from every run and pages you when one doesn't come or says it failed.
Store the heartbeat URL as a repository secret, add a last step that sends /0 when the job succeeded and /1 when it didn't, and give the heartbeat the same cron line as the workflow.
The workflow
name: nightly
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./nightly.sh
- name: Beat the heartbeat
if: always()
env:
HEARTBEAT_URL: ${{ secrets.HEARTBEAT_URL }}
run: |
curl -fsS -m 10 --retry 3 -X POST \
"$HEARTBEAT_URL/${{ job.status == 'success' && 0 || 1 }}" \
--data-binary "run ${{ github.run_id }} ${{ job.status }}"
if: always()- Runs the last step whether or not
nightly.shfailed, so a failure is reported straight away instead of waiting out the grace window. job.status- GitHub sets it to
success,failureorcancelled. The expression turnssuccessinto/0, which is a beat, and anything else into/1, which marks the heartbeat down and pages. --data-binary- The body is kept with the beat, so the run id is in the heartbeat's history when you go looking for the run that failed.
workflow_dispatch- Lets you run it by hand once from the Actions tab to see the first beat arrive.
Keep the URL in a repository secret named HEARTBEAT_URL. It's a write capability, and a public repository's history stays public, so a URL committed there has to be rotated.
Beat only on success
If you'd rather not report failures and only want to know when good runs stop, drop the if:. A step without it runs only when every step before it succeeded:
- name: Beat the heartbeat
env:
HEARTBEAT_URL: ${{ secrets.HEARTBEAT_URL }}
run: curl -fsS -m 10 --retry 3 -X POST "$HEARTBEAT_URL"
A failed run then sends nothing, and the heartbeat goes down when the grace runs out.
Matching the heartbeat to the schedule
GitHub reads the cron line in UTC unless the schedule entry has a timezone: with an IANA zone name. Give the heartbeat the same cron line and the same zone, or leave its zone empty for UTC:
curl -X PATCH https://api.tissue.systems/v1/mast/alert-sources/nightly \
-H "Authorization: Bearer $TISSUE_TOKEN" -H "Content-Type: application/json" \
-d '{"schedule": "17 3 * * *", "schedule_tz": "", "grace_secs": 3600}'
Be generous with the grace. GitHub says the schedule event can be delayed during periods of high load, that some queued jobs may be dropped, and that the start of every hour is the busiest time. A minute like 17 stays clear of the top of the hour, and an hour of grace leaves room for a delay plus the job's own run time.
A few more limits from GitHub's documentation: scheduled workflows run only from the default branch, the shortest interval is once every 5 minutes, and shortcuts like @daily aren't accepted.
When GitHub switches the schedule off
In a public repository, GitHub disables scheduled workflows automatically when no repository activity has happened in 60 days. The runs stop, so the beats stop, and the heartbeat goes down. From Mast's side that looks the same as a job that died, and it's often the first anyone hears of it.
If the page comes a couple of months after the last change to the repository, check the workflow's page on GitHub first. You can turn it back on there, or with the REST API, which takes the workflow's file name:
gh api --method PUT repos/OWNER/REPO/actions/workflows/nightly.yml/enable
The next run's beat closes the page.
Free is ten heartbeats with an email address and no credit card. Team is $29 a month for 250 heartbeats, with rotations and escalation for everyone on call.