Sophie Koonin deploys her site to NeoCities using GitHub Actions (go read that; it is a really good write-up of how things work). Knowing that GitHub Actions has support for custom caching, I decided to do the same but with Cloudflare Pages instead of NeoCities.
I created a GitHub Actions workflow that caches the node_modules
and .cache
directories, as well as the img
directory where the photos are stored. This reduced the build time to just over 2 minutes, a 7x improvement!
This is the complete workflow as I write this post. I may have updated it since then, so please refer to the source code for the latest version.
name: Build and Deploy
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
schedule:
- cron: "17 8 * * 6"
jobs:
build:
name: "Build and Deploy"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 20.10.0
cache: "yarn"
- run: yarn install --frozen-lockfile
- uses: actions/cache/restore@v4
id: cache
with:
path: |
.cache
img
key: 11ty-${{ runner.os }}-${{ github.run_id }}
restore-keys: |
11ty-${{ runner.os }}
${{ runner.os }}-11ty
- name: Build 11ty site
run: yarn build
env:
TINA_CLIENT_ID: ${{ secrets.TINA_CLIENT_ID }}
TINA_SEARCH_TOKEN: ${{ secrets.TINA_SEARCH_TOKEN }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
ENABLE_ANALYTICS: ${{ github.ref == 'refs/heads/master' }}
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: 8dfec48c278d5a97c93de33e072261bd
projectName: jonas-brusman-se
directory: dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}
wranglerVersion: "3"
- uses: actions/cache/save@v4
with:
path: |
.cache
img
key: 11ty-${{ runner.os }}-${{ github.run_id }}
The workflow does the following:
github.run_id
to create a unique key for the cache so it can be updated with new content/images on every build.branch: ${{ github.head_ref || github.ref_name }}
to make it work with pull requests.Published at | |
---|---|
Tags | programming cloudflare github netlify eleventy meta |
Related posts | |
Have some thoughts? | Reply by email |
Reactions |