GitHub actions and repository environments

Background

This repository demonstrate how to run a github action against multiple repository environments in which some of those environments need approval before deploying to the environment

Since this is a proof of concept project, the action does not deploy code to any servers but instead print the environment name at the end.

Enviironments

I defined 3 environments

Environment Name Need approval
DEV
QA
PROD

Action

This action package a Java based application and accepts environment name as input parameter. Action file is located in .github/workflows/environment-based.yml

Creating environments

  • You need to have admin access to the repository. To create a new environment you can got to Repository settings -> Environments -> click on new Environment
  • The enter environment name and click on configure environment button

image image

Environments

DEV

image

QA and PROD with approver needs

Click on environment name then enable Required reviewers then in the search box type github handles and add desired reviewers image

Click on environment name then enable Required reviewers then in the search box type github handles and add desired reviewers

Trigger actions

Against environment

Go to Actions tab -> select the action from side menu -> click on Run workflow -> select environment -> click on run workflow green button

DEV

Since there is no reviewer required, it automatically starts and finishes the run and look into build and deploy summary image

QA and PROD

This step needs approval and when you trigger the action, it sends an approval request to reviewer (usually via email, it depends on your github notification settings) In action run details page click on review deployment (if you are a reviewer) -> select the environment name in poped up window -> leave a comment if you want -> approve or reject the request

If you approve the request then action will be triggered and if you reject it then action's run will be cancelled.

You will see a Deployment reviews box below action run

image image image image