GitHub, CI/CD, and Tests
Set up automatic checks that really stop a bad release, keep the exact version that was checked, and limit what untrusted changes can reach.
Content date: October 21, 2026.
Plain English
Continuous integration (CI) runs a set of checks on every change in a controlled place, such as GitHub Actions. Continuous delivery or deployment (CD) moves a checked version toward your users under a release policy. Having a workflow file does not prove the checks ran, passed for the current version, or are required before merging or deploying. A useful gate catches a real failure, stops the release, and keeps enough output to find the cause.
Use this when
Start as soon as more than one change needs a repeatable review. Do it before you automate anything that reaches production, and again whenever you add outside contributors, secrets, or deployment power to a workflow.
If you are just starting
Run the same documented commands on your computer and in CI: a locked dependency install, the type, lint, and test checks that matter, and the production build. In npm projects, npm ci installs exactly what the lockfile lists and fails if package.json and the lockfile disagree, instead of quietly changing the lockfile. Use made-up test data and a separate test setup. The local release practice is free and shows a check that blocks a release. A run on a hosted CI service is separate evidence that you gather yourself.
When your project grows
Require the intended checks on the exact version you will release, and look at the repository's real protection settings. Set GITHUB_TOKEN permissions to the least needed (read-only by default, raised per job). Review third-party actions and pin each to a full commit SHA, a 40-character ID that cannot be silently changed. Keep production secrets away from pull requests from forks or other untrusted sources, avoid the pull_request_target trigger unless you need it, and never check out untrusted code in it. Put deployment in a separate, trusted workflow, with short-lived sign-in (OIDC) instead of stored cloud keys. Make sure a required failure blocks the release. Use concurrency settings so an old run cannot overwrite a newer release or interrupt a migration. As of October 2026, private repositories on GitHub Free cannot use deployment environments and their protection rules, so check your plan.
Worked example
A tutoring site's contact form still validates input after someone changes its success message to claim "Your message was sent," though nothing sends. The local release practice has a narrow text check that rejects that version and keeps the previous good file in place. It also rejects a file whose bytes changed after checking. Opening the broken version in a browser shows the false claim directly. Neither result proves that a GitHub repository requires checks or keeps secrets away from outside code.
Practice
Prove a relevant gate blocks promotion
- Run the local release practice and find the two expected rejections, the broken version and the changed file.
- Open the broken version in a browser, then write down what a simple text check cannot prove about a form.
- Draft a workflow for your project with the runtime version, a locked install, the checks that matter, a saved build artifact, and a failure that stops the job.
- Review the workflow's triggers, token permissions, action versions, how it treats untrusted pull requests, which secrets it uses, and how overlapping deploys are handled.
- If you have a GitHub repository, record a real run and the required-check settings. If not, mark both as pending and keep the local evidence separate.
Deliverable: A short release-gate plan, your local rejection results, and a permissions and versions record that marks any steps you could not run on GitHub.
Common mistakes to watch for
- A test step is set to continue after failure, so a broken booking form ships with a green badge.
- Only the previous commit was checked, and the final one was never tested.
- A pull request from a stranger runs with the production deploy key and leaks it.
- Deployment rebuilds from scratch and ships different files than the ones that passed.
- Two deploys overlap, and an older one lands after a newer one.
Prompting
A weak prompt
Add a green CI badge and deploy every push even if the optional tests fail.
A better prompt
Create a GitHub Actions workflow for this project's real commands: [install, test, build]. Pin the Node version, use npm ci, pin each action to a full commit SHA, give the workflow read-only token permissions, and run deployment in a separate job only on [main]. Show that a failing test stops the deploy. Record the exact commit and build, and tell me which GitHub settings I must check myself, such as required status checks.
A check that cannot stop a release only gives you false confidence, and the green badge makes a broken site look safe.
Check before you move on
- The workflow runs the same commands the project uses locally.
- A real test failure blocks the release.
- The checked commit and build are recorded.
- Untrusted code cannot reach production secrets.
- Required status checks are turned on in the repository settings, or noted as not yet done.
- The workflow has a deliberate rule for overlapping runs.
You are done when
- A deliberately broken version cannot replace the accepted file in the local practice release.
- Your report keeps local success and a workflow file separate from proof that GitHub enforces the checks.
Questions to think about
You add a workflow file to your repository. Does GitHub now refuse to merge a pull request that fails its tests?
Not by itself. You still have to confirm the workflow runs and then mark its checks as required in the repository's branch protection or rules.
A volunteer wants their pull request's tests to use your real payment keys so the tests feel realistic. What should happen?
Refuse, and use fake test credentials instead. The pull request's code runs during the tests and could print or send any secret it can see.
A test fails, but the deploy step still runs. Is that workflow a quality gate?
No. The failure has to stop the deploy step, for example because the deploy depends on the tests passing. Otherwise it only reports the problem.