Skip to content

build_site

build_site #2566

Workflow file for this run

name: build_site
on:
push:
branches:
- main
paths-ignore:
- 'assets/**'
- 'caddy/**'
- 'dns/**'
- 'scripts/**'
- 'Caddyfile'
- '.github/workflows/caddy_fmt.yml'
- '.github/workflows/check_dns.yml'
- '.github/workflows/rubocop.yml'
- '.github/workflows/run_plugin_tests.yml'
pull_request:
branches:
- main
paths-ignore:
- 'assets/**'
- 'caddy/**'
- 'dns/**'
- 'scripts/**'
- 'Caddyfile'
- '.github/workflows/caddy_fmt.yml'
- '.github/workflows/check_dns.yml'
- '.github/workflows/rubocop.yml'
- '.github/workflows/run_plugin_tests.yml'
# This daily rebuild is to avoid GitHub Actions purging the site cache,
# because regenerating all the image thumbnails would be a PITA:
#
# GitHub will remove any cache entries that have not been
# accessed in over 7 days.
#
# See https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
schedule:
- cron: "30 7 * * *"
jobs:
build:
name: Build the website
runs-on: macos-latest
steps:
- name: "Check out the repo"
uses: actions/checkout@v4
- name: "Set up Ruby"
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
cache-version: 1
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- run: pip install -r requirements.txt
- name: "Cache site output"
uses: "actions/cache@v4"
with:
path: _site
key: "site-${{ github.sha }}"
restore-keys: "site-"
- name: "Cache the .jekyll-cache folder"
uses: "actions/cache@v4"
with:
path: src/.jekyll-cache
key: "jekyll-cache-${{ github.sha }}"
restore-keys: "jekyll-cache-"
- name: "Set the JEKYLL_ENV variable"
run: |
if [[ "$GITHUB_REF" == "refs/heads/main" ]]
then
echo "JEKYLL_ENV=production" >> "$GITHUB_ENV"
else
echo "JEKYLL_ENV=development" >> "$GITHUB_ENV"
fi
- name: "Build the site"
run: |
rm -rf _site/c
bundle exec jekyll build --drafts
- name: "Run linting"
run: bundle exec ruby scripts/linter.rb
- name: "Publish drafts"
if: github.ref == 'refs/heads/main'
run: |
if [[ -d "src/_drafts" ]]
then
touch ~/.gitconfig
git config user.name "GitHub Actions on behalf of Alex Chan"
git config user.email "[email protected]"
git config --global --add safe.directory /home/runner/work/alexwlchan.net/alexwlchan.net
bundle exec ruby scripts/publish_drafts.rb
# Note: although there are no more drafts, we build with the
# flag to avoid Jekyll invalidating its cache
bundle exec jekyll build --drafts
else
echo "There is no _drafts folder, so nothing to publish!"
fi
- name: Deploy to Linode
if: github.ref == 'refs/heads/main'
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
# Get the SSH host keys for my web server
mkdir -p ~/.ssh
ssh-keyscan -H "alexwlchan.net" >> ~/.ssh/known_hosts
# Save the deploy key to a file, so it can be used by
# the SSH process
echo "$DEPLOY_KEY" > id_rsa
chmod 600 id_rsa
# Run the rsync command to upload the _site folder to
# my web server
rsync \
--rsh="ssh -i id_rsa -o IdentityAgent=none -o HostKeyAlgorithms=ssh-ed25519" \
--compress \
--archive \
--recursive \
--delete \
--exclude="" --include="" --filter="" \
"_site/" \
"[email protected]:repos/alexwlchan.net/_site/"
# Clean up the SSH key
rm id_rsa
- name: "Run the website tests"
run: ruby tests/run_all_tests.rb
- name: "Push any commits to GitHub"
if: github.ref == 'refs/heads/main'
run: |
if [[ $(git log -1 --pretty=format:'%an') == "GitHub Actions on behalf of Alex Chan" ]]
then
git push --verbose origin main
fi