Full pipeline: test → build → release → deploy
A repo with protected main, CI, automated releases and a deployment.
By Invicly Tech, , in Git, GitHub & GitHub Actions. About 11 minutes to read.
In short
The project combines everything into one repo: protected main, CI on every PR, automated releases and an OIDC deployment behind an approval gate, all documented in the README.
Explained simply
This project turns one repository into a small software factory. A change starts as a pull request, gets checked by robots and reviewed by a person, is merged, packaged as a numbered release, and is deployed, first to a test environment and then, after a human says yes, to production.
Each stage is a gate. Protected main stops anyone from pushing straight to the main branch. CI (continuous integration) runs the tests on every pull request. A release workflow stamps a version number and writes the changelog. A deploy workflow ships that exact version.
Security is built in, not added later. The deploy job logs in to the cloud with OIDC (OpenID Connect): GitHub hands it a short-lived identity token, and the cloud trusts that token for a few minutes. No long-lived password is stored anywhere in the repo.
Finally, the README explains the whole pipeline: what runs when, how to cut a release, and how to roll back. If a new teammate can ship a change by reading it, the project is done.
Press Play on a diagram to walk through it one step at a time.
- 1Open pull request
CODEOWNERS review requested automatically.
- 2CI checks
Lint and tests across a small matrix.
- 3Merge to main
Allowed only with approval and green checks.
- 4Release
Version tag, changelog and image pushed to GHCR.
- 5Deploy staging
OIDC login, automatic deploy, smoke test.
- 6Approve production
Environment reviewers approve the same image.
- CODEOWNERS
- Required reviewers by path
- dependabot.yml
- Weekly dependency updates
- workflows/
- ci.yml
- release.yml
- deploy.yml
- 1Ruleset on main
PR, approval, code owners, no force push
- 2Required CI checks
Lint and tests must be green
- 3Release PR
Version and changelog reviewed like code
- 4Staging deploy
Automatic, ends with a smoke test
- 5Production environment
Reviewer approval, main or tags only
In depth
Protecting main with rulesets and CODEOWNERS
Create a branch ruleset (Settings, Rules, Rulesets) that targets the default branch. Turn on: require a pull request before merging, at least one approval, dismiss stale approvals when new commits are pushed, require review from code owners, require status checks to pass, and block force pushes and deletions. Leave the bypass list empty so admins follow the same rules.
The status check names you require must match the job names that CI reports, for example test (ubuntu-latest, 22). A check that never runs, such as one skipped by a paths filter, leaves the pull request stuck waiting, so keep required jobs always running.
CODEOWNERS lives in .github/, the repo root or docs/. Each line is a pattern followed by owners, and the last matching line wins. A line like /infra/ @org/platform means any change under infra needs a review from the platform team.
- * @org/maintainers sets a default owner for everything
- /.github/workflows/ @org/platform guards the pipeline itself
- Require branches to be up to date, or use a merge queue on busy repos
CI on every pull request
The CI workflow runs on pull_request and on push to main. Keep it fast and trustworthy: cache dependencies with the setup action's built-in cache, run lint and tests, and use a small matrix only where versions really differ. Set permissions: contents: read at the top so the token can only read the code.
Add concurrency with a group based on the branch and cancel-in-progress: true, so a new push cancels the outdated run instead of queueing behind it. Upload test reports or coverage with actions/upload-artifact when a run fails, so reviewers can see why without rerunning.
Pull requests from forks run with a read-only token and no access to secrets. That is a safety feature; never switch such workflows to pull_request_target and check out the fork's code, which would run untrusted code with secrets.
Automated releases and changelogs
Release automation reads your commit history and decides the next version. With Conventional Commits, fix: means a patch bump, feat: a minor bump, and a ! or BREAKING CHANGE footer a major bump. Tools such as release-please open a release pull request that updates the version and CHANGELOG.md; merging it creates the tag and the GitHub release.
The release workflow then builds the container image once, tags it with the version (for example ghcr.io/org/app:1.4.0) and pushes it to GitHub Container Registry using the GITHUB_TOKEN with packages: write.
One trap catches many people: events caused by the GITHUB_TOKEN do not start new workflow runs (apart from workflow_dispatch and repository_dispatch). If a release is created with GITHUB_TOKEN, a separate workflow listening for release: published will not fire. Either deploy from the same workflow as a later job, or create the release with a GitHub App token.
- 1feat: and fix: commits
Merged to main through pull requests
- 2Release PR opened
Next version and changelog proposed
- 3Merge the release PR
Tag v1.4.0 and GitHub release created
- 4Build image once
Pushed as ghcr.io/org/app:1.4.0
- 5Deploy jobs start
Same workflow, so no trigger trap
Deploying with OIDC and environment gates
A job that sets permissions: id-token: write can ask GitHub for an OIDC token. The token's sub claim describes where it came from; for a job tied to an environment it looks like repo:org/app:environment:production. In AWS you create an IAM role whose trust policy accepts tokens from token.actions.githubusercontent.com only with that exact sub, and aws-actions/configure-aws-credentials exchanges the token for temporary keys.
Environments add the human gate. Under Settings, Environments, give production required reviewers, optionally a wait timer, and a deployment branch rule so only main or version tags can deploy. A job with environment: production pauses until a reviewer approves, and environment secrets are only released to it after approval.
Add concurrency per environment so two deploys never run at once, and finish each deploy with a smoke test that calls the health endpoint and fails the job if it does not answer.
- Deploy job to GitHub: Job targets environment production1Job targets environment production
- GitHub to Reviewer: Approval requested2Approval requested
- Reviewer to GitHub: Approved3Approved
- Deploy job to GitHub: Request OIDC token4Request OIDC token
- GitHub to Deploy job: Token, sub ends environment:production5Token, sub ends environment:production
- Deploy job to AWS STS: AssumeRoleWithWebIdentity6AssumeRoleWithWebIdentity
- AWS STS to Deploy job: Temporary credentials, about 1 hour7Temporary credentials, about 1 hour
Documenting the pipeline
The README is part of the deliverable. Start with status badges: each workflow has one at https://github.com/ORG/REPO/actions/workflows/ci.yml/badge.svg. Then a short pipeline section: a diagram or list of what happens on a pull request, on merge, on release and on deploy.
Add the procedures people actually need. How to cut a release (merge the release pull request). How to promote to production (approve the waiting job in the Actions tab). How to roll back (rerun the deploy job of the previous release, or trigger a workflow_dispatch with an older tag). Where secrets and roles live, without the values.
Keep the pipeline itself reviewable too: pin third-party actions to a full commit SHA, enable Dependabot for the github-actions ecosystem, and make /.github/ owned by a CODEOWNERS team.
Learn it in 5 short steps
About 1h each. Track them with a timer in your plan.
- 1Protect main with rules and CODEOWNERS~1h
- 2Add CI tests on every pull request~1h
- 3Automate releases and changelogs~1h
- 4Deploy via OIDC with environment gates~1h
- 5Document the pipeline in the README~1h
Key points
- Build order: protection rules, CI, release automation, then deployment.
- Deploy the image built at release time; never rebuild per environment.
- Use OIDC and environments so production needs no stored keys and a human approval.
- The README should show the pipeline and how to cut a release.
Key terms
Tap a card to flip it. 0/4 known
Examples
# deploy.yml
on: { release: { types: [published] } }
permissions: { id-token: write, contents: read }
jobs:
staging:
uses: ./.github/workflows/deploy-env.yml
with: { environment: staging, tag: "${{ github.event.release.tag_name }}" }
production:
needs: staging
uses: ./.github/workflows/deploy-env.yml
with: { environment: production, tag: "${{ github.event.release.tag_name }}" }One release deploys to staging, then waits for production approval.
CI that is safe to require
This workflow runs on every pull request and every push to main. The token is read-only, an outdated run on the same branch is cancelled, and the job name (test) is what you add as a required status check in the ruleset. Because there is no paths filter, the check always reports, so pull requests never get stuck waiting.
name: ci
on:
pull_request:
push: { branches: [main] }
permissions: { contents: read }
concurrency: { group: "ci-${{ github.ref }}", cancel-in-progress: true }
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: npm }
- run: npm ci
- run: npm run lint && npm testTrust policy that only production can use
The AWS role for production should accept only OIDC tokens from this repo's production environment. The condition checks the audience and the exact sub. A workflow on a feature branch, or a job targeting staging, gets a different sub and is refused. Create a second role with the staging sub for staging deploys.
{
"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:org/app:environment:production"
}
}
}Quick reference
- Required status check names must match the job names CI reports
- CODEOWNERS: last matching pattern wins; put it in .github/CODEOWNERS
- fix: = patch, feat: = minor, feat!: or BREAKING CHANGE = major (Conventional Commits)
- Events made with GITHUB_TOKEN do not trigger new workflow runs
- OIDC needs permissions: id-token: write on the job or workflow
- Environment sub claim: repo:ORG/REPO:environment:NAME
- Build the image once at release; deploy that same tag everywhere
- Badge URL: github.com/ORG/REPO/actions/workflows/ci.yml/badge.svg
Common mistakes
- Starting with deployment before CI is reliable, so broken code ships faster.
- Allowing admins to bypass protection, making the gates optional.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write a CODEOWNERS file: maintainers own everything, the platform team owns workflows and infra, and the frontend team owns web/.
- Exercise 2medium
Add a release job that pushes the image to GHCR tagged with the release version, after release-please creates the release in the same workflow.
- Exercise 3hard
Write a reusable deploy workflow that takes an environment and tag, logs in to AWS with OIDC, deploys, runs a smoke test, and never runs twice at once for the same environment.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Branch protection rules or rulesets?
- Both work. Rulesets are the newer system: several can apply at once, they can target many branches or tags by pattern, and they show who can bypass them more clearly.
- Can I require approvals for environments on a private repo?
- Required reviewers for environments are available on public repositories and, for private repositories, on paid plans such as Team or Enterprise.
- How do I roll back a bad release?
- Redeploy the previous version's image tag, for example by rerunning that release's deploy job or a workflow_dispatch with the old tag. Then fix forward with a new release.
- Should I use release-please or semantic-release?
- Both read Conventional Commits. release-please adds a reviewable release pull request before tagging; semantic-release publishes directly on every qualifying merge.