Skip to content

Commit 37918a8

Browse files
committed
ci: refresh cache
1 parent a7f72c5 commit 37918a8

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

.github/workflows/production.yml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
build:
3636
runs-on: ubuntu-latest
3737
name: Build website
38+
permissions:
39+
contents: read
40+
actions: write
3841
steps:
3942
- name: Maximize build space
4043
run: |
@@ -84,8 +87,8 @@ jobs:
8487
fi
8588
8689
- name: Restore gatsby cache
87-
uses: actions/cache@v3
8890
id: gatsby-cache
91+
uses: actions/cache/restore@v4
8992
with:
9093
path: |
9194
.cache
@@ -106,6 +109,7 @@ jobs:
106109
107110
- name: Build website
108111
if: ${{ !inputs.fallback || (steps.gatsby-cache.outputs.cache-hit != 'true') }}
112+
id: build-website
109113
env:
110114
CI: true
111115
GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
@@ -117,6 +121,74 @@ jobs:
117121
run: |
118122
yarn build
119123
124+
- name: Delete gatsby cache
125+
if: ${{ steps.build-website.outcome == 'success' }}
126+
uses: actions/github-script@v7
127+
env:
128+
CACHE_KEY: ${{ runner.os }}-gatsby-cache-docs-staging-${{ steps.calc-cache-key.outputs.key }}
129+
CACHE_REF: ${{ github.ref }}
130+
with:
131+
script: |
132+
const owner = context.repo.owner;
133+
const repo = context.repo.repo;
134+
const key = process.env.CACHE_KEY;
135+
const ref = process.env.CACHE_REF;
136+
137+
core.info(`Deleting actions cache for key="${key}" ref="${ref}"`);
138+
139+
const caches = [];
140+
let page = 1;
141+
while (true) {
142+
const resp = await github.request("GET /repos/{owner}/{repo}/actions/caches", {
143+
owner,
144+
repo,
145+
key,
146+
ref,
147+
per_page: 100,
148+
page,
149+
});
150+
151+
const pageCaches = resp?.data?.actions_caches ?? [];
152+
caches.push(...pageCaches);
153+
154+
if (pageCaches.length < 100) break;
155+
page += 1;
156+
}
157+
158+
const targets = caches.filter((cache) => cache.key === key && cache.ref === ref);
159+
if (targets.length === 0) {
160+
core.info("No matching caches found, skip delete.");
161+
return;
162+
}
163+
164+
for (const cache of targets) {
165+
core.info(`Deleting cache id=${cache.id} key=${cache.key} ref=${cache.ref}`);
166+
try {
167+
await github.request("DELETE /repos/{owner}/{repo}/actions/caches/{cache_id}", {
168+
owner,
169+
repo,
170+
cache_id: cache.id,
171+
});
172+
} catch (error) {
173+
if (error.status === 404) {
174+
core.info(`Cache id=${cache.id} already deleted.`);
175+
continue;
176+
}
177+
throw error;
178+
}
179+
}
180+
181+
core.info(`Deleted ${targets.length} cache(s).`);
182+
183+
- name: Save gatsby cache
184+
if: ${{ steps.build-website.outcome == 'success' }}
185+
uses: actions/cache/save@v4
186+
with:
187+
path: |
188+
.cache
189+
public
190+
key: ${{ runner.os }}-gatsby-cache-docs-staging-${{ steps.calc-cache-key.outputs.key }}
191+
120192
- name: Check output
121193
id: check-output
122194
run: |

docs

Submodule docs updated 25732 files

0 commit comments

Comments
 (0)