From 917ab90a0cd7b53b2f5d6914c34f8a37dac0c1b4 Mon Sep 17 00:00:00 2001 From: Sami Dalouche Date: Tue, 24 Nov 2026 16:47:13 -0500 Subject: [PATCH] fix(build-dependency-cache): unset an empty region the restore ran without (SC-88184) v1.2.1 has the save take back the region its restore ran with, after configure-aws-credentials' post step sets AWS_REGION and AWS_DEFAULT_REGION to "". It didn't cover a job that sets no region before the cache step and configures credentials after it, as narrative-connectors' global-dependency-graph does: the restore ran with the region unset, which the aws CLI resolves itself (it restored 5.47 GiB), so there was nothing to keep, and the save still got "" and failed with "Invalid endpoint: https://s3..amazonaws.com". - s3-cache.js: the save sees the region as the restore did. Each region variable that's now empty is set back to the restore's value, or unset when the restore had none. - tests/s3-cache.test.js: a save unsets a region that was unset when the restore ran. - README.md says so. With the region unset and the credentials empty, `aws s3api head-object` goes on to look for credentials, as it does with the region set, instead of failing on the endpoint. Co-Authored-By: Claude Opus 5.5 --- build-dependency-cache/README.md | 3 ++- build-dependency-cache/s3-cache.js | 15 +++++++++------ build-dependency-cache/tests/s3-cache.test.js | 8 ++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/build-dependency-cache/README.md b/build-dependency-cache/README.md index 749c55c..41833df 100644 --- a/build-dependency-cache/README.md +++ b/build-dependency-cache/README.md @@ -93,7 +93,8 @@ every workflow would need a second step, placed last, to save. Their scripts onl The save then runs after the post steps of any action placed below the cache step. `configure-aws-credentials` sets `AWS_REGION` and `AWS_DEFAULT_REGION` to empty strings in its post step, and the aws CLI takes an empty region as the -region, so the restore keeps the region it ran with in the step's state and the save takes it back. The credentials +region, so the restore keeps the region it ran with in the step's state, and the save takes it back, or unsets the +variables when the restore ran without a region (a job that configures credentials only after the cache step). The credentials that post step blanks don't matter: the CLI skips them and uses the runner's instance role, as the restore did. `setup-mise` has to be composite to call `jdx/mise-action`, and saves right after the install instead: mise's folder is diff --git a/build-dependency-cache/s3-cache.js b/build-dependency-cache/s3-cache.js index c24b3ae..f058910 100644 --- a/build-dependency-cache/s3-cache.js +++ b/build-dependency-cache/s3-cache.js @@ -46,13 +46,16 @@ function rememberRegion(env, append, log) { } } -// env, with each region variable that's now empty set back to the value the restore ran with. +// env, with each region variable that's now empty as the restore saw it: set back to the value it had then, or +// unset when it had none. A job that configures AWS credentials only after the cache step restores with no region, +// which the CLI resolves itself; the cleanup then turns that into "", which it can't. function withRestoredRegion(env) { - const restored = REGION_VARIABLES.filter((name) => !env[name] && env[`STATE_${name}`]).map((name) => [ - name, - env[`STATE_${name}`], - ]); - return { ...env, ...Object.fromEntries(restored) }; + const restored = { ...env }; + for (const name of REGION_VARIABLES.filter((name) => !env[name])) { + if (env[`STATE_${name}`]) restored[name] = env[`STATE_${name}`]; + else delete restored[name]; + } + return restored; } // Runs s3_cache.py and returns the step's exit status. scope is the folder that keeps the job's archives apart: an diff --git a/build-dependency-cache/tests/s3-cache.test.js b/build-dependency-cache/tests/s3-cache.test.js index 15b76c2..cd09632 100644 --- a/build-dependency-cache/tests/s3-cache.test.js +++ b/build-dependency-cache/tests/s3-cache.test.js @@ -119,6 +119,14 @@ test("a save gets back the region configure-aws-credentials blanked", () => { assert.equal(calls[0].env.AWS_DEFAULT_REGION, "us-east-1"); }); +test("a save unsets a region that was unset when the restore ran", () => { + const { calls, spawn } = fakeSpawn({ status: 0 }); + const env = { ...MAIN, INPUT_SAVE: "true", AWS_REGION: "", AWS_DEFAULT_REGION: "" }; + saveIfAsked("sbt", "", { env, spawn }); + assert.equal("AWS_REGION" in calls[0].env, false); + assert.equal("AWS_DEFAULT_REGION" in calls[0].env, false); +}); + test("a save keeps a region that's still set", () => { const { calls, spawn } = fakeSpawn({ status: 0 }); const env = { ...MAIN, INPUT_SAVE: "true", AWS_REGION: "eu-west-1", STATE_AWS_REGION: "us-east-1" };