Skip to main content
In this guide, we’ll set up a GitHub Actions CI/CD workflow that uses conditional if expressions to deploy an application to development on feature branches and to production only from the main branch. Pull requests will gate production releases behind review and environment protection rules.

Table of Contents

Environment Variables

Define shared environment variables at the top of your workflow file:
Always store sensitive data such as database credentials and API keys in GitHub Secrets or Variables.

Job Overview

Below is a summary of each job, its trigger condition, and dependencies:

Dev Deploy Job

The dev-deploy job runs on any branch matching feature/. It depends on the docker job:
The contains function evaluates whether the branch ref string includes feature/. See GitHub Actions expressions for more.

Dev Integration Testing Job

After deployment to development, run integration tests to verify application health:

Prod Deploy Job

Production deployments trigger only on the main branch. This job also sets up Kubernetes credentials and applies manifests:

Prod Integration Testing Job

Once production is deployed, run a final health check:

Workflow Execution & Pull Request Flow

  1. Feature Branch Push
    • docker builds and pushes the image.
    • dev-deploy and dev-integration-testing run automatically.
    • Production jobs are skipped on feature branches.
The image shows a GitHub Actions workflow interface for a project named "solar-system," displaying a workflow in progress with steps like unit testing, containerization, and deployment.
  1. Review Feature Deployments
    • The workflow summary marks all dev jobs as successful.
The image shows a GitHub Actions workflow summary with various jobs like unit testing, containerization, and deployment, all marked as successful. It includes a visual representation of the workflow steps and deployment protection rules.
  1. Open Pull Request
    • Create a PR from feature/* into main to prepare a production release.
The image shows a GitHub interface where a user is creating a pull request to merge changes from a feature branch into the main branch, with a description about adding GitHub Actions workflows for CI/CD automation.
  1. Confirm Previous Deployments
    • The PR page lists all commits and verifies the dev deployment.
The image shows a GitHub pull request page with a list of commits, most of which are verified, and a notification that the branch was successfully deployed.
  1. Merge to Main
    • Merging triggers a new workflow: dev jobs skip, prod job awaits manual approval or timer.
The image shows a GitHub Actions workflow interface for a project named "solar-system," displaying the status of various jobs like unit testing, code coverage, and deployment processes. The workflow is waiting for a review to deploy to production.
  1. Approve or Reject
    • A reviewer approves the production deployment via the Actions UI.
The image shows a GitHub Actions interface with a pending deployment review for a production environment. There are options to reject or approve and deploy the changes.
  1. Production Deployment Complete
    • Once approved, the production deployment proceeds and can be monitored in the Deployments UI.
This image shows a GitHub deployment page for a project named "solar-system," displaying active deployments and a list of recent deployment activities.
By leveraging conditional if expressions, pull requests, and environment protection rules, you can build a robust, secure CI/CD pipeline that separates development and production deployments seamlessly.

Watch Video