Workflow file for this run
This file contains 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: Hugo Build to `builds/prod-prod` (deploy to production servers) | |
# run action on a merged PR on "production", or manually | |
on: | |
pull_request: | |
branches: | |
- production | |
types: | |
- closed | |
workflow_dispatch: | |
env: | |
HUGO_GIT_BRANCH: production | |
TZ: America/New_York | |
jobs: | |
# ------------------ | |
# build to prod-prod | |
# ------------------ | |
build: | |
name: Build `production` to `builds/prod-prod` | |
runs-on: ubuntu-22.04 | |
# only run the action if the PR was merged, or it was manually triggered | |
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' | |
# wait for other triggered jobs to finish before running this | |
concurrency: # don't run two of these jobs at the same time | |
group: ${{ github.workflow }}-${{ github.ref_name }} # ref name is branch name, so only one job on a branch will run at a time | |
cancel-in-progress: true # this makes it so that only the most recent job is run | |
# define job's steps | |
steps: | |
# setting line endings to LF to match line endings in source files (which were used to compute resource integrity) | |
- name: set git EOL | |
run: | | |
git config --global core.eol lf | |
git config --global core.autocrlf input | |
# using checkout action | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: production | |
fetch-depth: 0 | |
# get last commit | |
- name: get last commit | |
id: last_commit | |
run: | | |
echo "last_hash=$(git log -1 --format=%h --abbrev=10)" >> $GITHUB_OUTPUT | |
echo "last_msg=\"$(git log -1 --format=%s)\"" >> $GITHUB_OUTPUT | |
# set up node and cache for npm | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22.5.x | |
cache: "npm" | |
# set up cache for node modules | |
- name: Cache node_modules | |
id: cache-nodemodules | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# prune node_modules | |
- name: Prune dependencies | |
run: npm prune | |
# update npm dependencies (if cached) | |
- name: Update dependencies | |
if: steps.cache-nodemodules.outputs.cache-hit == 'true' | |
run: npm update | |
# install npm dependencies (if not cached) | |
- name: Install dependencies | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: npm ci | |
# list dependencies | |
- name: List dependencies | |
run: npm ls | |
- name: List sub-dependencies | |
run: npm ls --all | |
# set up Hugo | |
- name: Set up Hugo | |
uses: peaceiris/actions-hugo@v3 | |
with: | |
hugo-version: "0.122.0" | |
extended: true | |
# build site with Hugo | |
- name: Build site with Hugo | |
run: | | |
export HUGO_GIT_LAST_HASH=${{ steps.last_commit.outputs.last_hash }} | |
export HUGO_GIT_LAST_MSG=${{ steps.last_commit.outputs.last_msg }} | |
hugo --environment prod_prod --cleanDestinationDir --logLevel debug | |
# run pagefind | |
- name: Build search with pagefind | |
run: | | |
cd '${{ github.workspace }}' | |
npx -y pagefind --site docs | |
# commit built index | |
- name: Commit changes to package.json & package-lock.json | |
uses: elstudio/actions-js-build/commit@v4 | |
with: | |
commitMessage: Update index & NPM package list | |
# publish to "builds/prod-prod" branch | |
- name: Publish to "builds/prod-prod" | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
full_commit_message: "Build ${{ steps.last_commit.outputs.last_hash }} (${{ steps.last_commit.outputs.last_msg }})" | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: builds/prod-prod | |
publish_dir: ./docs/ | |
enable_jekyll: false |