Skip to content

Commit d20def4

Browse files
committed
Add auto-deploy support
1 parent db10ebd commit d20def4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

+19-2
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: "A branch specified here will autodeploy to the environment specified in auto_deploy_env. An on.push event 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`
@@ -55,7 +61,7 @@ env:
5561
jobs:
5662
checks:
5763
name: Checks and variables
58-
runs-on: ubuntu-22.04
64+
runs-on: ubuntu-24.04
5965
permissions:
6066
contents: read
6167
outputs:
@@ -74,7 +80,7 @@ jobs:
7480
build:
7581
needs: [checks]
7682
if: ${{ needs.checks.outputs.forked_workflow == 'false' }}
77-
runs-on: ubuntu-latest
83+
runs-on: ubuntu-24.04
7884
env:
7985
# Remapping of inputs to envs
8086
PRODUCTION_URL_PATH: ${{inputs.production_url_path}}
@@ -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

+8
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)