Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/update-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
description: 'Node.js version (ex/ `v20.0.0`)'
required: false
type: string
purge-cache:
description: 'Purge all elements in the KV cache?'
type: boolean
required: false
default: false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to verify this exists


concurrency:
group: update-redirect-links
Expand Down Expand Up @@ -59,7 +64,7 @@ jobs:
run: npm ci && npm update nodejs-latest-linker --save

- name: Update Directory Cache
run: node scripts/handle-mainline-release.mjs && node --run format
run: node scripts/handle-mainline-release.mjs ${{ inputs.purge-cache ?? '--purge' }} && node --run format
env:
VERSION_INPUT: "${{ inputs.version || '' }}"
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
Expand Down
87 changes: 0 additions & 87 deletions scripts/build-directory-cache.mjs

This file was deleted.

25 changes: 23 additions & 2 deletions scripts/handle-mainline-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Updates the cached directory listings for paths that have symlinks for the
* mainline release bucket.
*
* Usage: ./handle-mainline-release.mjs
* Usage: ./handle-mainline-release.mjs [--purge]
* --purge: Delete all elements in the cache before writing the new keys.
*
* If no version is provided, this just updates what's in {@link ALWAYS_UPDATED_PATHS}
*/
Expand All @@ -18,7 +19,12 @@ import {
} from './constants.mjs';
import { addSymlinksToDirectoryCache } from './utils/addSymlinksToDirectoryCache.mjs';
import { getLatestVersionMapping } from './utils/getLatestVersionMapping.mjs';
import { createCloudflareClient, writeKeysToKv } from './utils/kv.mjs';
import {
createCloudflareClient,
deleteKvNamespaceKeys,
listKvNamespace,
writeKeysToKv,
} from './utils/kv.mjs';
import { createS3Client, listR2DirectoryRecursive } from './utils/r2.mjs';

// Ensure all necessary environment variables are set
Expand Down Expand Up @@ -72,6 +78,21 @@ const latestVersions = await getLatestVersionMapping(

await addSymlinksToDirectoryCache(s3Client, directories, latestVersions);

// Purge directory cache if wanted
if (process.argv[2] === '--purge') {
const cachedDirectoryKeys = await listKvNamespace(
cfClient,
DIRECTORY_CACHE_NAMESPACE_ID
);
console.log(`Purging ${cachedDirectoryKeys.size} keys`);

await deleteKvNamespaceKeys(
cfClient,
DIRECTORY_CACHE_NAMESPACE_ID,
Array.from(cachedDirectoryKeys)
);
}

// Update keys in the directory cache. These intentionally do not have an
// expiration set since they were made with info that the worker doesn't have
// when deployed.
Expand Down
Loading