Skip to content

Commit 3652ebd

Browse files
committed
.github/actions/deploy-to-github-pages: use Cloudflare API directly
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 <me@ttaylorr.com>
1 parent 040e187 commit 3652ebd

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

.github/actions/deploy-to-github-pages/action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ inputs:
1414
description: The GitHub token used to create an authenticated client
1515
default: ${{ github.token }}
1616
required: true
17+
cloudflare-token:
18+
description: The Cloudflare API token used to purge Cloudflare caches.
19+
required: false
20+
cloudflare-zone:
21+
description: The Cloudflare zone to purge.
22+
required: false
1723
outputs:
1824
url:
1925
description: The URL to which the site was deployed
@@ -87,6 +93,17 @@ runs:
8793
id: deploy
8894
uses: actions/deploy-pages@v4
8995

96+
- name: Purge Cloudflare cache
97+
env:
98+
CLOUDFLARE_ZONE: ${{ inputs.cloudflare-zone }}
99+
CLOUDFLARE_TOKEN: ${{ inputs.cloudflare-token }}
100+
if: env.CLOUDFLARE_TOKEN != ''
101+
run: |
102+
curl "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \
103+
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
104+
-H "Content-Type: application/json" \
105+
-d '{ "purge_everything": true }'
106+
90107
- name: construct `--remap` option for lychee
91108
id: remap
92109
shell: bash

.github/workflows/deploy.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
- name: deploy to GitHub Pages
2222
id: deploy
2323
uses: ./.github/actions/deploy-to-github-pages
24-
- name: Purge Cloudflare cache
25-
env:
26-
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}
27-
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
28-
if: env.CLOUDFLARE_TOKEN != ''
29-
uses: jakejarvis/cloudflare-purge-action@v0.3.0
24+
with:
25+
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
26+
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}

.github/workflows/update-book.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ jobs:
133133
- name: deploy to GitHub Pages
134134
id: deploy
135135
uses: ./.github/actions/deploy-to-github-pages
136+
with:
137+
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
138+
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}

.github/workflows/update-download-data.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ jobs:
7070
if: steps.commit.outputs.result != ''
7171
id: deploy
7272
uses: ./.github/actions/deploy-to-github-pages
73+
with:
74+
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
75+
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}

.github/workflows/update-git-version-and-manual-pages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ jobs:
103103
if: steps.commit.outputs.result != '' || steps.manual-pages.outputs.result != ''
104104
id: deploy
105105
uses: ./.github/actions/deploy-to-github-pages
106+
with:
107+
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
108+
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}

.github/workflows/update-translated-manual-pages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ jobs:
8989
if: steps.manual-pages.outputs.result != ''
9090
id: deploy
9191
uses: ./.github/actions/deploy-to-github-pages
92+
with:
93+
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
94+
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}

0 commit comments

Comments
 (0)