Skip to content

Commit

Permalink
.github/actions/deploy-to-github-pages: use Cloudflare API directly
Browse files Browse the repository at this point in the history
As pointed out in [1], using the cloudflare-purge-action incurs a ~31
second penalty at the start of the "deploy" action, where time is spent
building a Docker container to run the action.

This is unnecessary, since Cloudflare has a straightforward REST API
that we can use cURL to communicate with directly, without the extra
start-up cost.

Let's do that instead, and move this to run in the
deploy-to-github-pages action, which is run from multiple entry points,
all of which will want to purge the Cloudflare caches upon deployment.

[1]: #1893 (comment)

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr committed Oct 4, 2024
1 parent 040e187 commit 225c7fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .github/actions/deploy-to-github-pages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ runs:
id: deploy
uses: actions/deploy-pages@v4

- name: Purge Cloudflare cache
env:
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
if: env.CLOUDFLARE_TOKEN != ''
run: |
curl "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "purge_everything": true }'
- name: construct `--remap` option for lychee
id: remap
shell: bash
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ jobs:
- name: deploy to GitHub Pages
id: deploy
uses: ./.github/actions/deploy-to-github-pages
- name: Purge Cloudflare cache
env:
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
if: env.CLOUDFLARE_TOKEN != ''
uses: jakejarvis/[email protected]

0 comments on commit 225c7fd

Please sign in to comment.