Skip to content

Add auto-deploy support #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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