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
3 changes: 2 additions & 1 deletion build-dependency-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions build-dependency-cache/s3-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions build-dependency-cache/tests/s3-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down