Skip to content

Commit a2c6aaa

Browse files
committed
Add auto-deploy support
1 parent a733e84 commit a2c6aaa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.github/workflows/docs-build-push.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ on:
3838
type: string
3939
description: "Overrides default of latest hugo theme. Useful for testing pre-release versions. Must start with 'v' before version."
4040
default: ""
41+
auto_deploy_branch:
42+
type: string
43+
description: "Branch specified here will autodeploy to production. An on.push for this branch must be specified in caller."
44+
auto_deploy_env:
45+
type: string
46+
description: "Env to which auto_deploy_branch will be deployed to. Preview is not supported."
4147

4248
env:
4349
GO_VERISON: "1.21" # Go version used for `hugo mod get`
@@ -83,10 +89,21 @@ jobs:
8389
EVENT_ACTION: ${{github.event.action}}
8490
DEPLOYMENT_ENV: ${{inputs.environment}}
8591
THEME_VERSION: ${{inputs.force_hugo_theme_version}}
92+
AUTO_DEPLOY_BRANCH: ${{inputs.auto_deploy_branch}}
93+
AUTO_DEPLOY_ENV: ${{inputs.auto_deploy_env}}
8694

8795
concurrency:
8896
group: ${{ github.workflow }}-${{ github.ref }}
8997
steps:
98+
- name: Check and setup auto-deploy
99+
# Auto deploy should only trigger when the auto_deploy_branch match the current ref.
100+
# We also check if `environment` has already been set, otherwise this flow could cause
101+
# manual triggers to deploy to `auto_deploy_env` instead of the one specified in the trigger.
102+
if: (inputs.auto_deploy_branch == github.ref_name) && inputs.environment == ''
103+
run: |
104+
echo "Auto deploy branch ($AUTO_DEPLOY_BRANCH) matches current branch. Attempting autodeploy to $AUTO_DEPLOY_ENV."
105+
echo "DEPLOYMENT_ENV=${AUTO_DEPLOY_ENV}" >> $GITHUB_ENV
106+
90107
- name: Validate environment inputs
91108
run: |
92109
if [[ -z "${DEPLOYMENT_ENV}" ]]; then

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ on:
8282
branches:
8383
- "*"
8484

85+
# Used for auto deploy builds. This branch _must_ match auto_deploy_branch
86+
push:
87+
branches:
88+
- "main"
89+
8590
jobs:
8691
# Configure the build
8792
call-docs-build-push:
@@ -93,6 +98,9 @@ jobs:
9398
docs_build_path: "./"
9499
doc_type: "hugo"
95100
environment: ${{inputs.environment}}
101+
# This means, any time there's a push to main, a deployment will automatically be made to dev.
102+
auto_deploy_branch: "main"
103+
auto_deploy_env: "dev"
96104
secrets:
97105
AZURE_CREDENTIALS: ${{secrets.AZURE_CREDENTIALS}}
98106
AZURE_KEY_VAULT: ${{secrets.AZURE_KEY_VAULT}}

0 commit comments

Comments
 (0)