From b90ed1bf68b86d49f61ec16ba46314fe69b27320 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Tue, 25 Jul 2023 19:29:37 +0200 Subject: [PATCH] cache-restore-only --- action.yml | 3 +++ dist/cache-save/index.js | 11 +++++++++-- dist/setup/index.js | 5 +++++ src/cache-save.ts | 6 +++++- src/constants.ts | 4 +++- src/main.ts | 3 +++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 12b47b697..8ef2bb8ff 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: default: true cache-dependency-path: description: 'Used to specify the path to a dependency file - go.sum' + cache-restore-only: + description: Used to specify the cache . Set to true, if you'd like to reuse existing cache but did not update it + default: false architecture: description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.' outputs: diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index c1161a721..95b9fbc18 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -58442,7 +58442,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.run = void 0; +exports.cachePackages = exports.run = void 0; const core = __importStar(__nccwpck_require__(2186)); const cache = __importStar(__nccwpck_require__(7799)); const fs_1 = __importDefault(__nccwpck_require__(7147)); @@ -58457,8 +58457,12 @@ process.on('uncaughtException', e => { }); function run() { return __awaiter(this, void 0, void 0, function* () { + if (core.getState(constants_1.State.CacheRestoreOnly) === constants_1.State.True) { + core.info('"cache-restore-only" set to true, skip caching'); + return; + } try { - yield cachePackages(); + yield exports.cachePackages(); } catch (error) { let message = 'Unknown error!'; @@ -58505,6 +58509,7 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { } core.info(`Cache saved with the key: ${primaryKey}`); }); +exports.cachePackages = cachePackages; function logWarning(message) { const warningPrefix = '[warning]'; core.info(`${warningPrefix}${message}`); @@ -58622,6 +58627,8 @@ var State; (function (State) { State["CachePrimaryKey"] = "CACHE_KEY"; State["CacheMatchedKey"] = "CACHE_RESULT"; + State["CacheRestoreOnly"] = "CACHE_RESTORE_ONLY"; + State["True"] = "true"; })(State = exports.State || (exports.State = {})); var Outputs; (function (Outputs) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 378197f56..d6d19e3f6 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -61292,6 +61292,8 @@ var State; (function (State) { State["CachePrimaryKey"] = "CACHE_KEY"; State["CacheMatchedKey"] = "CACHE_RESULT"; + State["CacheRestoreOnly"] = "CACHE_RESTORE_ONLY"; + State["True"] = "true"; })(State = exports.State || (exports.State = {})); var Outputs; (function (Outputs) { @@ -61690,6 +61692,7 @@ const cache_utils_1 = __nccwpck_require__(1678); const child_process_1 = __importDefault(__nccwpck_require__(2081)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); +const constants_1 = __nccwpck_require__(9042); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -61727,6 +61730,8 @@ function run() { core.debug(`add bin ${added}`); const goPath = yield io.which('go'); const goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); + const cacheRestoreOnly = core.getBooleanInput('cache-dependency-path'); + core.saveState(constants_1.State.CacheRestoreOnly, cacheRestoreOnly ? constants_1.State.True : ''); if (cache && cache_utils_1.isCacheFeatureAvailable()) { const packageManager = 'default'; const cacheDependencyPath = core.getInput('cache-dependency-path'); diff --git a/src/cache-save.ts b/src/cache-save.ts index 584d0a697..95513bfe0 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -13,6 +13,10 @@ process.on('uncaughtException', e => { }); export async function run() { + if (core.getState(State.CacheRestoreOnly) === State.True) { + core.info('"cache-restore-only" set to true, skip caching'); + return; + } try { await cachePackages(); } catch (error) { @@ -27,7 +31,7 @@ export async function run() { } } -const cachePackages = async () => { +export const cachePackages = async () => { const cacheInput = core.getBooleanInput('cache'); if (!cacheInput) { return; diff --git a/src/constants.ts b/src/constants.ts index b43d18c00..e0c19ce43 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,8 @@ export enum State { CachePrimaryKey = 'CACHE_KEY', - CacheMatchedKey = 'CACHE_RESULT' + CacheMatchedKey = 'CACHE_RESULT', + CacheRestoreOnly = 'CACHE_RESTORE_ONLY', + True = 'true' } export enum Outputs { diff --git a/src/main.ts b/src/main.ts index d3fb857df..cebac1769 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,7 @@ import {isCacheFeatureAvailable} from './cache-utils'; import cp from 'child_process'; import fs from 'fs'; import os from 'os'; +import {State} from './constants'; export async function run() { try { @@ -64,6 +65,8 @@ export async function run() { const goPath = await io.which('go'); const goVersion = (cp.execSync(`${goPath} version`) || '').toString(); + const cacheRestoreOnly = core.getBooleanInput('cache-dependency-path'); + core.saveState(State.CacheRestoreOnly, cacheRestoreOnly ? State.True : ''); if (cache && isCacheFeatureAvailable()) { const packageManager = 'default'; const cacheDependencyPath = core.getInput('cache-dependency-path');