GitHub Actions CI/CD Pipeline Tutorial: Build, Test, Deploy, and Promote Across Environments
GitHub ActionsCI/CDDevOpsContinuous DeliveryAutomation

GitHub Actions CI/CD Pipeline Tutorial: Build, Test, Deploy, and Promote Across Environments

CCloud Life Editorial Team
2026-12-06
7 min read

A practical GitHub Actions checklist for testing, building, approving, promoting, and rolling back releases across environments.

This GitHub Actions CI/CD pipeline tutorial gives you a repeatable path from pull request to production, with separate build, test, deployment, approval, artifact promotion, and rollback controls. Use the checklist to design a pipeline for a new service, review an existing workflow, or update delivery practices when your repository, cloud platform, or deployment tool changes.

Overview

A safe continuous delivery pipeline should make each release traceable and reduce the number of decisions made manually during deployment. A practical flow is:

  1. A pull request runs fast validation, tests, and security checks.
  2. A merge to the default branch builds one deployable artifact.
  3. The artifact is deployed to a non-production environment.
  4. Smoke tests confirm that the deployment is usable.
  5. A protected production environment requires approval when appropriate.
  6. The same artifact is promoted to production rather than rebuilt.

Keeping build and promotion separate matters. If production is built independently, dependencies, source files, or build tools could differ from what was tested in staging. An immutable artifact—such as a container image or packaged application—provides a clearer link between a commit, a workflow run, and a release.

A simple branch-to-environment strategy works for many teams: pull requests target the default branch and deploy only to ephemeral or validation resources; the default branch deploys to staging; a version tag or approved workflow run promotes the staged artifact to production. Teams that use a release branch can apply the same model, provided the promotion rule is documented and consistent.

Checklist by scenario

For pull requests

  • Trigger validation for relevant pull request activity, and cancel outdated runs when a newer commit supersedes them.
  • Set a minimal permissions block. Grant only the repository contents, pull request, or security permissions that a job actually needs.
  • Check out the code, configure the required runtime, restore dependencies with the official package-manager cache where practical, and run formatting, linting, unit tests, and static analysis.
  • Build the application when compilation or packaging errors would otherwise appear later in the pipeline.
  • Publish test reports or logs when failures are difficult to diagnose from standard output alone.
  • Keep pull-request jobs fast. Move lengthy integration or end-to-end checks to a separate job or a controlled staging workflow if they do not need to run on every change.

For builds on the default branch

  • Pin action references to an approved major version or, for higher assurance, to a reviewed commit SHA. Recheck those references during routine maintenance.
  • Use a lockfile and install dependencies in a reproducible mode. Do not allow the build to silently resolve a different dependency set from the one tested locally.
  • Create a uniquely identifiable artifact using the commit SHA, release tag, or another immutable identifier.
  • Upload the artifact once and pass its name, digest, or package coordinates to later jobs.
  • Record useful metadata such as the source commit, build timestamp, application version, and deployment target.
  • Run vulnerability, license, or image checks according to your risk requirements before the artifact becomes eligible for deployment.

For staging deployment

  • Download the artifact produced by the build job rather than rebuilding from source.
  • Use a GitHub Actions environment named for staging, with environment-specific variables and credentials.
  • Run database migrations as an explicit, observable step. Decide in advance whether migrations are backward-compatible with the previous application version.
  • Deploy using a service account or cloud identity with only the permissions needed for that target.
  • Run smoke tests against a health endpoint and one or two representative application paths.
  • Expose deployment logs and the deployed version so an engineer can quickly confirm what is running.

For production promotion

  • Require a release tag, a successful staging result, or another explicit promotion condition.
  • Configure the production GitHub Actions environment with required reviewers when a human approval step is appropriate.
  • Use production-scoped secrets or cloud identity configuration. Never reuse staging credentials simply because the commands are similar.
  • Promote the previously tested artifact by its immutable identifier.
  • Deploy using a strategy suited to the service: rolling, blue-green, canary, or a controlled replacement.
  • Run post-deployment checks, then publish the release URL, commit, artifact identifier, and outcome to the workflow summary or team notification channel.

For reusable workflows

Use a reusable workflow when several services share the same delivery pattern. A caller workflow can pass inputs such as the application name, artifact name, environment, and deployment mode. Keep cloud-specific details inside the reusable workflow or a dedicated deployment action, and document required secrets and permissions at the interface.

A reusable workflow should have a narrow contract. Validate required inputs, define safe defaults, and avoid accepting arbitrary shell commands from callers. This limits accidental differences between services while allowing teams to update common CI/CD behavior in one place.

Illustrative workflow structure

name: delivery

on:
  pull_request:
  push:
    branches: [main]
    tags: ['release-*']

permissions:
  contents: read

jobs:
  test:
    uses: ./.github/workflows/reusable-test.yml
    with:
      runtime: 'your-runtime'

  build:
    needs: test
    uses: ./.github/workflows/reusable-build.yml
    with:
      artifact-name: 'service-${{ github.sha }}'

  deploy-staging:
    if: github.ref == 'refs/heads/main'
    needs: build
    uses: ./.github/workflows/reusable-deploy.yml
    with:
      environment: staging
      artifact-name: 'service-${{ github.sha }}'
    secrets: inherit

  deploy-production:
    if: startsWith(github.ref, 'refs/tags/release-')
    needs: deploy-staging
    environment: production
    uses: ./.github/workflows/reusable-deploy.yml
    with:
      environment: production
      artifact-name: 'service-${{ github.sha }}'
    secrets: inherit

This is a design example, not a drop-in deployment. Adapt event filters, artifact handling, runtime setup, and cloud commands to your repository. Verify the current syntax and supported references for every marketplace action before committing the workflow.

What to double-check

Secrets, permissions, and identity

Prefer short-lived cloud authentication through OpenID Connect (OIDC) when your cloud provider and deployment integration support it. The workflow requests an identity token, and the cloud-side trust policy limits which repository, branch, tag, or environment may assume the deployment role. A conceptual job permission block may look like this:

permissions:
  contents: read
  id-token: write

The permission alone does not grant access; the cloud trust configuration must also restrict the identity. Review both sides together. For systems that still require stored credentials, place them in the narrowest environment or repository scope and rotate them according to your operating process.

Caching and artifacts

Dependency caching can shorten workflows, but a cache is not a release artifact. Build outputs should be uploaded deliberately and referenced by an immutable name. Include dependency lockfiles and relevant configuration in cache keys so a changed dependency set does not reuse an inappropriate cache. Set a recovery path for cache misses; correctness is more important than speed.

Approvals and branch protection

Environment approvals are useful when production changes need a deliberate review. They should complement, not replace, protected branches, required checks, code review, and deployment observability. Confirm who can approve, what evidence they review, and whether an approval can be bypassed by changing the workflow file or triggering a different event.

Rollback behavior

Write the rollback procedure before the first production release. It may mean redeploying the previous artifact, switching traffic to the previous environment, or reverting a configuration change. Test that the previous artifact remains available and that database migrations do not make rollback impossible. A failed deployment should stop clearly, preserve logs, and identify the last known-good version.

Common mistakes

  • Rebuilding during promotion: this weakens the connection between tested code and deployed code. Build once and promote the same artifact.
  • Using broad permissions: begin with read-only repository access and add narrowly scoped permissions only when a job requires them.
  • Putting every secret in repository-wide storage: separate staging and production access through environments and cloud-side role restrictions.
  • Relying only on a successful process exit: add smoke tests and deployment verification. A command can succeed while the application remains unhealthy.
  • Ignoring concurrency: overlapping deployments can produce confusing results. Define whether a newer deployment cancels an older one or waits for it.
  • Making migrations inseparable from rollback: use backward-compatible schema changes where possible and document the recovery sequence.
  • Copying marketplace actions without review: check the action’s inputs, permissions, maintenance status, and release reference before adoption.
  • Keeping one enormous workflow: split testing, building, and deployment into understandable jobs or reusable workflows with clear inputs and outputs.

For adjacent infrastructure checks, pair the pipeline with a Terraform testing and policy workflow, and review image handling with the container image security workflow. These controls help ensure that CI/CD automation does not simply deliver an untested image or unreviewed infrastructure change.

When to revisit

Review this pipeline before a seasonal planning cycle, when a new service is introduced, or whenever the deployment target changes. Also revisit it after changes to repository permissions, cloud identity policies, runtime versions, artifact registries, deployment actions, or GitHub-hosted and self-hosted runner arrangements.

At each review, run this short check:

  1. Trace one commit from pull request through the exact production artifact.
  2. Confirm that tests, branch rules, environment approvals, and deployment conditions still match your release policy.
  3. Verify action references, runner capabilities, caching behavior, and reusable workflow inputs.
  4. Inspect OIDC trust rules or stored credentials and remove access that is no longer needed.
  5. Perform a rollback rehearsal and confirm that logs identify the deployed version.

Keep the workflow readable enough that the next engineer can answer three questions quickly: what will run, what can reach production, and how do we recover? Those answers are the practical measure of a dependable GitHub Actions CI/CD pipeline.

Related Topics

#GitHub Actions#CI/CD#DevOps#Continuous Delivery#Automation
C

Cloud Life Editorial Team

Cloud and DevOps Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.