In this hands-on lab your will create simple deployment workflow using environments . If you like more background information, please refer to the Deploying with GitHub Actions pages on GitHub Docs.
- On GitHub, navigate to the main page of the repository.
- Click
Settings
- In the left sidebar, click
Environments
- Click
New Environment
- In the
Name
field typeDev
- Click
Configure Environment
- Click
Save Protection rules
- In the left sidebar, click
Environments
- Click
New Environment
- In the
Name*
field typeProduction
- Click
Configure Environment
- Select
Required Reviewers
checkbox - Add yourself as a review
- Click
Save Protection rules
- On GitHub, navigate to the main page of the repository.
- Select
Actions
- Select
New Workflow
- Select
Set up a workflow yourself
- Name the file
deploy.yml
- Paste in the following code:
###################################################################
#Deploy action
# GitHub displays the names of your workflows on your repository's actions page
name: Bootcamp Deploy Action!
# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
ghhandle:
description: 'The GitHub Handle of the user to set up'
default: 'bootcamp_magician'
type: string
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
DeployToDev:
# The type of runner that the job will run on
runs-on: windows-latest
environment: Dev
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs a single command using the runners shell
- name: Deploying To Dev for ${{ inputs.ghhandle }}!
run: "echo I just deployed to Dev"
DeployToProd:
runs-on: windows-latest
needs: DeployToDev
environment: Production
steps:
- name: Deploying To Production for ${{ inputs.ghhandle }}!
run: "echo I just deployed to Production"
###################################################################
-
Commit changes directly to main branch
-
Now you can see Bootcamp deploy action in the Actions tab.
-
Since we have added Manual
workflow_dispatch
event as trigger type, we can trigger this manually only. Click Run Workflow -
When the job is triggered for Production environment tasks, it will ask for review. You need to approve to continue with the execution.