Deploy to GitHub Pages #174
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: Deploy to GitHub Pages | |
on: | |
push: | |
branches: | |
- main # Set a branch to deploy | |
pull_request: | |
schedule: | |
- cron: "11 0 * * 6" # Every Saturday at 00:11, to keep next date updated. | |
workflow_dispatch: | |
jobs: | |
deploy: | |
name: Deploy to Github Pages | |
runs-on: ubuntu-latest | |
env: | |
WWW_DIR: public | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
submodules: true # Fetch Hugo themes (true OR recursive) | |
# fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod | |
- name: Install Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: '0.110.0' | |
extended: true | |
- name: Build w/ Hugo | |
shell: bash | |
run: HUGO_NEXT_LAST_FRIDAY=$(pwsh -Command '(.\next-last-friday.ps1).ToString("o")') hugo --minify | |
- name: Include extra files | |
shell: bash | |
run: cp -r .github/gh-pages/. "$WWW_DIR/" | |
- name: Push to gh-pages | |
# Do not deploy PRs. | |
if: ${{ github.event_name != 'pull_request' }} | |
shell: bash | |
run: | | |
git -C "$WWW_DIR" init -q | |
git -C "$WWW_DIR" remote add origin "$(git remote get-url origin)" | |
git -C "$WWW_DIR" config credential.helper "$(git config credential.helper)" | |
git -C "$WWW_DIR" config 'http.https://github.com/.extraheader' "$(git config 'http.https://github.com/.extraheader')" | |
git -C "$WWW_DIR" config core.autocrlf input | |
git -C "$WWW_DIR" config core.safecrlf false | |
git -C "$WWW_DIR" fetch origin gh-pages:gh-pages || true | |
git -C "$WWW_DIR" symbolic-ref HEAD refs/heads/gh-pages | |
git -C "$WWW_DIR" reset | |
git -C "$WWW_DIR" add -A | |
if git -C "$WWW_DIR" -c 'user.name=github-actions[bot]' -c 'user.email=41898282+github-actions[bot]@users.noreply.github.com' \ | |
commit -m "Build site $(date -I) $(git rev-parse HEAD)"; | |
then | |
git -C "$WWW_DIR" push -u origin gh-pages --quiet | |
else | |
echo 'No changes to commit' | |
fi |