GitHub Actions Workflow for Cron Build That Opens an Issue on Failure
Run a scheduled build and file an issue when it breaks.
This workflow runs on a cron and, on failure, uses a follow-up step to create a GitHub issue so the breakage is tracked.
The workflow
.github/workflows/nightly.yml
name: Nightly
on:
schedule:
- cron: '0 4 * * *'
permissions:
contents: read
issues: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./build-and-test.sh
- if: failure()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Nightly build failed: run ${{ github.run_id }}',
body: 'See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
})Notes
- Needs
issues: writeto create the issue. - The issue step runs only
if: failure(). - Scheduled failures are easy to miss -- an auto-issue makes them visible.
Run it cheaper
Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.
Related guides
GitHub Actions Workflow for Scheduled Nightly BuildA GitHub Actions workflow that runs a full build and test suite on a nightly cron schedule, independent of an…
How to Speed Up GitHub Actions: 9 High-Impact TacticsMake GitHub Actions faster: caching, parallelization, test splitting, Docker layer caching, slimmer images, a…