1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 10:38:26 -04:00
jarv.is/.github/workflows/gh-pages.yml

58 lines
2.3 KiB
YAML

name: GitHub Pages
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
lfs: false
# Pull from custom Hugo Extended image with opinionated changes:
# https://github.com/jakejarvis/hugo-custom/packages
# https://github.com/jakejarvis/hugo-custom/blob/master/Dockerfile
# Can't use native `uses: docker://` syntax for GitHub Package Registry...
- name: Build Hugo
run: |
echo ${{ secrets.GITHUB_ACCESS_TOKEN }} | docker login docker.pkg.github.com -u $GITHUB_ACTOR --password-stdin
docker run -v $GITHUB_WORKSPACE:/src docker.pkg.github.com/jakejarvis/hugo-custom/hugo-custom:latest --gc --cleanDestinationDir
docker logout docker.pkg.github.com
# Copy built site to a directory where we have permissions, and
# add a CNAME file for a custom domain (jarv.is).
- name: Prepare for GitHub Pages
run: |
cp -r $GITHUB_WORKSPACE/public $HOME/gh-pages
echo "jarv.is" > $HOME/gh-pages/CNAME
# Put a bow on top of Hugo's automatic image processing by using
# pngquant and jpegoptim to optimize/compress images in posts,
# just a little lossily (is that a word?)
- name: Optimize processed images
run: |
sudo apt-get install -y --no-install-recommends pngquant jpegoptim
cd $HOME/gh-pages/notes
find . -iname "*.jp*" -print0 | xargs -0 jpegoptim --max=90 --strip-all
find . -iname "*.png" -print0 | xargs -0 pngquant --quality=60-75 --speed 1 --ext=.png --force --verbose
# Initialize a sub-repository in the new gh-pages directory and
# add jakejarvis/jakejarvis.github.io as a remote.
# Using native git commands for speed and simplicity, and because
# this setup is a weird edge case not worth making an action for.
- name: Deploy to jakejarvis.github.io
run: |
cd $HOME/gh-pages
git init
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git remote add origin https://${{ secrets.GITHUB_ACCESS_TOKEN }}@github.com/jakejarvis/jakejarvis.github.io.git
git add -A
git commit -m "GitHub Pages deploy from $GITHUB_REPOSITORY@$GITHUB_SHA"
git push --force origin master