From 8b0dfa3b5d39fbcb07cd4ff1e5a3bc6f2ad45900 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Thu, 17 Aug 2023 18:16:38 +0200 Subject: [PATCH 1/4] Set default `cache` input to false for self-hosted runners --- dist/cache-save/index.js | 51 +++++++++++++++++++++++++++++++++++++--- dist/setup/index.js | 40 +++++++++++++++++++++++++++---- src/cache-save.ts | 6 ++--- src/installer.ts | 8 ++----- src/main.ts | 3 ++- src/utils.ts | 13 ++++++++++ 6 files changed, 102 insertions(+), 19 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 19f39d251..e28601740 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -58495,6 +58495,7 @@ const cache = __importStar(__nccwpck_require__(7799)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const constants_1 = __nccwpck_require__(9042); const cache_utils_1 = __nccwpck_require__(1678); +const utils_1 = __nccwpck_require__(1314); // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to // throw an uncaught exception. Instead of failing this action, just warn. @@ -58521,10 +58522,8 @@ function run() { } exports.run = run; const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { - const cacheInput = core.getBooleanInput('cache'); - if (!cacheInput) { + if (!utils_1.getCacheInput()) return; - } const packageManager = 'default'; const state = core.getState(constants_1.State.CacheMatchedKey); const primaryKey = core.getState(constants_1.State.CachePrimaryKey); @@ -58693,6 +58692,52 @@ exports.supportedPackageManagers = { }; +/***/ }), + +/***/ 1314: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getCacheInput = exports.isSelfHosted = exports.StableReleaseAlias = void 0; +const core = __importStar(__nccwpck_require__(2186)); +var StableReleaseAlias; +(function (StableReleaseAlias) { + StableReleaseAlias["Stable"] = "stable"; + StableReleaseAlias["OldStable"] = "oldstable"; +})(StableReleaseAlias = exports.StableReleaseAlias || (exports.StableReleaseAlias = {})); +const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && + process.env['AGENT_ISSELFHOSTED'] === '1'; +exports.isSelfHosted = isSelfHosted; +const getCacheInput = () => { + // for self-hosted environment turn off cache by default + if (exports.isSelfHosted() && core.getInput('cache') === '') + return false; + return core.getBooleanInput('cache'); +}; +exports.getCacheInput = getCacheInput; + + /***/ }), /***/ 2877: diff --git a/dist/setup/index.js b/dist/setup/index.js index b0a3f4e6b..9b5533d5f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -61495,8 +61495,7 @@ function cacheWindowsDir(extPath, tool, version, arch) { if (os_1.default.platform() !== 'win32') return false; // make sure the action runs in the hosted environment - if (process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && - process.env['AGENT_ISSELFHOSTED'] === '1') + if (utils_1.isSelfHosted()) return false; const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE']; if (!defaultToolCacheRoot) @@ -61777,6 +61776,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 utils_1 = __nccwpck_require__(1314); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -61785,7 +61785,7 @@ function run() { // If not supplied then problem matchers will still be setup. Useful for self-hosted. // const versionSpec = resolveVersionInput(); - const cache = core.getBooleanInput('cache'); + const cache = utils_1.getCacheInput(); core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); if (!arch) { @@ -61966,17 +61966,47 @@ exports.getArch = getArch; /***/ }), /***/ 1314: -/***/ ((__unused_webpack_module, exports) => { +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.StableReleaseAlias = void 0; +exports.getCacheInput = exports.isSelfHosted = exports.StableReleaseAlias = void 0; +const core = __importStar(__nccwpck_require__(2186)); var StableReleaseAlias; (function (StableReleaseAlias) { StableReleaseAlias["Stable"] = "stable"; StableReleaseAlias["OldStable"] = "oldstable"; })(StableReleaseAlias = exports.StableReleaseAlias || (exports.StableReleaseAlias = {})); +const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && + process.env['AGENT_ISSELFHOSTED'] === '1'; +exports.isSelfHosted = isSelfHosted; +const getCacheInput = () => { + // for self-hosted environment turn off cache by default + if (exports.isSelfHosted() && core.getInput('cache') === '') + return false; + return core.getBooleanInput('cache'); +}; +exports.getCacheInput = getCacheInput; /***/ }), diff --git a/src/cache-save.ts b/src/cache-save.ts index 584d0a697..76ea87af5 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -3,6 +3,7 @@ import * as cache from '@actions/cache'; import fs from 'fs'; import {State} from './constants'; import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; +import {getCacheInput} from './utils'; // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to @@ -28,10 +29,7 @@ export async function run() { } const cachePackages = async () => { - const cacheInput = core.getBooleanInput('cache'); - if (!cacheInput) { - return; - } + if (!getCacheInput()) return; const packageManager = 'default'; diff --git a/src/installer.ts b/src/installer.ts index be90e101a..72b3bd53d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -6,7 +6,7 @@ import * as httpm from '@actions/http-client'; import * as sys from './system'; import fs from 'fs'; import os from 'os'; -import {StableReleaseAlias} from './utils'; +import {isSelfHosted, StableReleaseAlias} from './utils'; type InstallationType = 'dist' | 'manifest'; @@ -175,11 +175,7 @@ async function cacheWindowsDir( if (os.platform() !== 'win32') return false; // make sure the action runs in the hosted environment - if ( - process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && - process.env['AGENT_ISSELFHOSTED'] === '1' - ) - return false; + if (isSelfHosted()) return false; const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE']; if (!defaultToolCacheRoot) return false; diff --git a/src/main.ts b/src/main.ts index d3fb857df..d03c8f7b6 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 {getCacheInput} from './utils'; export async function run() { try { @@ -17,7 +18,7 @@ export async function run() { // const versionSpec = resolveVersionInput(); - const cache = core.getBooleanInput('cache'); + const cache = getCacheInput(); core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); diff --git a/src/utils.ts b/src/utils.ts index 79d03bcad..ddd3f746a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,17 @@ +import * as core from '@actions/core'; + export enum StableReleaseAlias { Stable = 'stable', OldStable = 'oldstable' } + +export const isSelfHosted = (): boolean => + process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && + process.env['AGENT_ISSELFHOSTED'] === '1'; + +export const getCacheInput = (): boolean => { + // for self-hosted environment turn off cache by default + if (isSelfHosted() && core.getInput('cache') === '') return false; + + return core.getBooleanInput('cache'); +}; From 6f72b31c9419b7d7fe3fc7294e6ed6fd5e198c1a Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Thu, 17 Aug 2023 18:30:41 +0200 Subject: [PATCH 2/4] Update docs --- docs/adrs/0000-caching-dependencies.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/adrs/0000-caching-dependencies.md b/docs/adrs/0000-caching-dependencies.md index dc8d85837..f7aeab2bc 100644 --- a/docs/adrs/0000-caching-dependencies.md +++ b/docs/adrs/0000-caching-dependencies.md @@ -17,8 +17,8 @@ We don't pursue the goal to provide wide customization of caching in scope of `a # Decision - Add `cache` input parameter to `actions/setup-go`. For now, input will accept the following values: - - `true` - enable caching for go dependencies - - `false`- disable caching for go dependencies. This value will be set as default value + - `true` - enable caching for go dependencies. This value will be set as default value for hosted runners. + - `false`- disable caching for go dependencies. This value will be set as default value for self-hosted runners. - Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major releases - Action will try to search a go.sum files in the repository and throw error in the scenario that it was not found - The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules) recommends) From deaf43692dc17489000e882d62134ed1417e9f1e Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 18 Aug 2023 09:01:34 +0200 Subject: [PATCH 3/4] Add unit tests --- __tests__/cache-utils.test.ts | 74 +++++++++++++++++++++++++++++++++++ dist/cache-save/index.js | 46 ++++++---------------- dist/setup/index.js | 46 ++++++---------------- src/cache-save.ts | 7 +++- src/cache-utils.ts | 7 ++++ src/main.ts | 3 +- src/utils.ts | 9 +---- 7 files changed, 114 insertions(+), 78 deletions(-) diff --git a/__tests__/cache-utils.test.ts b/__tests__/cache-utils.test.ts index 695c561cc..58e7ac626 100644 --- a/__tests__/cache-utils.test.ts +++ b/__tests__/cache-utils.test.ts @@ -3,6 +3,7 @@ import * as cache from '@actions/cache'; import * as core from '@actions/core'; import * as cacheUtils from '../src/cache-utils'; import {PackageManagerInfo} from '../src/package-managers'; +import * as utils from '../src/utils'; describe('getCommandOutput', () => { //Arrange @@ -209,3 +210,76 @@ describe('isCacheFeatureAvailable', () => { expect(warningSpy).toHaveBeenCalledWith(warningMessage); }); }); + +describe('Detect environment', () => { + it('"RUNNER_ENVIRONMENT" = "github-hosted" should be hosted environment', () => { + delete process.env['AGENT_ISSELFHOSTED']; + process.env['RUNNER_ENVIRONMENT'] = 'github-hosted'; + expect(utils.isSelfHosted()).toBeFalsy(); + }); + + it('"RUNNER_ENVIRONMENT" = "hosted" should be self-hosted environment', () => { + delete process.env['AGENT_ISSELFHOSTED']; + process.env['RUNNER_ENVIRONMENT'] = 'hosted'; + expect(utils.isSelfHosted()).toBeTruthy(); + }); + + it('"AGENT_ISSELFHOSTED" = "0" should be hosted environment', () => { + process.env['AGENT_ISSELFHOSTED'] = '0'; + delete process.env['RUNNER_ENVIRONMENT']; + expect(utils.isSelfHosted()).toBeFalsy(); + }); + + it('"AGENT_ISSELFHOSTED" = "0" should be self-hosted environment', () => { + process.env['AGENT_ISSELFHOSTED'] = '1'; + delete process.env['RUNNER_ENVIRONMENT']; + expect(utils.isSelfHosted()).toBeTruthy(); + }); + + it('unset "RUNNER_ENVIRONMENT" and "AGENT_ISSELFHOSTED" should be self-hosted environment', () => { + delete process.env['AGENT_ISSELFHOSTED']; + delete process.env['RUNNER_ENVIRONMENT']; + expect(utils.isSelfHosted()).toBeTruthy(); + }); +}); +describe('Default cache values', () => { + const inputSpy = jest.spyOn(utils, 'isSelfHosted'); + + beforeEach(() => { + delete process.env['INPUT_CACHE']; + }); + + it('default cache should be false in self-hosted environment', () => { + inputSpy.mockReturnValueOnce(true); + expect(cacheUtils.getCacheInput()).toBeFalsy(); + }); + + it('cache should be false if set to false in self-hosted environment', () => { + inputSpy.mockReturnValueOnce(true); + process.env['INPUT_CACHE'] = 'false'; + expect(cacheUtils.getCacheInput()).toBeFalsy(); + }); + + it('cache should be tue if set to true in self-hosted environment', () => { + inputSpy.mockReturnValueOnce(true); + process.env['INPUT_CACHE'] = 'true'; + expect(cacheUtils.getCacheInput()).toBeTruthy(); + }); + + it('default cache should be handled by action.yml default in hosted environment', () => { + inputSpy.mockReturnValueOnce(false); + expect(() => cacheUtils.getCacheInput()).toThrow(); + }); + + it('cache should be false if set to false in hosted environment', () => { + inputSpy.mockReturnValueOnce(false); + process.env['INPUT_CACHE'] = 'true'; + expect(cacheUtils.getCacheInput()).toBeTruthy(); + }); + + it('cache should be tue if set to true in hosted environment', () => { + inputSpy.mockReturnValueOnce(false); + process.env['INPUT_CACHE'] = 'false'; + expect(cacheUtils.getCacheInput()).toBeFalsy(); + }); +}); diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index e28601740..78584ea60 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -58495,7 +58495,6 @@ const cache = __importStar(__nccwpck_require__(7799)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const constants_1 = __nccwpck_require__(9042); const cache_utils_1 = __nccwpck_require__(1678); -const utils_1 = __nccwpck_require__(1314); // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to // throw an uncaught exception. Instead of failing this action, just warn. @@ -58522,7 +58521,7 @@ function run() { } exports.run = run; const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { - if (!utils_1.getCacheInput()) + if (!cache_utils_1.getCacheInput()) return; const packageManager = 'default'; const state = core.getState(constants_1.State.CacheMatchedKey); @@ -58594,11 +58593,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; +exports.getCacheInput = exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const package_managers_1 = __nccwpck_require__(6663); +const utils_1 = __nccwpck_require__(1314); const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); if (exitCode) { @@ -58653,6 +58653,13 @@ function isCacheFeatureAvailable() { return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; +const getCacheInput = () => { + // for self-hosted environment turn off cache by default + if (utils_1.isSelfHosted() && core.getInput('cache') === '') + return false; + return core.getBooleanInput('cache'); +}; +exports.getCacheInput = getCacheInput; /***/ }), @@ -58695,47 +58702,20 @@ exports.supportedPackageManagers = { /***/ }), /***/ 1314: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +/***/ ((__unused_webpack_module, exports) => { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getCacheInput = exports.isSelfHosted = exports.StableReleaseAlias = void 0; -const core = __importStar(__nccwpck_require__(2186)); +exports.isSelfHosted = exports.StableReleaseAlias = void 0; var StableReleaseAlias; (function (StableReleaseAlias) { StableReleaseAlias["Stable"] = "stable"; StableReleaseAlias["OldStable"] = "oldstable"; })(StableReleaseAlias = exports.StableReleaseAlias || (exports.StableReleaseAlias = {})); const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && - process.env['AGENT_ISSELFHOSTED'] === '1'; + process.env['AGENT_ISSELFHOSTED'] !== '0'; exports.isSelfHosted = isSelfHosted; -const getCacheInput = () => { - // for self-hosted environment turn off cache by default - if (exports.isSelfHosted() && core.getInput('cache') === '') - return false; - return core.getBooleanInput('cache'); -}; -exports.getCacheInput = getCacheInput; /***/ }), diff --git a/dist/setup/index.js b/dist/setup/index.js index 9b5533d5f..3e993d28f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -61265,11 +61265,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; +exports.getCacheInput = exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const package_managers_1 = __nccwpck_require__(6663); +const utils_1 = __nccwpck_require__(1314); const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); if (exitCode) { @@ -61324,6 +61325,13 @@ function isCacheFeatureAvailable() { return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; +const getCacheInput = () => { + // for self-hosted environment turn off cache by default + if (utils_1.isSelfHosted() && core.getInput('cache') === '') + return false; + return core.getBooleanInput('cache'); +}; +exports.getCacheInput = getCacheInput; /***/ }), @@ -61776,7 +61784,6 @@ 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 utils_1 = __nccwpck_require__(1314); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -61785,7 +61792,7 @@ function run() { // If not supplied then problem matchers will still be setup. Useful for self-hosted. // const versionSpec = resolveVersionInput(); - const cache = utils_1.getCacheInput(); + const cache = cache_utils_1.getCacheInput(); core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); if (!arch) { @@ -61966,47 +61973,20 @@ exports.getArch = getArch; /***/ }), /***/ 1314: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +/***/ ((__unused_webpack_module, exports) => { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getCacheInput = exports.isSelfHosted = exports.StableReleaseAlias = void 0; -const core = __importStar(__nccwpck_require__(2186)); +exports.isSelfHosted = exports.StableReleaseAlias = void 0; var StableReleaseAlias; (function (StableReleaseAlias) { StableReleaseAlias["Stable"] = "stable"; StableReleaseAlias["OldStable"] = "oldstable"; })(StableReleaseAlias = exports.StableReleaseAlias || (exports.StableReleaseAlias = {})); const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && - process.env['AGENT_ISSELFHOSTED'] === '1'; + process.env['AGENT_ISSELFHOSTED'] !== '0'; exports.isSelfHosted = isSelfHosted; -const getCacheInput = () => { - // for self-hosted environment turn off cache by default - if (exports.isSelfHosted() && core.getInput('cache') === '') - return false; - return core.getBooleanInput('cache'); -}; -exports.getCacheInput = getCacheInput; /***/ }), diff --git a/src/cache-save.ts b/src/cache-save.ts index 76ea87af5..a9d913938 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -2,8 +2,11 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; import fs from 'fs'; import {State} from './constants'; -import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; -import {getCacheInput} from './utils'; +import { + getCacheDirectoryPath, + getPackageManagerInfo, + getCacheInput +} from './cache-utils'; // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 545c97af1..460e1f5e6 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -2,6 +2,7 @@ import * as cache from '@actions/cache'; import * as core from '@actions/core'; import * as exec from '@actions/exec'; import {supportedPackageManagers, PackageManagerInfo} from './package-managers'; +import {isSelfHosted} from './utils'; export const getCommandOutput = async (toolCommand: string) => { let {stdout, stderr, exitCode} = await exec.getExecOutput( @@ -83,3 +84,9 @@ export function isCacheFeatureAvailable(): boolean { ); return false; } +export const getCacheInput = (): boolean => { + // for self-hosted environment turn off cache by default + if (isSelfHosted() && core.getInput('cache') === '') return false; + + return core.getBooleanInput('cache'); +}; diff --git a/src/main.ts b/src/main.ts index d03c8f7b6..f655d874e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,11 +4,10 @@ import * as installer from './installer'; import * as semver from 'semver'; import path from 'path'; import {restoreCache} from './cache-restore'; -import {isCacheFeatureAvailable} from './cache-utils'; +import {isCacheFeatureAvailable, getCacheInput} from './cache-utils'; import cp from 'child_process'; import fs from 'fs'; import os from 'os'; -import {getCacheInput} from './utils'; export async function run() { try { diff --git a/src/utils.ts b/src/utils.ts index ddd3f746a..f8e45977d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,11 +7,4 @@ export enum StableReleaseAlias { export const isSelfHosted = (): boolean => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && - process.env['AGENT_ISSELFHOSTED'] === '1'; - -export const getCacheInput = (): boolean => { - // for self-hosted environment turn off cache by default - if (isSelfHosted() && core.getInput('cache') === '') return false; - - return core.getBooleanInput('cache'); -}; + process.env['AGENT_ISSELFHOSTED'] !== '0'; From efdf435b25c9fbb4cb211d39f56d71b65e123d42 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 18 Aug 2023 14:20:24 +0200 Subject: [PATCH 4/4] Fix lint warning --- src/utils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index f8e45977d..457ff139d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,3 @@ -import * as core from '@actions/core'; - export enum StableReleaseAlias { Stable = 'stable', OldStable = 'oldstable'