diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index 0ffc363fa..8de9d3ce1 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -103,6 +103,32 @@ jobs: run: npm run check-ci -- --stream shell: bash + # Downloading and extracting MongoDB server binaries is slow on Windows, + # so we cache them between runs. + # + # Cache directories are named after the requested version range ('8.x', + # '*'), not the version it resolved to, so a cache entry pins tests to + # whichever release was current when it was written. Including the ISO + # week in the key rotates that weekly, keeping us at most a week behind. + # Bump `v1` to force a refresh. + - name: Compute cache week + if: ${{ runner.os == 'Windows' }} + id: cache-week + run: echo "week=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT" + shell: bash + + - name: Cache MongoDB binaries + if: ${{ runner.os == 'Windows' }} + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ runner.temp }}/mongodb-binaries + key: v1-mongodb-binaries-${{ runner.os }}-${{ steps.cache-week.outputs.week }} + + - name: Set MongoDB binaries download dir + if: ${{ runner.os == 'Windows' }} + run: echo "MONGODB_RUNNER_DOWNLOAD_DIR=${RUNNER_TEMP}/mongodb-binaries" >> $GITHUB_ENV + shell: bash + - name: Run Tests run: | scopes=$(node .github/scripts/compute-test-group.mjs "${{ matrix.group }}" "${TOTAL_GROUPS}") diff --git a/packages/mongodb-runner/src/mongocluster.ts b/packages/mongodb-runner/src/mongocluster.ts index 6f8d24a8b..0715ccdb0 100644 --- a/packages/mongodb-runner/src/mongocluster.ts +++ b/packages/mongodb-runner/src/mongocluster.ts @@ -80,6 +80,8 @@ export interface RSMemberOptions { export interface CommonOptions { /** * Directory where server binaries will be downloaded and stored. + * Defaults to the `MONGODB_RUNNER_DOWNLOAD_DIR` environment variable if set, + * otherwise to `tmpDir`. */ downloadDir?: string; /** @@ -380,7 +382,9 @@ export class MongoCluster extends EventEmitter { cluster.defaultConnectionOptions = { ...options.internalClientOptions }; if (!options.binDir) { options.binDir = await this.downloadMongoDb( - options.downloadDir ?? options.tmpDir, + options.downloadDir ?? + process.env.MONGODB_RUNNER_DOWNLOAD_DIR ?? + options.tmpDir, options.version, options.downloadOptions, );