From b85ac67c9a993c72637451381492014e96a5da4f Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Thu, 26 Aug 2021 16:56:06 -0600 Subject: [PATCH] Seed the cache key with workflow id in CI This will eliminate cache entries from previous workflow runs, allowing us to test cache functionality in isolation. If the `CACHE_KEY_SEED` environment variable is not set, this will have no impact. --- .github/workflows/prod.yml | 3 +++ src/cache-gradle-user-home.ts | 3 ++- src/cache-project-dot-gradle.ts | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 963130e..235a88c 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -6,6 +6,9 @@ on: push: workflow_dispatch: +env: + CACHE_KEY_SEED: ${{github.workflow}}#${{github.run_number}}- + jobs: basic-build: strategy: diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index b69a5dc..cf21b9f 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -28,8 +28,9 @@ export async function restore(): Promise { return } + const cacheKeySeed = process.env[`CACHE_KEY_SEED`] || '' const runnerOs = process.env[`RUNNER_OS`] || '' - const cacheKeyPrefix = `${runnerOs}-gradle|` + const cacheKeyPrefix = `${cacheKeySeed}${runnerOs}|gradle|` const args = truncateArgs(core.getInput('arguments')) const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|` diff --git a/src/cache-project-dot-gradle.ts b/src/cache-project-dot-gradle.ts index 7aa3197..732d92f 100644 --- a/src/cache-project-dot-gradle.ts +++ b/src/cache-project-dot-gradle.ts @@ -27,8 +27,9 @@ export async function restore(rootDir: string): Promise { return } + const cacheKeySeed = process.env[`CACHE_KEY_SEED`] || '' const runnerOs = process.env[`RUNNER_OS`] || '' - const cacheKeyPrefix = `${runnerOs}-project|` + const cacheKeyPrefix = `${cacheKeySeed}${runnerOs}|project|` const args = truncateArgs(core.getInput('arguments')) const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`