Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/update-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
description: 'Node.js version (ex/ `v20.0.0`)'
required: true
type: string
schedule:
- cron: "0 0 * * *"

concurrency:
group: update-redirect-links
Expand Down Expand Up @@ -60,7 +62,7 @@ jobs:
- name: Update Directory Cache
run: node scripts/update-directory-cache.mjs "$VERSION_INPUT" && node --run format
env:
VERSION_INPUT: '${{ inputs.version }}'
VERSION_INPUT: '${{ inputs.version ?? "" }}'
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
S3_ACCESS_KEY_ID: ${{ secrets.CF_ACCESS_KEY_ID }}
S3_ACCESS_KEY_SECRET: ${{ secrets.CF_SECRET_ACCESS_KEY }}
Expand Down
3 changes: 2 additions & 1 deletion scripts/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const STAGING_BUCKET = process.env.STAGING_BUCKET ?? 'dist-staging';

export const RELEASE_DIR = 'nodejs/release/';
export const DOCS_DIR = 'nodejs/docs/';
export const NIGHTLY_RELEASES_DIR = 'nodejs/nightly';

export const NODE_LATEST_FILE_NAME = 'node-latest.tar.gz';

Expand Down Expand Up @@ -57,4 +58,4 @@ export const STATIC_FILE_SYMLINKS_PATH = join(
* Paths in the R2 bucket that we should always be updating whenever a new
* version releases.
*/
export const ALWAYS_UPDATED_PATHS = [RELEASE_DIR, DOCS_DIR];
export const ALWAYS_UPDATED_PATHS = [RELEASE_DIR, DOCS_DIR, NIGHTLY_RELEASES_DIR];
44 changes: 27 additions & 17 deletions scripts/update-directory-cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* Update the most commonly updated paths in the directory cache for a Node.js
* release.
*
* Usage: ./update-directory-cache.mjs <version>
* Usage: ./update-directory-cache.mjs [version]
* Example: ./update-directory-cache.mjs v24.0.0
*
* If no version is provided, this just updates what's in {@link ALWAYS_UPDATED_PATHS}
*/

import { listR2Directory } from '../lib/listR2Directory.mjs';
Expand All @@ -22,16 +24,6 @@ import { createS3Client, listR2DirectoryRecursive } from './utils/r2.mjs';

const VERSION = process.argv[2]?.toLowerCase();

if (!VERSION) {
throw new TypeError('version missing from args');
}

if (!VERSION.startsWith('v')) {
throw new TypeError(
'provided version not in correct format, expected vX.X.X'
);
}

// Ensure all necessary environment variables are set
for (const envVar of [
'CLOUDFLARE_API_TOKEN',
Expand All @@ -51,12 +43,10 @@ const s3Client = createS3Client(

const cfClient = createCloudflareClient();

// List the directory of the new release (and subdirectories)
const directories = await listR2DirectoryRecursive(
s3Client,
PROD_BUCKET,
`${RELEASE_DIR}${VERSION}/`
);
/**
* @type {import('./utils/r2.mjs').DirectoryListMapping}
*/
const directories = new Map();

// Non-recursively list the paths that we always want to update
await Promise.all(
Expand All @@ -77,6 +67,26 @@ await Promise.all(
)
);

if (VERSION !== undefined && VERSION !== '') {
if (!VERSION.startsWith('v')) {
throw new TypeError(
'provided version not in correct format, expected vX.X.X'
);
}

console.log(`Listing version ${VERSION}`);

const versionDirectory = await listR2DirectoryRecursive(
s3Client,
PROD_BUCKET,
`${RELEASE_DIR}${VERSION}/`
);

for (const [k, v] of versionDirectory.entries()) {
directories.set(k, v);
}
}

const latestVersions = await getLatestVersionMapping(
s3Client,
directories.get(RELEASE_DIR),
Expand Down