Ping CronMissed from GitHub Actions

On this page

The last step of a scheduled workflow reports its result. With if: always() it runs even after a failed step, and the job status picks between the plain URL and /fail. The ping URL lives in a repository secret.

What should a workflow job send?

  • A request to /start before the work, so CronMissed can time the run and notice a job that never finishes.
  • A request to the plain URL when the work succeeded, or to /fail when it did not. /<exit status> works too: 0 is a success and any other number is a failure.
  • The end of the output in the request body, up to 100,000 bytes, so the alert shows the error without a trip to the server.

What is the workflow?

.github/workflows/nightly-build.yml
on:
  schedule:
    - cron: '17 4 * * *'
jobs:
  nightly-build:
    runs-on: ubuntu-latest
    steps:
      # ... the job's own steps ...
      - name: Report to CronMissed
        if: always()
        env:
          PING_URL: ${{ secrets.CRONMISSED_PING_URL }}
          JOB_STATUS: ${{ job.status }}
        run: |
          if [ "$JOB_STATUS" = "success" ]; then suffix=""; else suffix="/fail"; fi
          curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null "$PING_URL$suffix"
  • Store https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10 as the repository secret CRONMISSED_PING_URL; the URL is the check's only credential.
  • GitHub runs schedules at most every 5 minutes, in UTC unless a time zone is set.

Keep the ping URL in an environment variable or a secret store, never in a public repository: the URL is the check's only credential.

How do I send a start ping and the log tail?

workflow.yml
      - name: Tell CronMissed the job started
        run: curl -fsS --max-time 10 --retry 5 -o /dev/null "${{ secrets.CRONMISSED_PING_URL }}/start"
      # ... the job's steps, writing their output to build.log ...
      - name: Report with the end of the log
        if: always()
        env:
          PING_URL: ${{ secrets.CRONMISSED_PING_URL }}
          JOB_STATUS: ${{ job.status }}
        run: |
          if [ "$JOB_STATUS" = "success" ]; then suffix=""; else suffix="/fail"; fi
          tail -c 100000 build.log | curl -fsS --max-time 10 --retry 5 -o /dev/null --data-binary @- "$PING_URL$suffix"

Put the start step first in the job. The GitHub Actions guide lists what GitHub documents about delays and disabled schedules.

Sources

Questions and answers

Why a secret and not a plain value?
Workflow files are often public. Anyone who sees the ping URL can send pings for that check, so keep it in a secret.
Does the step run when the workflow is cancelled?
if: always() runs after cancellation too, with a job status of cancelled, so the step sends /fail. Use if: success() || failure() to skip cancelled runs.
Create the check these snippets report to

Make a check, copy its ping URL into the snippet, and run the job once.

Start monitoring