Skip to content

Commit

Permalink
cache-restore-only
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jul 26, 2023
1 parent db8764c commit 0f07568
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions dist/cache-save/index.js
Expand Up @@ -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));
Expand All @@ -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!';
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -58622,6 +58627,9 @@ var State;
(function (State) {
State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT";
State["CacheRestoreOnly"] = "CACHE_RESTORE_ONLY";
State["True"] = "true";
State["False"] = "false";
})(State = exports.State || (exports.State = {}));
var Outputs;
(function (Outputs) {
Expand Down
6 changes: 6 additions & 0 deletions dist/setup/index.js
Expand Up @@ -61292,6 +61292,9 @@ var State;
(function (State) {
State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT";
State["CacheRestoreOnly"] = "CACHE_RESTORE_ONLY";
State["True"] = "true";
State["False"] = "false";
})(State = exports.State || (exports.State = {}));
var Outputs;
(function (Outputs) {
Expand Down Expand Up @@ -61690,6 +61693,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 {
Expand Down Expand Up @@ -61727,6 +61731,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-restore-only');
core.saveState(constants_1.State.CacheRestoreOnly, cacheRestoreOnly ? constants_1.State.True : constants_1.State.False);
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand Down
6 changes: 5 additions & 1 deletion src/cache-save.ts
Expand Up @@ -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) {
Expand All @@ -27,7 +31,7 @@ export async function run() {
}
}

const cachePackages = async () => {
export const cachePackages = async () => {
const cacheInput = core.getBooleanInput('cache');
if (!cacheInput) {
return;
Expand Down
5 changes: 4 additions & 1 deletion src/constants.ts
@@ -1,6 +1,9 @@
export enum State {
CachePrimaryKey = 'CACHE_KEY',
CacheMatchedKey = 'CACHE_RESULT'
CacheMatchedKey = 'CACHE_RESULT',
CacheRestoreOnly = 'CACHE_RESTORE_ONLY',
True = 'true',
False = 'false'
}

export enum Outputs {
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -64,6 +65,11 @@ export async function run() {
const goPath = await io.which('go');
const goVersion = (cp.execSync(`${goPath} version`) || '').toString();

const cacheRestoreOnly = core.getBooleanInput('cache-restore-only');
core.saveState(
State.CacheRestoreOnly,
cacheRestoreOnly ? State.True : State.False
);
if (cache && isCacheFeatureAvailable()) {
const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand Down

0 comments on commit 0f07568

Please sign in to comment.