GitHub Actions does CI/CD inside your repository: you commit a YAML workflow file under .github/workflows/, and GitHub runs it on a fresh virtual machine whenever something happens in the repo, such as a pull request being opened or a commit landing on main. A typical pipeline tests every pull request, builds once after a merge, and deploys that build to staging and then production through environments that hold the credentials and the release rules. Public repositories use the standard runners for free; private ones get a monthly allowance of minutes and pay per minute after it.
Below is a complete workflow that does all of this for a Node.js project, followed by the settings that cause trouble a few months in: what the token may do, pull requests from forks, third-party actions, caching and the bill. Versions and prices are as of October 2026, and this month the date matters, because the ubuntu-latest label moves to Ubuntu 26.04 between 19 October and 19 November.
How a workflow is put together
A workflow starts on one or more events: push, pull_request, schedule, workflow_dispatch (a "Run workflow" button in the Actions tab) and a few dozen others. It contains jobs, and each job runs on a runner. A runner is either a virtual machine GitHub starts for that job and discards afterwards, or a machine you operate yourself (a self-hosted runner). A job is a list of steps. A step runs shell commands (run:) or calls an action (uses:), which is a packaged piece of code published in a GitHub repository. Almost every job starts with actions/checkout, which clones your code onto the runner.
The detail that trips people up early: jobs run in parallel on separate machines and share nothing. A dist/ folder built in one job does not exist in the next unless you upload it as an artifact, and needs: is how you make one job wait for another.
A complete CI/CD workflow
This file tests every pull request. On each push to main it tests again, then deploys the same build to staging and then to production. It assumes lint, test and build scripts in package.json, the Node version in a .nvmrc file, and a static build in dist/ served from an S3 bucket. AWS_ROLE_ARN, AWS_REGION and BUCKET are variables defined on each environment, so the same steps deploy to different accounts or buckets. Only the last two steps of each deploy job depend on where you host; replace them with your platform's login and deploy commands. Save it as .github/workflows/ci-cd.yml:
name: CI/CD
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
permissions:
# Read-only token by default; a job asks for more only if it needs it.
contents: read
concurrency:
# New commits on a pull request cancel that PR's previous run. Other events fall
# back to run_id, a unique group, so runs on main never cancel each other.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
- name: Keep the build for the deploy jobs
if: github.event_name == 'push'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: site
path: dist/
retention-days: 14
deploy-staging:
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-24.04
timeout-minutes: 10
environment: staging
concurrency:
group: deploy-staging
cancel-in-progress: false
permissions:
id-token: write # lets the job request an OIDC token for AWS
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: site
path: dist
- uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Upload to S3
env:
BUCKET: ${{ vars.BUCKET }}
run: aws s3 sync dist/ "s3://$BUCKET" --delete
deploy-production:
needs: deploy-staging
runs-on: ubuntu-24.04
timeout-minutes: 10
environment: production
concurrency:
group: deploy-production
cancel-in-progress: false
permissions:
id-token: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: site
path: dist
- uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Upload to S3
env:
BUCKET: ${{ vars.BUCKET }}
run: aws s3 sync dist/ "s3://$BUCKET" --deleteWhy it is written this way
The permissions block at the top makes every job's GITHUB_TOKEN read-only, and only the deploy jobs add id-token: write. Once you list any permission, every permission you didn't list becomes none, so the deploy jobs here can't even read the repository. They don't need to: they download the build and upload it.
Every action is pinned to a full commit SHA, with the version in a comment so that people and Dependabot can still read it. The section on third-party actions explains why.
runs-on: ubuntu-24.04 instead of ubuntu-latest is deliberate, and this month it is timely. GitHub is moving ubuntu-latest to Ubuntu 26.04 in a rollout that starts on 19 October 2026 and should be complete by 19 November. With the version pinned, you upgrade when you choose: add a job on ubuntu-26.04, fix whatever breaks, then switch.
The build happens once, and both deploy jobs ship the artifact it produced. Rebuilding for each environment costs minutes and leaves room for production to get something slightly different from what you checked on staging.
timeout-minutes matters more than it looks. The default is 360 minutes, so a test that hangs in a private repository keeps billing for six hours. Fifteen minutes is generous for most test suites.
There are two concurrency settings. The workflow-level one cancels a pull request's previous run when new commits arrive, which saves a lot of minutes on busy branches. The deploy jobs have their own groups with cancel-in-progress: false, because a deploy cancelled halfway can leave a bucket with half the new files. If two merges land close together, the second deploy waits for the first. If a third arrives meanwhile, it replaces the one that was waiting, so you always end up shipping the latest build. If every merge has to deploy in order (say each one carries a database migration), set queue: max on the group instead, which lets up to 100 runs wait.
One thing the example leaves out: if CloudFront serves the bucket, follow the sync with aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION_ID" --paths "/*", or visitors keep getting the old index.html until the CDN cache expires.
Pull requests from forks, and what the token may do
When a pull request comes from a fork, GitHub passes no secrets to the workflow and gives it a read-only GITHUB_TOKEN. In public repositories a maintainer may also have to approve workflow runs for first-time contributors. That is why the example can run on pull_request safely: the test job needs no secret, and the deploy jobs never run for pull requests.
pull_request_target is the trigger to be careful with. It runs in the context of your repository, with your secrets and a token that can write, so it is safe only if it never executes code from the pull request. Avoid it unless you really need it. Two recent changes reduce the risk. Since 8 December 2025 it always takes the workflow file from the default branch. And actions/checkout v7 refuses to check out a fork's pull request code in a workflow started by pull_request_target or workflow_run, unless you set allow-unsafe-pr-checkout: true. If you catch yourself typing that input, stop and redesign the workflow.
Check the default token permission as well. Organizations and personal repositories created since 2 February 2023 get a read-only GITHUB_TOKEN by default, and an organization's repositories inherit its setting. Older accounts kept read and write unless someone changed it under Settings → Actions → General. With a permissions: block in the file, the workflow behaves the same whatever that setting says.
Deploying: environments, approvals and OIDC
An environment (Settings → Environments) is a named deploy target with its own secrets and variables, rules about which branches or tags may deploy to it, and optional protection rules. The protection rules you are most likely to want are required reviewers (up to six people or teams, where one approval is enough, and you can stop people approving their own runs) and a wait timer.
Your GitHub plan matters here more than anywhere else in Actions. GitHub's environment reference gives the split. On GitHub Free, environments work only in public repositories. Pro and Team add environment secrets, environment variables and deployment branch rules for private repositories. Required reviewers and wait timers in a private repository need GitHub Enterprise. It is easy to miss until you try to add an approval step to production and the option isn't there.
So on Team with a private repository, the workflow above deploys to production straight after staging, which is continuous deployment. If you want a person to decide when production changes, move the production job into its own workflow that runs on a version tag:
on:
push:
tags: ['v*']Then allow only tags matching v* in the production environment's deployment rules. A release becomes git tag v1.4.0 && git push origin v1.4.0, and only people who can push tags can do it. A tag ruleset narrows down who that is.
One catch when you split the workflow: an artifact belongs to the run that uploaded it, so the tag workflow can't simply download site from the run on main. download-artifact can fetch from another run if you give it a run-id and a token with actions: read, but you then have to look up which run built that commit. Most teams check out the tag and build again. The tag pins the commit, so the code is the code that passed on staging, even though the build itself is new.
OIDC instead of stored cloud keys
The deploy jobs above contain no AWS keys. The job asks GitHub for a short-lived OpenID Connect token, and AWS exchanges it for temporary credentials of an IAM role whose trust policy names your repository and environment. GitHub's AWS guide walks through creating the identity provider. The part worth getting right is the condition in the role's trust policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:environment:production"
}
}
}
]
}Because the job references an environment, the token's subject is repo:ORG/REPO:environment:NAME. Only a job running in that repository's production environment can assume the production role. A workflow on a feature branch or in a pull request can't, even if someone edits the file. Azure (azure/login) and Google Cloud (google-github-actions/auth) support the same pattern, and so does Terraform when it runs in a workflow; our Terraform post covers the Terraform side.
Check which subject format your repository uses before you copy that policy. According to GitHub's OIDC reference, repositories created after 15 July 2026 get an immutable format that adds the owner and repository IDs, so the subject starts repo:your-org@ORG_ID/your-repo@REPO_ID. Older repositories keep the format above unless someone opts in, and renaming or transferring a repository moves it to the new one. A trust policy written for the wrong format fails the deploy with "Not authorized to perform sts:AssumeRoleWithWebIdentity", so a repository rename can break deploys that worked the day before.
If you deploy to your own server over SSH, there is no OIDC equivalent. Keep the private key in the production environment's secrets, give it a dedicated user that can do the deploy and nothing else, and replace the key when someone who had access leaves.
Rolling back
Actions has no rollback button. The cheapest rollback is already in the example: open the last good run and re-run its deploy-production job. A re-run uses the original run's commit and its artifacts, so it ships the old build again. You can do that for up to 30 days after the original run, and only while its artifact still exists, which is why the example keeps artifacts for 14 days. With containers the idea is the same: deploy the previous image tag instead of building again.
Third-party actions run with your secrets
An action is someone else's code running on your runner with your secrets in reach. In March 2025 attackers compromised the widely used tj-actions/changed-files action and pointed many of its version tags at a malicious commit that wrote the secrets of the workflows using it into the job logs. CISA's alert told affected teams to treat those secrets as compromised and rotate them. Workflows that referenced the action by a version tag picked up the malicious code on their next run. Workflows pinned to an earlier commit SHA kept running the code they had before.
So pin actions to full commit SHAs. A tag can be moved to another commit; a SHA always means the same code. Dependabot keeps pinned actions current if you add the github-actions ecosystem to .github/dependabot.yml:
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weeklyTwo newer controls are worth knowing. Since August 2025, enterprise, organization and repository admins can require SHA pinning in the allowed-actions policy, so a run that uses an unpinned action fails. And on 14 October 2026 GitHub put workflow lockfiles into public preview. The gh actions-lock CLI extension writes .github/workflows/actions.lock, which records the exact commit of every action you use, of the actions those actions call, and of your reusable workflows. That covers what SHA pinning misses: an action you pinned can still call another action by a tag. It is still a preview, so try it on one workflow before rolling it out everywhere.
Script injection is the other common hole. Anything a contributor controls, such as a pull request title, a branch name or an issue body, becomes part of the script if you put it inside ${{ }} on a run: line:
steps:
# Unsafe: the title is pasted into the script before bash runs it,
# so a crafted title can run any command on the runner.
- run: echo "Checking ${{ github.event.pull_request.title }}"
# Safe: the title reaches bash as data in an environment variable.
- env:
TITLE: ${{ github.event.pull_request.title }}
run: echo "Checking $TITLE"Two more rules. Self-hosted runners should almost never serve public repositories, because anyone can open a pull request that runs code on your machine. And keep real customer data out of CI altogether: with synthetic fixtures, a leaked log or artifact exposes nothing. Scanning code and dependencies belongs in the same pipeline; our DevSecOps post covers that side.
Making it faster
In many pipelines the slowest part is installing dependencies, so get the cache right first. cache: npm in setup-node caches npm's download cache, keyed on a hash of package-lock.json. It does not cache node_modules; npm ci still runs, it just stops downloading. Each repository includes 10 GB of cache (you can raise the limit and pay for the extra), entries unused for seven days are deleted, and when you go over the limit the least recently used entries go first. Scope is the part people miss: a branch can restore caches it created and caches from the default branch, and a pull request can also use its base branch's, but nothing from other branches. If the workflow never runs on main, every new branch starts cold.
Docker builds have their own cache. docker/build-push-action with cache-from: type=gha stores image layers in the same Actions cache, and it needs docker/setup-buildx-action earlier in the job. Our Docker and Kubernetes post covers the image side.
Path filters save minutes in a monorepo, with a trap. If you put paths: on the workflow trigger and a pull request doesn't touch those paths, the workflow never starts, its required checks stay "Pending", and the pull request can't be merged. Filter inside the workflow instead: a small first job works out what changed, and later jobs run only when needed. A job skipped by its if: reports success, so a required check on it still passes.
on: pull_request
permissions:
contents: read
jobs:
changes:
runs-on: ubuntu-slim
permissions:
pull-requests: read # the filter lists the PR's files through the API
outputs:
api: ${{ steps.filter.outputs.api }}
steps:
- id: filter
uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
with:
filters: |
api:
- 'api/**'
api-tests:
needs: changes
if: needs.changes.outputs.api == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm test -w apiIf you use a merge queue, add merge_group: to the workflow's triggers. Without it, required checks never report for queued pull requests and nothing merges.
A test matrix earns its minutes when you ship to several runtimes, for example a library that people install on different Node versions. For an application, test the version you deploy. If you keep a matrix, update it: Node 20 reached end of life on 30 April 2026, Node 22 is in maintenance until 30 April 2027, Node 24 moves to maintenance on 20 October 2026, and Node 26 becomes the active LTS on 28 October 2026.
For small jobs like the change detector above, ubuntu-slim runs in a container with one vCPU and costs a third of the standard Linux runner per minute. Jobs on it are stopped after 15 minutes.
Is GitHub Actions free? What it costs
In public repositories, standard GitHub-hosted runners are free. In private repositories, each plan includes a number of minutes on standard runners every month, and usage beyond that is billed per minute. The figures from GitHub's billing documentation:
Plan | Included minutes per month | Artifact storage |
|---|---|---|
Free | 2,000 | 500 MB |
Pro | 3,000 | 1 GB |
Team | 3,000 | 2 GB |
Enterprise Cloud | 50,000 | 50 GB |
Past the allowance, a 2-core Linux runner costs $0.006 a minute, its arm64 version $0.005, Windows $0.010 and macOS $0.062. These rates have applied since 1 January 2026, when GitHub cut hosted-runner prices by up to 39%. Each job is rounded up to the next whole minute, so a 20-second deploy job bills as one minute. Larger runners are always billed, even in public repositories. Without a payment method on file, usage stops when the allowance runs out.
A rough example for a private repository on Team. One hundred pull request runs a week with a 6-minute test job come to about 2,600 minutes a month. Eighty merges a month, each running the test job and two short deploy jobs, add about 640 more. That is a little over the 3,000 included minutes, and the overage costs less than two dollars. Now add a 15-minute iOS build to every pull request run: that is about 6,500 macOS minutes a month, roughly $400 at $0.062, against about $40 for the same minutes on Linux. At these rates macOS minutes are what turn a CI bill from a rounding error into a line item, so build iOS only on the runs where it tells you something new. Our mobile app testing post covers CI for mobile apps in more depth.
Self-hosted runners cost nothing in Actions minutes. GitHub announced a platform charge of $0.002 a minute for them from 1 March 2026, then postponed it to re-evaluate, and its billing page still lists self-hosted usage as free. A machine of your own is rarely cheaper once you count the server and the hours to keep it patched.
Where to start in an existing repository
If you are adding this to a project that already exists, this order gives the most protection for the least work:
- Add the
testjob onpull_requestand make it a required status check onmain. - Put
permissions: contents: readat the top of every workflow. - Pin actions to commit SHAs and add the Dependabot config.
- Move deploy credentials into environments, then replace stored cloud keys with OIDC.
- Add
timeout-minutesand the concurrency groups. - Pin the Ubuntu version before the
ubuntu-latestmove finishes on 19 November.
If you'd like another pair of eyes on a pipeline that has become slow or expensive, you can reach us through the contact form.
Frequently asked questions
Should we use GitHub Actions, GitLab CI or Jenkins?
Use the CI that lives where your code lives. If the repository is on GitHub, Actions gives you checks on pull requests, environments and OIDC without another service to run. GitLab CI is the equivalent for code on GitLab. Jenkins makes sense when builds must run inside your own network and someone on the team is willing to maintain the server and its plugins.
Can I run a workflow on my machine before pushing?
act (from the nektos/act project) runs workflows locally in Docker containers. It is good for quick feedback on syntax and shell steps, but its containers are not identical to GitHub's runner images, and anything that depends on GitHub's side, such as OIDC tokens or environment protection rules, doesn't carry over. For those, push to a branch and start the workflow with workflow_dispatch.
How do I debug a failing workflow?
Re-run the failed job with debug logging: the re-run dialog has an "Enable debug logging" option, and gh run rerun RUN_ID --failed --debug does the same from a terminal. To get debug output on every run, set ACTIONS_STEP_DEBUG (step logs) or ACTIONS_RUNNER_DEBUG (runner diagnostics) to true as a repository secret or variable.
When are self-hosted runners worth it?
When jobs need something GitHub's machines don't have: a private network or database, a GPU, special hardware, or builds so long that minutes add up. Use them only with private repositories, prefer ephemeral runners that take one job and are then removed (just-in-time runners, or Actions Runner Controller on Kubernetes), and plan time for patching them.
Related Articles
AWS Cloud Architecture: A Practical Blueprint and What It Costs
The AWS setup we would suggest for most web apps and SaaS products, layer by layer: accounts, network, compute, data and operations, with October 2026 prices for Frankfurt.
Read More: AWS Cloud Architecture: A Practical Blueprint and What It CostsCloud Migration Strategy: How to Pick the Right R for Each App
Choose one of the 7 Rs per application, map what each system talks to, move in waves, rehearse the rollback and budget for the costs most migration plans leave out.
Read More: Cloud Migration Strategy: How to Pick the Right R for Each AppAWS Cost Optimization: What to Fix First, and What It Saves
The order matters more than any single trick: clean up, rightsize and move to Graviton before you buy Savings Plans. Worked examples use AWS list prices from October 2026.
Read More: AWS Cost Optimization: What to Fix First, and What It Saves
