Deployment #150
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Deployment | |
on: | |
workflow_dispatch: | |
inputs: | |
env: | |
description: "Select environment to deploy to" | |
type: choice | |
required: true | |
default: "stage" | |
options: | |
- stage | |
- prod | |
- stage & prod | |
clean: | |
description: "Clean cache?" | |
type: boolean | |
required: true | |
default: "no" | |
build-navigation: | |
description: "Build navigation file?" | |
type: boolean | |
required: true | |
default: "false" | |
build-redirections: | |
description: "Build redirections file?" | |
type: boolean | |
required: true | |
default: "false" | |
jobs: | |
set-state: | |
runs-on: ubuntu-latest | |
outputs: | |
path_prefix: ${{ steps.get_path_prefix.outputs.path_prefix }} | |
branch_short_ref: ${{ steps.get_branch.outputs.branch }} | |
deploy_stage: ${{ contains(inputs.env, 'stage') }} | |
deploy_prod: ${{ contains(inputs.env, 'prod') }} | |
clean_cache: ${{ inputs.clean }} | |
build_navigation: ${{ inputs.build-navigation }} | |
build_redirections: ${{ inputs.build-redirections }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get path prefix | |
uses: actions/github-script@v7 | |
id: get_path_prefix | |
with: | |
script: | | |
const script = require('./.github/scripts/get-path-prefix.js'); | |
script({ core, isStage:"${{ contains(inputs.env, 'stage') }}", isProd:"${{ contains(inputs.env, 'prod') }}" }); | |
result-encoding: string | |
- name: Get branch name | |
shell: bash | |
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "$GITHUB_OUTPUT" | |
id: get_branch | |
echo-state: | |
needs: [set-state] | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "Deploy to stage - ${{ needs.set-state.outputs.deploy_stage }}" | |
- run: echo "Deploy to prod - ${{ needs.set-state.outputs.deploy_prod }}" | |
- run: echo "Clean cache - ${{ needs.set-state.outputs.clean_cache }}" | |
- run: echo "Build navigation file - ${{ needs.set-state.outputs.build_navigation }}" | |
- run: echo "Build redirections file - ${{ needs.set-state.outputs.build_redirections }}" | |
- run: echo "Path prefix - ${{ needs.set-state.outputs.path_prefix }}" | |
- run: echo "Repository org - ${{ github.event.repository.owner.login }}" | |
- run: echo "Repository name - ${{ github.event.repository.name }}" | |
- run: echo "Repository branch - ${{ needs.set-state.outputs.branch_short_ref }}" | |
build: | |
defaults: | |
run: | |
shell: bash | |
needs: [set-state] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node v18 for Yarn v3 | |
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "18" | |
- name: Enable Corepack for Yarn v3 | |
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true' | |
run: corepack enable | |
- name: Install Yarn v4 | |
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true' | |
uses: borales/actions-yarn@v4 | |
with: | |
cmd: set version stable | |
- name: Install Dependencies | |
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true' | |
uses: borales/actions-yarn@v3 | |
env: | |
YARN_ENABLE_IMMUTABLE_INSTALLS: false | |
with: | |
cmd: install | |
- name: Build navigation file | |
if: needs.set-state.outputs.build_navigation == 'true' | |
uses: borales/actions-yarn@v3 | |
with: | |
cmd: buildNavigation | |
- name: Build redirections file | |
if: needs.set-state.outputs.build_redirections == 'true' | |
uses: borales/actions-yarn@v3 | |
with: | |
cmd: buildRedirections | |
- name: Clean cache on stage | |
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_stage == 'true' | |
run: | | |
bash .github/scripts/process-mds.sh cache stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}" | |
- name: Clean cache on prod | |
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_prod == 'true' | |
run: | | |
bash .github/scripts/process-mds.sh cache prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}" | |
- name: Deploy to stage | |
if: needs.set-state.outputs.deploy_stage == 'true' | |
run: | | |
bash .github/scripts/process-mds.sh preview stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}" | |
- name: Deploy to prod | |
if: needs.set-state.outputs.deploy_prod == 'true' | |
run: | | |
bash .github/scripts/process-mds.sh preview prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}" | |
bash .github/scripts/process-mds.sh live prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}" |