Skip to content

Instantly share code, notes, and snippets.

@tastapod
Last active December 20, 2021 15:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tastapod/c2eaf34408b6586631347f0411c84339 to your computer and use it in GitHub Desktop.
Save tastapod/c2eaf34408b6586631347f0411c84339 to your computer and use it in GitHub Desktop.
GitHub Action to build and push Hugo website to a separate GitHub Pages repo
name: Release website
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build-website:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v2
with:
lfs: true
- name: Check out target
uses: actions/checkout@v2
with:
repository: ${{ secrets.WEBSITE_REPOSITORY }}
ref: ${{ secrets.WEBSITE_RELEASE_BRANCH }}
token: ${{ secrets.WEBSITE_TOKEN }}
path: ${{ secrets.WEBSITE_DIR }}
lfs: false
- name: Setup Go environment
uses: actions/setup-go@v2
- name: Build website
run: make website
- name: Commit changes
env:
REMOTE: https://${{ secrets.WEBSITE_ACTOR }}:${{ secrets.WEBSITE_TOKEN }}@github.com/${{ secrets.WEBSITE_REPOSITORY }}.git
run: |
cd ${{ secrets.WEBSITE_DIR }}
git config user.name ${{ secrets.WEBSITE_GIT_USER_NAME }}
git config user.email ${{ secrets.WEBSITE_GIT_USER_EMAIL }}
git add --all
if git commit -m "built from GitHub Action"; then
git remote add website "${{ env.REMOTE }}"
git push website ${{ secrets.WEBSITE_RELEASE_BRANCH }}
else
echo "Nothing has changed -- not releasing"
fi
@tastapod
Copy link
Author

The relevant Makefile target looks like this:

hugo := ./tools/bin/$(shell uname -s)/hugo
publish_site_dir := $(publish_repo_dir)/docs

website:
	$(hugo) --destination $(publish_site_dir) --minify --cleanDestinationDir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment