In my repository, every merge to main started the full CI run again: typecheck, the whole test suite, a supply-chain check. The same commit had already passed that run on its pull request. And a deploy workflow started at the same moment, which runs its own tests before it deploys. The deploys were usually finished while the CI run on main was still going.
So what was that run on main for? This post is how I answered that, what I changed, and what I gave up.
Why I have CI at all, and what it does
The repository is one Worker that renders many sites from their configs, plus a few smaller Workers (a landing page, an admin page, a client editor) that share code with it. A change to shared code, such as a template, the config schema or a library, can break many sites at once, and I cannot open every site by hand before each merge. So a set of automatic checks runs on every pull request, before I merge:
- Supply-chain check. The registry signatures and provenance of the dependencies must verify (this blocks). Known advisories are listed but do not block; I triage them separately.
- Typecheck. Eleven TypeScript projects: the Worker, the scripts, the smaller Workers and the shared code.
- The full test suite. It also renders every site in every language and validates every site config.
- A browser check. The pull request's own Worker code runs on a local server, and Chromium opens every site on a desktop and a phone screen. It fails on a script error or a broken menu, gallery or order builder.
- An order-flow check. The order flow runs end to end in a real local workerd, with the guest page and the kitchen page in Chromium and a notification all the way to Google's push service.
- An editor check. The client editor is driven in Chromium the way a client would use it: add a highlight, move sections, change a text and a price, and run the same save check the editor uses before publishing.
None of these deploy anything or use secrets; they only check. The Chromium ones are the heaviest, so each has its own workflow that starts only when a file it uses changes.
CI can only check what it can run: the pull request's own code, with no real data and no real phone. How a page looks on a phone, I still check myself on a preview of the branch.
What the run on main actually did
I looked at what was already running on a merge:
| Workflow | Tests before it deploys |
|---|---|
| The main Worker's deploy | typecheck, the full test suite, config validation |
| Three smaller Workers' deploys | only the tests of their own folder |
CI on main |
typecheck, the full test suite, the supply-chain check |
The same tests, up to three times
For a change to the main Worker, the same tests ran up to three times for one commit:
- On the pull request, before the merge.
- In the deploy workflow, right after the merge, before it deploys.
- In the CI run on
main, started by the same push.
The first run is the useful one: it finds problems early, on the branch. The second is the gate, since it sits before the deploy. The third repeated the second, on another runner.
The CI run on main finished after the deploy
Both the deploy and the CI run start on the same push, and they run in parallel. The deploy, with its tests, was usually finished while the CI run on main was still going. So by the time that run could tell me anything, the code was already live. It gated nothing: it could only report, after the fact, that something was wrong.
What the run on main could catch that the pull request run could not:
- Two pull requests that each pass alone but break together once both are merged.
- A branch that was tested before
mainmoved on.
On a private repository on the free plan there is no branch protection, so GitHub cannot force "up to date with main before merge". Both cases are possible. But I am the only contributor: nobody else opens pull requests, so the only way to get case 1 is two of my own pull requests open at the same time, and I merge them one at a time. That makes both cases rare.
The change
Three parts:
CI runs on pull requests, by hand, and on a schedule, but not after each merge. The pull request run is what finds problems early. The manual run is for the case "I merged two pull requests close together".
The smaller deploys got one shared step before they deploy: the typecheck of the whole repository plus the tests of the folder that all the Workers share. It is one script in
package.json, so a new test is added in one place:"test:predeploy": "npm run typecheck && vitest run --dir shared"A type error or a broken shared test now stops a deploy. The old run on
mainnever stopped anything.A scheduled run on
main, every night, as the safety net. More on that below.
Measure before you add a step
I did not want to add minutes to every deploy without knowing how many. On my laptop (two test workers):
| Step | Time |
|---|---|
| Typecheck, 11 TypeScript projects | about 13 s |
| Tests of the shared folder, 15 files, 326 tests | about 20 s |
About 35 seconds. A merge that touches the shared code starts three deploys, so that is about a minute and a half of runner time, on those merges only. That is less than the full CI run I dropped.
The gap that is left, and why I accepted it
The new step covers the typecheck and the shared folder. The smaller Workers also bundle other folders (src/lib, src/templates), and their tests are not run by those three deploys. Only the main deploy runs the full suite, in parallel, and it does not block the others. So a deploy is gated on types and shared tests, not on every test of everything it bundles.
Closing it was a decision. I measured the obvious option: running the src/lib tests in every deploy. They are 82 files with 1,136 tests. The tests themselves add up to about two seconds; the rest of the 82 seconds I measured is importing and transforming the modules. So "only run the quick ones" does not help: there are no slow tests, only a fixed start-up cost per file. That is 1 to 1.5 minutes extra on every deploy, to close a gap that a different change closes for free.
Nightly instead of weekly, and a skip
My first idea for the safety net was a weekly run. A failing test would then show up after days, which is worse than the run I removed. A nightly run shows it the next morning.
A nightly run on a repository where most nights nothing is merged would mostly repeat the last result. So the run starts with one cheap step that asks the GitHub API: did this workflow already pass on main for exactly this commit? If yes, it skips everything else. It is about forty lines of plain Node, run before npm ci, only for the scheduled trigger:
- A run by hand and a pull request always run.
- A red run is never skipped. The next night finds no passed run for that commit and runs again, so a broken
mainkeeps emailing me until I fix it. For this job that is a feature. - Anything unexpected (an API error, no earlier run) means no skip. One run too many costs a few minutes; a missed run costs trust.
The check is a small pure function with a test, and a second test reads the three workflow files and checks that the skip step exists, runs on the schedule only, and that every later step waits for it. It is easy to add a step to a workflow later and forget the condition.
One cost I accept: the editor check is split in three parallel parts, and each part starts its own runner before it can skip. A quiet night is a few short runner starts, not zero.
Where the saving lands: ACA and the laptop
I do not use GitHub-hosted runners for CI. The jobs run on my own laptop and on Azure Container Apps, where each job starts a container that is billed for the time it runs. That changes what "a run" costs: not minutes of a free allowance, but container time on ACA, plus heat and load on the laptop.
Before this change a merge started a full CI run on top of the deploy. Now it starts none, and the nightly run starts almost nothing on a night without a merge, because it skips itself before npm ci and the browser install, which are the slow part of a job. I do not have the new ACA bill yet, so I will not quote a number; the number of jobs started per week is the thing to watch, and it is down by one full run per merge.
What I gave up, and what I gained
Gave up
- A check on
mainright after each merge. A change that only touches scripts or the root config, or two pull requests that only break together, is now found by the next nightly run instead of at once. The second is unlikely to happen at all, because I am the only contributor and I merge one pull request at a time; on a team with several people merging all day it would weigh much more, and I would keep the run after each merge. - The three smaller deploys do not run every test of the folders they bundle.
Gained
- No full CI run on every merge. My CI jobs run on only two kinds of runner: a self-hosted runner on my laptop and ephemeral runners on Azure Container Apps (ACA), and every job that starts on ACA is billed (a job starts a container, even for a few seconds). Fewer jobs means a smaller ACA bill and less load on the laptop, instead of GitHub-hosted minutes.
- A gate before three deploys that had none, because the check now sits before the deploy instead of after it.
- A fresh full run every morning, and the supply-chain check with it. Advisories and signature problems appear without any commit, so a run per merge was never the right rhythm for that check.
Takeaways
- Ask what a check on
maincan catch that the pull request run could not. If the answer is "rarely", move it to a schedule. - A check that runs in parallel with the deploy is a warning, not a gate. If you want it to gate, put it before the deploy.
- Measure what you add to a deploy before you add it. Mine was about 35 seconds.
- Make a skip rule fail open: skip only on a clear yes.
- Have the workflow files tested like code. A test that reads the YAML is cheap and catches the forgotten
if.