diff --git a/.github/workflows/update-links.yml b/.github/workflows/update-links.yml index 4627bcdf..31128916 100644 --- a/.github/workflows/update-links.yml +++ b/.github/workflows/update-links.yml @@ -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 @@ -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 }} diff --git a/scripts/constants.mjs b/scripts/constants.mjs index 7368997f..21f21a3d 100644 --- a/scripts/constants.mjs +++ b/scripts/constants.mjs @@ -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'; @@ -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]; diff --git a/scripts/update-directory-cache.mjs b/scripts/update-directory-cache.mjs index 96612817..b5f861a7 100644 --- a/scripts/update-directory-cache.mjs +++ b/scripts/update-directory-cache.mjs @@ -4,8 +4,10 @@ * Update the most commonly updated paths in the directory cache for a Node.js * release. * - * Usage: ./update-directory-cache.mjs + * 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'; @@ -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', @@ -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( @@ -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),