Last active
December 20, 2021 15:53
-
-
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
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: 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The relevant Makefile target looks like this: