build_site #1846
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_site | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- 'assets/**' | |
- '.github/workflows/rubocop.yml' | |
- '.github/workflows/run_plugin_tests.yml' | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- 'assets/**' | |
- 'scripts/**' | |
- '.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: ubuntu-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: 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 Netlify | |
uses: nwtgck/[email protected] | |
with: | |
publish-dir: "_site" | |
production-branch: main | |
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
deploy-message: "Deploy from GitHub Actions" | |
enable-pull-request-comment: true | |
overwrites-pull-request-comment: true | |
netlify-config-path: netlify.toml | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: "da37a488-4df9-4cc2-b267-947179af20bd" | |
timeout-minutes: 1 | |
- 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 |