Sub topic 7
What to defer to nightly builds
This chapter assumes you know Git and pull request workflow, have used a CI system such as GitHub Actions, and know what linting, unit tests, and integration tests are. It covers the third stage of the placement model: checks that run on a schedule instead of on every change.
Why a nightly stage exists
Pull request and merge checks must finish quickly, because developers wait on them. Some checks cannot meet that budget. A full end-to-end suite may take two hours. A load test needs a dedicated environment. A dependency audit changes its result when new advisories appear, even if your code did not change.
A nightly build runs these checks on a schedule against the default branch. Nobody waits on it, so it can spend time and money that a pull request cannot. The cost is delayed feedback. A bug found at 02:00 may have been merged many hours earlier, along with other changes.
What belongs in the nightly stage
A check is a good candidate for deferral when one or more of these hold:
- It runs longer than your pull request budget, even after caching and parallelism.
- It needs scarce or expensive resources, such as a large database, real devices, or a staging environment.
- Its result depends on time or external data, not only on the diff.
- It covers a broad matrix, such as many OS and runtime versions.
- Its failures are rare and mostly caught earlier by cheaper checks.
| Check | Why defer it | Typical failure signal |
|---|---|---|
| Full end-to-end suite | Long runtime, many moving parts | A user flow breaks across services |
| Load and performance tests | Needs a quiet, dedicated environment | A latency or throughput regression |
| Dependency and vulnerability scans | Results change with new advisories | A new advisory affects a pinned package |
| Full browser or OS matrix | Multiplies runtime | A failure on one platform only |
| Long-running fuzz or soak tests | Value grows with time spent | A crash after sustained input or uptime |
Configuring a nightly workflow
Scheduled workflows use a cron expression, which is evaluated in UTC. In GitHub Actions they run only on the default branch. Add workflow_dispatch so someone can rerun the suite by hand after a fix, without waiting a day.
name: nightly
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run test:e2eThe timeout-minutes setting matters here. Without it, a hung job holds a runner until the platform's default limit, which is much longer than you want.
Common errors
- Deferring without an owner. A nightly failure that nobody is assigned to gets ignored within a week. Name a team or rotation before you move a check here. Chapter 12 covers triage in more detail.
- Using nightly as a dumping ground. Moving a flaky or slow test out of pull requests hides the problem instead of fixing it. Only move checks that are valuable and expensive, not ones that are simply broken.
- Treating nightly results as blocking. A scheduled run is not a status check on any pull request, so it cannot stop a merge. If a failure must stop releases, wire it to a release gate or an alert.
- Assuming the run covers your branch. Scheduled workflows test the default branch, not open pull requests.
- Forgetting the schedule is best effort. Runs can start late during busy periods on shared runners. Do not depend on exact timing.
How a deferred check flows
Exercise
Your 90-minute end-to-end suite blocks pull requests, and it is stable and catches real bugs. You move it to a nightly workflow. Name two things you should set up so the move does not erode trust in the pipeline.
Show answer
Assign an owner (a team or rotation) who triages nightly failures, and add a manual trigger (workflow_dispatch) plus a timeout-minutes limit. Alerting on failure and listing the commits since the last green run are also valid answers.
Exercise
A teammate says a failing nightly run will stop a bad pull request from merging. Is that correct? Explain.
Show answer
No. A scheduled run executes on the default branch and is not a status check on any pull request, so it cannot block a merge. Only required checks that run on the pull request or merge queue can do that.