From 7b3fb1946295b8b6121c0871ef1e1c2e645cf8b0 Mon Sep 17 00:00:00 2001
From: Caleb Gosiak <caleb@hipcamp.com>
Date: Thu, 30 Sep 2021 19:28:38 -0500
Subject: [PATCH] v0.11.0

---
 dist/restore/index.js    | 16 +++++++++-------
 dist/save/index.js       | 16 +++++++++-------
 package.json             |  2 +-
 src/cache.service.ts     | 10 ++++------
 src/utils/actionUtils.ts |  6 +++++-
 5 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/dist/restore/index.js b/dist/restore/index.js
index 399aa19..fd7f903 100644
--- a/dist/restore/index.js
+++ b/dist/restore/index.js
@@ -2349,7 +2349,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
+exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.formatKey = exports.isGhes = void 0;
 const core = __importStar(__webpack_require__(6470));
 const constants_1 = __webpack_require__(1211);
 function isGhes() {
@@ -2357,9 +2357,13 @@ function isGhes() {
     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
 }
 exports.isGhes = isGhes;
+function formatKey(key) {
+    return key.replace(/[^\w\s]/gi, "-");
+}
+exports.formatKey = formatKey;
 function isExactKeyMatch(key, cacheKey) {
     return !!(cacheKey &&
-        cacheKey.localeCompare(key, undefined, {
+        formatKey(cacheKey).localeCompare(formatKey(key), undefined, {
             sensitivity: "accent"
         }) === 0);
 }
@@ -43281,6 +43285,7 @@ const aws_sdk_1 = __webpack_require__(9350);
 const filesize_1 = __importDefault(__webpack_require__(7283));
 const fs_1 = __importDefault(__webpack_require__(5747));
 const path = __importStar(__webpack_require__(5622));
+const actionUtils_1 = __webpack_require__(443);
 class CacheService {
     constructor(accessKeyId, secretAccessKey, region, bucket) {
         this._client = new aws_sdk_1.S3({
@@ -43295,7 +43300,7 @@ class CacheService {
     restoreCache(paths, primaryKey, restoreKeys) {
         return __awaiter(this, void 0, void 0, function* () {
             restoreKeys = restoreKeys || [];
-            const keys = [primaryKey, ...restoreKeys].map(x => this.formatKey(x));
+            const keys = [primaryKey, ...restoreKeys].map(x => actionUtils_1.formatKey(x));
             core.debug("Resolved Keys:");
             core.debug(JSON.stringify(keys));
             const compressionMethod = yield utils.getCompressionMethod();
@@ -43331,7 +43336,7 @@ class CacheService {
     }
     saveCache(paths, key) {
         return __awaiter(this, void 0, void 0, function* () {
-            const formattedKey = this.formatKey(key);
+            const formattedKey = actionUtils_1.formatKey(key);
             const compressionMethod = yield utils.getCompressionMethod();
             const cachePaths = yield utils.resolvePaths(paths);
             core.debug("Cache Paths:");
@@ -43452,9 +43457,6 @@ class CacheService {
             .replace("/", "-")
             .toLowerCase();
     }
-    formatKey(key) {
-        return key.replace(/[^\w\s]/gi, "-");
-    }
 }
 exports.CacheService = CacheService;
 
diff --git a/dist/save/index.js b/dist/save/index.js
index 3756278..dc4feba 100644
--- a/dist/save/index.js
+++ b/dist/save/index.js
@@ -2349,7 +2349,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
+exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.formatKey = exports.isGhes = void 0;
 const core = __importStar(__webpack_require__(6470));
 const constants_1 = __webpack_require__(1211);
 function isGhes() {
@@ -2357,9 +2357,13 @@ function isGhes() {
     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
 }
 exports.isGhes = isGhes;
+function formatKey(key) {
+    return key.replace(/[^\w\s]/gi, "-");
+}
+exports.formatKey = formatKey;
 function isExactKeyMatch(key, cacheKey) {
     return !!(cacheKey &&
-        cacheKey.localeCompare(key, undefined, {
+        formatKey(cacheKey).localeCompare(formatKey(key), undefined, {
             sensitivity: "accent"
         }) === 0);
 }
@@ -43281,6 +43285,7 @@ const aws_sdk_1 = __webpack_require__(9350);
 const filesize_1 = __importDefault(__webpack_require__(7283));
 const fs_1 = __importDefault(__webpack_require__(5747));
 const path = __importStar(__webpack_require__(5622));
+const actionUtils_1 = __webpack_require__(443);
 class CacheService {
     constructor(accessKeyId, secretAccessKey, region, bucket) {
         this._client = new aws_sdk_1.S3({
@@ -43295,7 +43300,7 @@ class CacheService {
     restoreCache(paths, primaryKey, restoreKeys) {
         return __awaiter(this, void 0, void 0, function* () {
             restoreKeys = restoreKeys || [];
-            const keys = [primaryKey, ...restoreKeys].map(x => this.formatKey(x));
+            const keys = [primaryKey, ...restoreKeys].map(x => actionUtils_1.formatKey(x));
             core.debug("Resolved Keys:");
             core.debug(JSON.stringify(keys));
             const compressionMethod = yield utils.getCompressionMethod();
@@ -43331,7 +43336,7 @@ class CacheService {
     }
     saveCache(paths, key) {
         return __awaiter(this, void 0, void 0, function* () {
-            const formattedKey = this.formatKey(key);
+            const formattedKey = actionUtils_1.formatKey(key);
             const compressionMethod = yield utils.getCompressionMethod();
             const cachePaths = yield utils.resolvePaths(paths);
             core.debug("Cache Paths:");
@@ -43452,9 +43457,6 @@ class CacheService {
             .replace("/", "-")
             .toLowerCase();
     }
-    formatKey(key) {
-        return key.replace(/[^\w\s]/gi, "-");
-    }
 }
 exports.CacheService = CacheService;
 
diff --git a/package.json b/package.json
index a555b02..a4994c3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cache",
-  "version": "0.10.0",
+  "version": "0.11.0",
   "private": true,
   "description": "Cache dependencies and build outputs",
   "main": "dist/restore/index.js",
diff --git a/src/cache.service.ts b/src/cache.service.ts
index a52760c..e2ccfe3 100644
--- a/src/cache.service.ts
+++ b/src/cache.service.ts
@@ -12,6 +12,8 @@ import filesize from "filesize";
 import fs from "fs";
 import * as path from "path";
 
+import { formatKey } from "./utils/actionUtils";
+
 export class CacheService {
     private _client: S3;
     private _bucket: string;
@@ -38,7 +40,7 @@ export class CacheService {
         restoreKeys: string[]
     ): Promise<string | undefined> {
         restoreKeys = restoreKeys || [];
-        const keys = [primaryKey, ...restoreKeys].map(x => this.formatKey(x));
+        const keys = [primaryKey, ...restoreKeys].map(x => formatKey(x));
 
         core.debug("Resolved Keys:");
         core.debug(JSON.stringify(keys));
@@ -85,7 +87,7 @@ export class CacheService {
     }
 
     async saveCache(paths: string[], key: string): Promise<string> {
-        const formattedKey: string = this.formatKey(key);
+        const formattedKey: string = formatKey(key);
         const compressionMethod = await utils.getCompressionMethod();
 
         const cachePaths = await utils.resolvePaths(paths);
@@ -219,8 +221,4 @@ export class CacheService {
             .replace("/", "-")
             .toLowerCase();
     }
-
-    private formatKey(key: string): string {
-        return key.replace(/[^\w\s]/gi, "-");
-    }
 }
diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts
index a4d712d..87df237 100644
--- a/src/utils/actionUtils.ts
+++ b/src/utils/actionUtils.ts
@@ -9,10 +9,14 @@ export function isGhes(): boolean {
     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
 }
 
+export function formatKey(key: string): string {
+    return key.replace(/[^\w\s]/gi, "-");
+}
+
 export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
     return !!(
         cacheKey &&
-        cacheKey.localeCompare(key, undefined, {
+        formatKey(cacheKey).localeCompare(formatKey(key), undefined, {
             sensitivity: "accent"
         }) === 0
     );