Automatic deploys are convenient: push to main and your app updates a minute later. They are also a fast way to ship a broken build if nothing checks the code first.
This guide is for developers who deploy from GitHub and want a safety net. You will set up a GitHub Actions workflow that lints and tests every pull request, make passing checks a requirement for merging, and connect that to your deploy process so only green code goes live.
The examples use Node.js, with a Python variant. The same pattern works for any language.
CI and CD in plain terms
Continuous integration (CI) means every change is built and tested automatically, usually on each push and pull request. The goal is to catch problems while they are small and the change is fresh in your mind.
Continuous delivery or deployment (CD) means code that passes CI can reach production with little or no manual effort. Delivery usually means it is ready to release at the press of a button; deployment means it goes out automatically.
You do not need a complex pipeline to get most of the benefit. A workflow that installs dependencies, runs the linter and runs the tests on every pull request catches a large share of mistakes before they reach users.
How GitHub Actions works
A workflow is a YAML file in .github/workflows/ in your repository. It defines:
- Triggers (
on:): events such aspushorpull_request. - Jobs: groups of steps that run on a fresh virtual machine called a runner.
- Steps: shell commands (
run:) or reusable actions (uses:).
GitHub-hosted runners are free for public repositories, and private repositories get a monthly allowance of minutes depending on your plan. Check GitHub's current pricing page for the exact figures.
A complete Node.js workflow
Save this as .github/workflows/ci.yml:
name: CI
on:
pull_request:
push:
branches: [main]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm testWhat each part does:
actions/checkout@v4fetches your code onto the runner.actions/setup-node@v4installs Node 20, andcache: npmcaches the npm download cache keyed on yourpackage-lock.json.npm ciinstalls exactly what the lockfile says, and fails ifpackage.jsonand the lockfile disagree. That is what you want in CI.concurrencycancels an older run on the same branch when you push again, which saves minutes.permissions: contents: readlimits the built-inGITHUB_TOKENto reading the repository.
The workflow assumes lint and test scripts exist in package.json. If your project has no linter yet, remove that line rather than leaving a failing step.
A Python variant
For a Python project, swap the setup and commands:
name: CI
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- run: pip install -r requirements.txt
- run: pip install ruff pytest
- run: ruff check .
- run: pytestQuote the Python version. Unquoted, YAML reads 3.10 as the number 3.1, which is a classic trap.
Testing against a real database
If your tests need PostgreSQL, run it as a service container next to the job:
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm testThe password here is a throwaway for a database that exists only for the length of the job. It is not a secret and is fine to commit.
Matrix builds
A matrix runs the same job across several versions at once. This is useful for libraries, or while you are upgrading:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm testFor an app that runs on one known version in production, a matrix is usually unnecessary. Test against the version you deploy with.
Caching beyond the basics
The cache option in the setup actions covers most needs. For other tools, actions/cache@v4 stores any folder keyed on a hash of your files:
- uses: actions/cache@v4
with:
path: .next/cache
key: nextjs-${{ hashFiles('package-lock.json') }}Cache downloads and build caches, not node_modules itself. Restoring node_modules across different runner images can cause subtle breakage.
Pairing CI with automatic deploys
On Launchpad, an app deployed from GitHub redeploys automatically on every push to its deployed branch. That deploy does not wait for your GitHub Actions results, so the safety has to come from controlling what reaches the branch. There are two clean ways to do that.
Option 1: merge only green pull requests. Work on feature branches, open a pull request, let CI run, and protect main so a pull request cannot be merged until its checks pass. The push that triggers a deploy is always a merge of tested code.
Option 2: deploy by hand. Turn off Deploy automatically on every push in the app's Settings, then press Redeploy once CI is green. This suits teams who want a person to decide when releases go out.
Either way, Launchpad adds its own safety: a health check must pass before a new version goes live, a failed deploy leaves the previous version running, and you can roll back to any earlier deployment that went live. See deployments, logs and rollbacks for how that works.
Step by step: protect your main branch
- Commit the workflow file on a branch and open a pull request, so the check runs at least once. GitHub only lists checks that have run recently.
- In your repository, open Settings → Branches and add a branch protection rule for
main(or create a ruleset under Settings → Rules). - Enable Require a pull request before merging.
- Enable Require status checks to pass, then search for and select your job (it appears as
test, ortest (20)for a matrix). - Optionally enable Require branches to be up to date before merging, so the check runs against the latest
main. - Merge your pull request. From now on, a failing check blocks the merge button.
Secrets in GitHub Actions
Store tokens and keys under Settings → Secrets and variables → Actions, then reference them as ${{ secrets.NAME }}. GitHub masks secret values in logs.
Keep CI secrets separate from production secrets. Your test job rarely needs real API keys; use test credentials or mocks. Production values belong in your host's settings, such as Launchpad's encrypted Variables tab, not in GitHub. The environment variables guide explains the split.
Common mistakes
- Using
npm installin CI. Fix: usenpm ciso the lockfile is respected and drift is caught. - Pushing straight to
main. Fix: require pull requests and passing checks with branch protection. - Unquoted Python versions. Fix: write
"3.10", not3.10. - A workflow that never runs on pull requests. Fix: include
pull_requestin theon:triggers, not onlypush. - Testing on a different version than production. Fix: match the Node or Python version your app actually runs on.
Security notes
- Set
permissions:to the minimum each workflow needs. - Secrets are not passed to workflows triggered by pull requests from forks. Do not work around this with
pull_request_targetcombined with checking out the fork's code, which can expose secrets to untrusted code. - Pin third-party actions to a full commit SHA if you want to be certain the code cannot change underneath you. Official
actions/*versions are generally fine on a major tag. - Never echo secrets in
run:steps, even for debugging.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
npm ci fails: lockfile out of sync | package.json changed without updating the lockfile | Run npm install locally and commit package-lock.json |
| Setup step says no dependency file found for caching | No lockfile in the repository | Commit your lockfile, or remove the cache: line |
| Status check missing in branch protection | The job has not run recently | Open a pull request to trigger it, then search again |
| Tests pass locally but fail in CI | Missing environment variable or service | Add the variable under env: or a service container |
| Workflow does not start | File not under .github/workflows/ or invalid YAML | Check the path and indentation |
Frequently asked questions
Do I need CI for a small personal project?
Not strictly, but a basic workflow takes minutes to add and catches typos and broken builds before they go live. It pays for itself the first time it stops a bad deploy.
Can GitHub Actions deploy to Launchpad for me?
You do not need it to. Launchpad watches the deployed branch itself, so a merge to main is the deploy trigger. Let Actions handle testing and branch protection handle the gate.
What should CI check?
Start with install, lint and unit tests. Add a build step if your app has one, since a build that fails in CI would also fail on deploy. Add integration tests as the project grows.
How long should CI take?
Aim for a few minutes. Slow pipelines get ignored. Caching, cancelling superseded runs and splitting slow tests into a separate job all help.
Next steps
A small workflow plus branch protection turns automatic deploys from a risk into a convenience. Start with lint and tests, protect main, and grow the pipeline as your app does.
- Deploy from GitHub with automatic deploys on every push
- Deployments, logs and rollbacks
- Docker for web apps
- Deploy your first app
- Connect your repository and deploy on Launchpad




