Build and Deploy Quarto Site #53
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: Build and Deploy Quarto Site | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
reduce-images: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Check for large image files | |
id: large-img-check | |
run: | | |
img_path=$(du -ah --threshold=1M | awk '/.(JPE?G|jpe?g|PNG|png|HEIC|heic)$/ {print $2}') | |
echo "$img_path" | |
if [[ -n "$img_path" ]]; then | |
echo "big_image=true" >> $GITHUB_OUTPUT | |
echo "img_path=$(echo $img_path)" >> $GITHUB_OUTPUT | |
fi | |
- name: Install ImageMagick | |
if: steps.large-img-check.outputs.big_image == 'true' | |
run: | | |
cd .. | |
wget https://imagemagick.org/archive/binaries/magick -o magick | |
chmod +x magick | |
- name: Shrink images | |
if: steps.large-img-check.outputs.big_image == 'true' | |
env: | |
img_path: ${{ steps.large-img-check.outputs.img_path }} | |
run: | | |
for image in $img_path; do | |
mogrify -resize 800 -quality 75 "$image" | |
done | |
# Body width in Quarto documents is 800 px by default | |
# https://quarto.org/docs/output-formats/page-layout.html#html-page-layout | |
# ImageMagick mogrify docs: https://imagemagick.org/script/mogrify.php | |
- name: Push changes | |
if: steps.large-img-check.outputs.big_image == 'true' | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add --all | |
git commit --allow-empty -m "[auto] Reduce image file size" | |
git push origin HEAD:main | |
build-deploy: | |
needs: reduce-images | |
runs-on: ubuntu-latest | |
container: eco4cast/rocker-neon4cast:latest | |
steps: | |
- run: git config --global --add safe.directory /__w/efi-ci-workshop-2024/efi-ci-workshop-2024 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-depth: 0 | |
set-safe-directory: '*' | |
- name: Set up Quarto | |
uses: quarto-dev/quarto-actions/setup@v2 | |
with: | |
version: 1.4.146 | |
- name: Render | |
run: | | |
quarto render | |
- name: Publish | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git checkout gh-pages | |
cp -r docs/* . | |
git add . | |
git commit -a -m "update pages" || echo "nothing to commit" | |
git push https://${GITHUB_PAT}:${GITHUB_PAT}@github.com/${GITHUB_REPOSITORY} | |