Skip to content

Commit

Permalink
feat(CI): Revalidate vercel data cache on areweturboyet after uploadi…
Browse files Browse the repository at this point in the history
…ng data to KV store
  • Loading branch information
bgw committed Mar 3, 2025
1 parent b52716b commit 3ee5136
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
34 changes: 33 additions & 1 deletion .github/actions/upload-turboyet-data/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/actions/upload-turboyet-data/dist/index.js.map

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion .github/actions/upload-turboyet-data/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ async function collectResults(manifestFile) {
}
}

async function collectAndUpload(kv, { jsonPrefix, kvPrefix }) {
async function collectAndUpload(
kv,
{ jsonPrefix, kvPrefix, deploymentDomain }
) {
const developmentResult = await collectResults(
`test/${jsonPrefix}dev-tests-manifest.json`
)
Expand Down Expand Up @@ -175,6 +178,34 @@ async function collectAndUpload(kv, { jsonPrefix, kvPrefix }) {

await kv.set(`${kvPrefix}examples-data`, developmentExamplesResult.data)
console.log('SUCCESSFULLY SAVED EXAMPLES')

if (deploymentDomain != null) {
// Upstash does not provide strong consistency, so just wait a couple
// seconds before invalidating the cache in case of replication lag.
//
// https://upstash.com/docs/redis/features/consistency
await new Promise((resolve) => setTimeout(resolve, 2000))
try {
const response = await fetch(
`https://${deploymentDomain}/api/revalidate`,
{
method: 'POST',
headers: {
'X-Auth-Token': process.env.TURBOYET_TOKEN,
'Content-Type': 'application/json',
},
}
)
const responseJson = await response.json()
if (!responseJson.revalidated) {
throw new Error(responseJson.error)
}
console.log('SUCCESSFULLY REVALIDATED VERCEL DATA CACHE')
} catch (error) {
// non-fatal: the cache will eventually expire anyways
console.error('FAILED TO REVALIDATE VERCEL DATA CACHE', error)
}
}
}

async function main() {
Expand All @@ -187,6 +218,7 @@ async function main() {
await collectAndUpload(kv, {
jsonPrefix: 'turbopack-',
kvPrefix: '',
deploymentDomain: 'areweturboyet.com',
})
console.log('### UPLOADING RSPACK DATA')
await collectAndUpload(kv, {
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/upload-tests-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ name: Upload bundler test manifests to areweturboyet.com
on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
inputs:
version:
description: Next.js version, sha, branch to test
type: string
default: 'canary'
workflow_dispatch: {}
push:
branches:
- canary
Expand Down Expand Up @@ -45,4 +40,5 @@ jobs:
env:
TURBOYET_KV_REST_API_URL: ${{ secrets.TURBOYET_KV_REST_API_URL }}
TURBOYET_KV_REST_API_TOKEN: ${{ secrets.TURBOYET_KV_REST_API_TOKEN }}
TURBOYET_TOKEN: ${{ secrets.TURBOYET_TOKEN }}
uses: ./.github/actions/upload-turboyet-data

0 comments on commit 3ee5136

Please sign in to comment.