githubyamlcontinuous-integrationgithub-actions

GitHub pause in the middle of workflow action


I have created GitHub workflow. It deployed first on staging and than on the production environment on merge. What I want is to pause the deployment at staging, (so that I can do a quick sanity test on staging) and than I have some manual trigger to deploy to production.

Below is the workflow yml file.

name: main

on:
  push:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/build-test.yml
    secrets: inherit

  staging:
    uses: ./.github/workflows/staging-deploy.yml
    secrets: inherit

  prod:
    name: 'Deploy to Prod'
    uses: ./.github/workflows/deploy.yml
    needs: [test, staging]
    with:
      stage: prod
    secrets: inherit

Solution

  • Github Actions allows you to review deployments by using environments.

    First, you will need to create an environment in the repository, and add Reviewers to it.

    Then, you will need to add a job in your workflow asking for this approval before executing the deploy to production.

    Example with an environment named Prod asking for review:

    name: main
    
    on:
      push:
        branches:
          - main
    
    jobs:
      test:
        uses: ./.github/workflows/build-test.yml
        secrets: inherit
    
      staging:
        uses: ./.github/workflows/staging-deploy.yml
        secrets: inherit
    
      manual-approval:
        environment: 'Prod'
        runs-on: ubuntu-24.04
        needs:
          - test
          - staging
        steps:
          - run: echo "Approved to Prod"
    
      prod:
        name: 'Deploy to Prod'
        uses: ./.github/workflows/deploy.yml
        needs: 
          - manual-approval
        with:
          stage: prod
        secrets: inherit