Skip to content
Latchkey

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: write to 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

Run this faster and cheaper on Latchkey managed runners. Start free →