From ae5523354c2e0f83f4027ed792aa583d1aa87a75 Mon Sep 17 00:00:00 2001 From: Eliot Partridge Date: Sun, 20 Oct 2024 20:14:40 -0400 Subject: [PATCH 1/2] Use case-insensitive key comparsion for cache keys --- bundler.js | 2 +- common.js | 12 ++++++++++++ dist/index.js | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bundler.js b/bundler.js index 711871bae..533bfaca7 100644 --- a/bundler.js +++ b/bundler.js @@ -206,7 +206,7 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer await exec.exec('bundle', ['install', '--jobs', '4']) // @actions/cache only allows to save for non-existing keys - if (cachedKey !== key) { + if (!common.isExactKeyMatch(key, cachedKey)) { if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems await exec.exec('bundle', ['clean']) } diff --git a/common.js b/common.js index 02e57b237..0b122dcc7 100644 --- a/common.js +++ b/common.js @@ -412,3 +412,15 @@ export async function setupJavaHome(rubyPrefix) { } }) } + +// Determines if two keys are an exact match for the purposes of cache matching +// Specifically, this is a case-insensitive match that ignores accents +// From actions/cache@v3 src/utils/actionUtils.ts (MIT) +export function isExactKeyMatch(key, cacheKey) { + return !!( + cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: 'accent' + }) === 0 + ); +} diff --git a/dist/index.js b/dist/index.js index 4df23eced..4b8e4ef06 100644 --- a/dist/index.js +++ b/dist/index.js @@ -220,7 +220,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b await exec.exec('bundle', ['install', '--jobs', '4']) // @actions/cache only allows to save for non-existing keys - if (cachedKey !== key) { + if (!common.isExactKeyMatch(key, cachedKey)) { if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems await exec.exec('bundle', ['clean']) } @@ -299,6 +299,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ isBundler1Default: () => (/* binding */ isBundler1Default), /* harmony export */ isBundler2Default: () => (/* binding */ isBundler2Default), /* harmony export */ isBundler2dot2Default: () => (/* binding */ isBundler2dot2Default), +/* harmony export */ isExactKeyMatch: () => (/* binding */ isExactKeyMatch), /* harmony export */ isHeadVersion: () => (/* binding */ isHeadVersion), /* harmony export */ isSelfHostedRunner: () => (/* binding */ isSelfHostedRunner), /* harmony export */ isStableVersion: () => (/* binding */ isStableVersion), @@ -730,6 +731,18 @@ async function setupJavaHome(rubyPrefix) { }) } +// Determines if two keys are an exact match for the purposes of cache matching +// Specifically, this is a case-insensitive match that ignores accents +// From actions/cache@v3 src/utils/actionUtils.ts (MIT) +function isExactKeyMatch(key, cacheKey) { + return !!( + cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: 'accent' + }) === 0 + ); +} + /***/ }), From dbd90321943bc8ae80e454611a4cf6993af4032b Mon Sep 17 00:00:00 2001 From: Eliot Partridge Date: Mon, 21 Oct 2024 11:52:42 -0400 Subject: [PATCH 2/2] Rename to `isExactCacheKeyMatch` --- bundler.js | 2 +- common.js | 2 +- dist/index.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bundler.js b/bundler.js index 533bfaca7..816c56bf8 100644 --- a/bundler.js +++ b/bundler.js @@ -206,7 +206,7 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer await exec.exec('bundle', ['install', '--jobs', '4']) // @actions/cache only allows to save for non-existing keys - if (!common.isExactKeyMatch(key, cachedKey)) { + if (!common.isExactCacheKeyMatch(key, cachedKey)) { if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems await exec.exec('bundle', ['clean']) } diff --git a/common.js b/common.js index 0b122dcc7..72e2a9ceb 100644 --- a/common.js +++ b/common.js @@ -416,7 +416,7 @@ export async function setupJavaHome(rubyPrefix) { // Determines if two keys are an exact match for the purposes of cache matching // Specifically, this is a case-insensitive match that ignores accents // From actions/cache@v3 src/utils/actionUtils.ts (MIT) -export function isExactKeyMatch(key, cacheKey) { +export function isExactCacheKeyMatch(key, cacheKey) { return !!( cacheKey && cacheKey.localeCompare(key, undefined, { diff --git a/dist/index.js b/dist/index.js index 4b8e4ef06..95decd0c1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -220,7 +220,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b await exec.exec('bundle', ['install', '--jobs', '4']) // @actions/cache only allows to save for non-existing keys - if (!common.isExactKeyMatch(key, cachedKey)) { + if (!common.isExactCacheKeyMatch(key, cachedKey)) { if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems await exec.exec('bundle', ['clean']) } @@ -299,7 +299,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ isBundler1Default: () => (/* binding */ isBundler1Default), /* harmony export */ isBundler2Default: () => (/* binding */ isBundler2Default), /* harmony export */ isBundler2dot2Default: () => (/* binding */ isBundler2dot2Default), -/* harmony export */ isExactKeyMatch: () => (/* binding */ isExactKeyMatch), +/* harmony export */ isExactCacheKeyMatch: () => (/* binding */ isExactCacheKeyMatch), /* harmony export */ isHeadVersion: () => (/* binding */ isHeadVersion), /* harmony export */ isSelfHostedRunner: () => (/* binding */ isSelfHostedRunner), /* harmony export */ isStableVersion: () => (/* binding */ isStableVersion), @@ -734,7 +734,7 @@ async function setupJavaHome(rubyPrefix) { // Determines if two keys are an exact match for the purposes of cache matching // Specifically, this is a case-insensitive match that ignores accents // From actions/cache@v3 src/utils/actionUtils.ts (MIT) -function isExactKeyMatch(key, cacheKey) { +function isExactCacheKeyMatch(key, cacheKey) { return !!( cacheKey && cacheKey.localeCompare(key, undefined, {