Every push to a repository is an event that can start work automatically: run the tests, check formatting, build the application, publish a release, or deploy to a server. That's continuous integration (CI) and continuous delivery or deployment (CD). Every major platform has its own CI system and its own configuration syntax, so this lesson does two things: it explains the concepts they share, and it shows how to keep your automation portable by putting the real work in scripts and keeping each platform's configuration thin. You'll see the same pipeline for GitHub Actions, GitLab CI/CD, and Forgejo Actions, and where they genuinely differ.
Before you start
You should be comfortable with branches, pull requests, and tags from the Intermediate level, especially Advanced Git Workflows: Rebase, Cherry-Pick, Stash, Tags, and Releases. Examples use a Node.js project, but the structure applies to any language.
The shared concepts
Whatever the platform, a CI/CD system has the same parts:
- Triggers: events that start a pipeline, such as a push, a pull or merge request, a tag, a schedule, or a manual button.
- Jobs and steps: units of work, often grouped into stages that run in order, with jobs inside a stage running in parallel.
- Runners: the machines or containers that execute jobs. Platforms provide hosted runners; you can also run your own.
- Artifacts: files a job produces (a build, a test report) and passes to later jobs or keeps for download.
- Caches: saved files, such as downloaded dependencies, reused between runs to save time.
- Secrets and variables: credentials and settings injected into jobs without being stored in the repository.
- Environments: named deployment targets, such as staging and production, with their own secrets and approval rules.
What CI should check
A useful CI pipeline answers one question for every proposed change: is it safe to merge? Typical steps, fastest first so failures are reported quickly:
- Install dependencies exactly as locked (
npm ci,pnpm install --frozen-lockfile,cargo build --locked). - Check formatting and run linters.
- Type-check, if the language has a separate step.
- Run unit tests, then slower integration tests.
- Build the production artifact.
For how to design those tests and choose quality gates that help rather than backfire, see Automated Testing in CI/CD: Coverage, Static Analysis, and Quality Gates in our testing series.
Combine this with branch protection (lesson 7): the main branch only accepts changes whose checks passed. CI that nobody is required to wait for quietly stops being trusted.
Keep the logic in your repository, not in YAML
Every platform's configuration language differs, and the more logic you put in it, the harder it is to run locally and the harder it is to move. Put the commands in a script or package scripts that anyone can run on their own machine:
{
"scripts": {
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"build": "vite build",
"ci": "npm run lint && npm run typecheck && npm test && npm run build"
}
}Then each platform's configuration only says: on these events, on this kind of machine, check out the code, install the runtime, and run npm run ci. If CI fails, a developer reproduces it locally with the same command.
Fast feedback before CI: Git hooks
Git can run scripts at certain moments through hooks, such as pre-commit (before a commit is recorded) and pre-push. They're a cheap first line of checks on the developer's machine:
#!/bin/sh
# Refuse the commit if formatting or lint fails on staged files
npm run lint --silent || exit 1Hooks in .git/hooks/ aren't shared through the repository, and anyone can skip them with --no-verify, so treat them as a convenience. CI remains the check that counts. Teams often share hooks by committing them to a folder and setting git config core.hooksPath .githooks, or with a hook manager.
One pipeline, three platforms
GitHub Actions
Workflows live in .github/workflows/*.yml:
name: ci
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run ciReusable steps come from actions, published in repositories. Pin third-party actions to full commit SHAs, as here, because tags can be moved (lesson 12 and the supply chain lesson of our security series explain why). The SHAs shown were current in November 2026; look up the latest when you use them.
GitLab CI/CD
GitLab reads one file, .gitlab-ci.yml, at the repository root. Jobs run in Docker images on GitLab runners:
stages: [verify]
verify:
stage: verify
image: node:24
cache:
key:
files: [package-lock.json]
paths: [.npm/]
script:
- npm ci --cache .npm --prefer-offline
- npm run ci
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHThere are no marketplace actions; you choose the container image and write the commands. Reuse comes from include: of shared templates and from GitLab's CI/CD components.
Forgejo Actions
Forgejo (and Codeberg, which runs it) uses a syntax deliberately modeled on GitHub Actions, with workflows in .forgejo/workflows/:
on:
pull_request:
push:
branches: [main]
jobs:
verify:
runs-on: docker # a label your Forgejo runner advertises; ask the instance admin
container:
image: node:24
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run ciIt looks almost identical, and that's the trap. Forgejo's documentation states that Forgejo Actions is designed to be familiar to GitHub Actions users but not designed to be compatible. Known differences include:
- Runners and labels are different. Runners are registered by the instance admin, with their own labels;
ubuntu-latestmay not exist, and the default image is a small Debian image with Node.js, not GitHub's large Ubuntu image with many tools preinstalled. Here, the job declares its owncontainer. - Some keys are ignored, such as
permissionson a job, and somegithubcontext values are missing. - OIDC tokens for cloud deployments are enabled with an
enable-openid-connectkey, notpermissions: id-token: write. - Action sources differ.
uses: actions/checkout@v4is resolved from the instance's configured default actions source, not necessarily from GitHub, and not every Marketplace action works.
Gitea Actions is similar, with workflows in .gitea/workflows/. Bitbucket Pipelines (bitbucket-pipelines.yml) and Azure Pipelines (azure-pipelines.yml) follow the GitLab-like model of images and script steps, each with its own keywords. And platforms such as Codeberg also support standalone CI systems like Woodpecker CI.
Because the real work is in npm run ci, moving between them means rewriting about fifteen lines of configuration, not your build.
Testing several versions: matrix builds
Libraries often need to work on several runtimes or operating systems. Both platforms can expand one job into several:
# GitHub Actions and Forgejo Actions
strategy:
matrix:
node: [22, 24]# GitLab CI/CD
parallel:
matrix:
- NODE_VERSION: ["22", "24"]Each combination runs as its own job and reports its own status, so you see exactly which version fails.
Continuous delivery and deployment
Continuous delivery means every change that passes CI produces a release candidate that *could* be deployed with one action. Continuous deployment goes further and deploys automatically. Either way, a few principles keep it safe:
- Build once, deploy that artifact. The deploy job uses the exact build CI tested, passed as an artifact or a container image digest. Rebuilding on the server reintroduces untested differences.
- Deploy from a controlled trigger: a push to the main branch, a tag such as
v1.4.0, or a manual approval. - Use environments with protection. Production secrets are only available to deploy jobs on protected branches or tags, and production deploys can require a reviewer.
- Make deployments reversible: keep the previous release, and roll back with one command.
A tag-triggered release job on GitHub Actions might start like this:
on:
push:
tags: ["v*"]
jobs:
release:
runs-on: ubuntu-latest
environment: production # its secrets and approval rules apply
permissions:
contents: write # only this job may create the release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: npm ci && npm run build
- run: ./scripts/deploy.sh dist/Speed and reliability
Slow or flaky pipelines get ignored. Keep them fast and trustworthy:
- Cache dependencies keyed on the lockfile.
- Run independent jobs in parallel, and split long test suites across runners.
- Fail fast: put quick checks first.
- Use
concurrency(GitHub, Forgejo) orinterruptible(GitLab) to cancel outdated runs when a branch gets a new push. - Treat a flaky test as a bug to fix, not a reason to click "re-run."
CI is a security boundary
Your pipeline has access to secrets and often to production. Grant the minimum permissions, keep secrets out of logs, don't run untrusted pull request code with secrets available, and prefer short-lived credentials (OIDC) over stored cloud keys. Lesson 12 and the Software Supply Chain Security lesson cover this in depth.
Common mistakes and troubleshooting
- Logic buried in YAML. It can't be run locally and doesn't port. Use scripts.
- Assuming "Actions-compatible" means compatible. Test workflows on each platform; read its documented differences.
- Installing without the lockfile. Use frozen installs so CI tests what developers locked.
- Rebuilding for deployment. Deploy the tested artifact.
- Secrets in pipeline output. Platforms mask registered secrets, but transformed values (base64, substrings) aren't masked. Don't print them.
- "Works locally, fails in CI." Compare runtime versions, environment variables, time zones, and missing tools in the runner image. Reproduce with the same container image locally.
Practical exercise: one project, two platforms
- Add a
ciscript to a small project that lints, tests, and builds. - Write a GitHub Actions workflow and a
.gitlab-ci.yml(or a Forgejo workflow) that both call it. - Push to both platforms (lesson 15 shows pushing to two remotes) and get both green.
- Break a test on a branch, open a pull or merge request, and confirm the check blocks merging.
- Add dependency caching and measure the run time before and after.
- Write down every line you had to change between platforms.
Key takeaways
- CI/CD systems share triggers, jobs, runners, artifacts, caches, secrets, and environments.
- Keep build and test logic in repository scripts; keep platform configuration thin.
- GitHub Actions, GitLab CI/CD, and Forgejo Actions differ in syntax, runners, and features; Forgejo Actions is familiar to, not compatible with, GitHub Actions.
- Build once, deploy the tested artifact, and protect production with environments and approvals.
- Treat the pipeline as a security boundary.
References
- Git documentation: githooks (opens in a new tab)
- GitHub Docs: Understanding GitHub Actions (opens in a new tab)
- GitLab Docs: CI/CD YAML syntax reference (opens in a new tab)
- Forgejo Actions compared with GitHub Actions (opens in a new tab)
- Forgejo Actions user guide (opens in a new tab)
- Bitbucket Pipelines configuration reference (opens in a new tab)
- Martin Fowler: Continuous Integration (opens in a new tab)
What's next
Automation needs access to your code and secrets, so the repository itself must be protected. Git Repository Security: Permissions, Secrets, Commit Signing, and Supply Chain Protection covers how.

