Skip to content

Deployment

Deployment #135

Workflow file for this run

---
name: Deployment
on:
workflow_dispatch:
inputs:
env:
description: "Select environment to deploy to"
type: choice
required: true
default: "stage"
options:
- stage
- prod
baseSha:
description: "Use base SHA commit to deploy from (empty string defaults to last commit before HEAD)"
type: string
required: false
default: ""
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') }}
base_Sha: ${{ github.event.inputs.baseSha }}
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 "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 }}"
- run: echo "Base Sha - ${{ needs.set-state.outputs.base_Sha }}"
deploy:
defaults:
run:
shell: bash
needs: [set-state]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get changed files in the src/pages and static folder
id: changed-files-specific
uses: tj-actions/[email protected]
with:
json: true
escape_json: false
files: |
src/pages/**
static/**
base_sha: ${{ needs.set-state.outputs.base_Sha }}
- name: Deploy to stage
if: needs.set-state.outputs.deploy_stage == 'true' && steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/deploy.js');
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "preview",
siteEnv: "stage",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});
- name: Clean cache on stage
if: needs.set-state.outputs.deploy_stage == 'true' && steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/deploy.js');
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "cache",
siteEnv: "stage",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});
- name: Deploy to prod (Step 1 of 2)
if: needs.set-state.outputs.deploy_prod == 'true' && steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/deploy.js');
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "preview",
siteEnv: "prod",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});
- name: Deploy to prod (Step 2 of 2)
if: needs.set-state.outputs.deploy_prod == 'true' && steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/deploy.js');
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "live",
siteEnv: "prod",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});
- name: Clean cache on prod
if: needs.set-state.outputs.deploy_prod == 'true' && steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/deploy.js');
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "cache",
siteEnv: "stage",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});
await script({
core,
changes: ${{ steps.changed-files-specific.outputs.all_changed_files }},
deletions: ${{ steps.changed-files-specific.outputs.deleted_files }},
operation: "cache",
siteEnv: "prod",
branch: "${{ needs.set-state.outputs.branch_short_ref }}",
pathPrefix: "${{ needs.set-state.outputs.path_prefix }}"
});