Skip to content

Commit

Permalink
Add auto-deploy support
Browse files Browse the repository at this point in the history
  • Loading branch information
nginx-jack committed Sep 4, 2024
1 parent db10ebd commit d20def4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/docs-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ on:
type: string
description: "Overrides default of latest hugo theme. Useful for testing pre-release versions. Must start with 'v' before version."
default: ""
auto_deploy_branch:
type: string
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."
auto_deploy_env:
type: string
description: "Env to which auto_deploy_branch will be deployed to. Preview is not supported."

env:
GO_VERISON: "1.21" # Go version used for `hugo mod get`
Expand All @@ -55,7 +61,7 @@ env:
jobs:
checks:
name: Checks and variables
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
Expand All @@ -74,7 +80,7 @@ jobs:
build:
needs: [checks]
if: ${{ needs.checks.outputs.forked_workflow == 'false' }}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
# Remapping of inputs to envs
PRODUCTION_URL_PATH: ${{inputs.production_url_path}}
Expand All @@ -83,10 +89,21 @@ jobs:
EVENT_ACTION: ${{github.event.action}}
DEPLOYMENT_ENV: ${{inputs.environment}}
THEME_VERSION: ${{inputs.force_hugo_theme_version}}
AUTO_DEPLOY_BRANCH: ${{inputs.auto_deploy_branch}}
AUTO_DEPLOY_ENV: ${{inputs.auto_deploy_env}}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- name: Check and setup auto-deploy
# Auto deploy should only trigger when the auto_deploy_branch match the current ref.
# We also check if `environment` has already been set, otherwise this flow could cause
# manual triggers to deploy to `auto_deploy_env` instead of the one specified in the trigger.
if: (inputs.auto_deploy_branch == github.ref_name) && inputs.environment == ''
run: |
echo "Auto deploy branch ($AUTO_DEPLOY_BRANCH) matches current branch. Attempting autodeploy to $AUTO_DEPLOY_ENV."
echo "DEPLOYMENT_ENV=${AUTO_DEPLOY_ENV}" >> $GITHUB_ENV
- name: Validate environment inputs
run: |
if [[ -z "${DEPLOYMENT_ENV}" ]]; then
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ on:
branches:
- "*"

# Used for auto deploy builds. This branch _must_ match auto_deploy_branch
push:
branches:
- "main"

jobs:
# Configure the build
call-docs-build-push:
Expand All @@ -93,6 +98,9 @@ jobs:
docs_build_path: "./"
doc_type: "hugo"
environment: ${{inputs.environment}}
# This means, any time there's a push to main, a deployment will automatically be made to dev.
auto_deploy_branch: "main"
auto_deploy_env: "dev"
secrets:
AZURE_CREDENTIALS: ${{secrets.AZURE_CREDENTIALS}}
AZURE_KEY_VAULT: ${{secrets.AZURE_KEY_VAULT}}
Expand Down

0 comments on commit d20def4

Please sign in to comment.