From 7e56f009beed93dc89d372d9e8a6d057c64b001a Mon Sep 17 00:00:00 2001 From: Zxilly <31370133+Zxilly@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:19:06 +0000 Subject: [PATCH 1/2] fix: add arch to cache key --- dist/setup/index.js | 12 ++++++------ src/cache-distributions/pip-cache.ts | 8 ++++---- src/cache-distributions/pipenv-cache.ts | 2 +- src/cache-distributions/poetry-cache.ts | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d558c611f..ce8529792 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -90192,12 +90192,12 @@ class PipCache extends cache_distributor_1.default { let restoreKey = ''; if (utils_1.IS_LINUX) { const osInfo = yield (0, utils_1.getLinuxInfo)(); - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; } else { - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}`; } return { primaryKey, @@ -90283,7 +90283,7 @@ class PipenvCache extends cache_distributor_1.default { computeKeys() { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${process.arch}-${this.pythonVersion}-${this.packageManager}-${hash}`; const restoreKey = undefined; return { primaryKey, @@ -90396,7 +90396,7 @@ class PoetryCache extends cache_distributor_1.default { return __awaiter(this, void 0, void 0, function* () { const hash = yield glob.hashFiles(this.patterns); // "v2" is here to invalidate old caches of this cache distributor, which were created broken: - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`; + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`; const restoreKey = undefined; return { primaryKey, diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 2ec3f9b01..d64ae931d 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -67,11 +67,11 @@ class PipCache extends CacheDistributor { if (IS_LINUX) { const osInfo = await getLinuxInfo(); - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`; } else { - primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; - restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; + primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}`; } return { diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index fd1994a68..376e4293d 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -32,7 +32,7 @@ class PipenvCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${process.arch}-${this.pythonVersion}-${this.packageManager}-${hash}`; const restoreKey = undefined; return { primaryKey, diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index c31fb05d4..cd3a189b2 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -47,7 +47,7 @@ class PoetryCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.patterns); // "v2" is here to invalidate old caches of this cache distributor, which were created broken: - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`; + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`; const restoreKey = undefined; return { primaryKey, From ae59c5af9656f2efa3191e798da170f40e8832dc Mon Sep 17 00:00:00 2001 From: Zxilly <31370133+Zxilly@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:27:14 +0000 Subject: [PATCH 2/2] test: update tests accordingly --- __tests__/cache-restore.test.ts | 6 +++--- src/cache-distributions/pipenv-cache.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index a1a8d8d23..d84c22969 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -186,15 +186,15 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py if (process.platform === 'linux' && packageManager === 'pip') { expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-20.04-Ubuntu-python-${pythonVersion}-${packageManager}-${fileHash}` + `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-20.04-Ubuntu-python-${pythonVersion}-${packageManager}-${fileHash}` ); } else if (packageManager === 'poetry') { expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-v2-${fileHash}` + `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-python-${pythonVersion}-${packageManager}-v2-${fileHash}` ); } else { expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` + `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-python-${pythonVersion}-${packageManager}-${fileHash}` ); } }, diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index 376e4293d..8ddcbed86 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -32,7 +32,7 @@ class PipenvCache extends CacheDistributor { protected async computeKeys() { const hash = await glob.hashFiles(this.patterns); - const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${process.arch}-${this.pythonVersion}-${this.packageManager}-${hash}`; + const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; const restoreKey = undefined; return { primaryKey,