Skip to content

Commit

Permalink
Do not include node version
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jun 22, 2023
1 parent e8f15a5 commit 1db1d57
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 136 deletions.
45 changes: 6 additions & 39 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60578,7 +60578,7 @@ const getCacheDirectories = (packageManagerInfo, cacheDependencyPath) => __await
});
exports.getCacheDirectories = getCacheDirectories;
/**
* Utility function check if the directory is a yarn project configured to manage
* A function to check if the directory is a yarn project configured to manage
* obsolete dependencies in the local cache
* @param directory - a path to the folder
* @return - true if the directory's project is yarn managed
Expand All @@ -60599,18 +60599,11 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false';
});
/**
* Memoization to avoid expensive walking through the directories tree
*/
let hasYarn3ManagedCacheMemoized = null;
/**
* Main function to report either the repo contains at least one Yarn managed directory
* A function to report either the repo contains at least one Yarn managed directory
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the report
* @return - true if there's at least one Yarn managed directory in the repo
*/
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
if (hasYarn3ManagedCacheMemoized !== null)
return hasYarn3ManagedCacheMemoized;
hasYarn3ManagedCacheMemoized = false;
if (packageManagerInfo.name !== 'yarn')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand All @@ -60619,11 +60612,10 @@ const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
hasYarn3ManagedCacheMemoized = true;
break;
return true;
}
}
return hasYarn3ManagedCacheMemoized;
return false;
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() {
Expand Down Expand Up @@ -60706,15 +60698,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.resolveVersionInput = exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
Expand Down Expand Up @@ -60784,26 +60771,6 @@ const unique = () => {
};
};
exports.unique = unique;
function resolveVersionInput() {
let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) {
core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used');
}
if (version) {
return version;
}
if (versionFileInput) {
const versionFilePath = path_1.default.join(process.env.GITHUB_WORKSPACE, versionFileInput);
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
version = parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
core.info(`Resolved ${versionFileInput} as ${version}`);
}
return version;
}
exports.resolveVersionInput = resolveVersionInput;


/***/ }),
Expand Down
71 changes: 28 additions & 43 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71138,14 +71138,12 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const constants_1 = __nccwpck_require__(9042);
const cache_utils_1 = __nccwpck_require__(1678);
const util_1 = __nccwpck_require__(2629);
const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
if (!packageManagerInfo) {
throw new Error(`Caching for '${packageManager}' is not supported`);
}
const platform = process.env.RUNNER_OS;
const nodeVersion = util_1.resolveVersionInput();
const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath);
core.saveState(constants_1.State.CachePaths, cachePaths);
const lockFilePath = cacheDependencyPath
Expand All @@ -71155,7 +71153,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
}
const keyPrefix = `node-cache-${platform}-${packageManager}-v2-${nodeVersion}`;
const keyPrefix = `node-cache-${platform}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
Expand Down Expand Up @@ -71366,7 +71364,7 @@ const getCacheDirectories = (packageManagerInfo, cacheDependencyPath) => __await
});
exports.getCacheDirectories = getCacheDirectories;
/**
* Utility function check if the directory is a yarn project configured to manage
* A function to check if the directory is a yarn project configured to manage
* obsolete dependencies in the local cache
* @param directory - a path to the folder
* @return - true if the directory's project is yarn managed
Expand All @@ -71387,18 +71385,11 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false';
});
/**
* Memoization to avoid expensive walking through the directories tree
*/
let hasYarn3ManagedCacheMemoized = null;
/**
* Main function to report either the repo contains at least one Yarn managed directory
* A function to report either the repo contains at least one Yarn managed directory
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the report
* @return - true if there's at least one Yarn managed directory in the repo
*/
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
if (hasYarn3ManagedCacheMemoized !== null)
return hasYarn3ManagedCacheMemoized;
hasYarn3ManagedCacheMemoized = false;
if (packageManagerInfo.name !== 'yarn')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand All @@ -71407,11 +71398,10 @@ const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
hasYarn3ManagedCacheMemoized = true;
break;
return true;
}
}
return hasYarn3ManagedCacheMemoized;
return false;
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() {
Expand Down Expand Up @@ -72171,6 +72161,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const os_1 = __importDefault(__nccwpck_require__(2037));
const auth = __importStar(__nccwpck_require__(7573));
const path = __importStar(__nccwpck_require__(1017));
Expand All @@ -72185,7 +72176,7 @@ function run() {
// Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc...
//
const version = util_1.resolveVersionInput();
const version = resolveVersionInput();
let arch = core.getInput('architecture');
const cache = core.getInput('cache');
// if architecture supplied but node-version is not
Expand Down Expand Up @@ -72232,6 +72223,25 @@ function run() {
});
}
exports.run = run;
function resolveVersionInput() {
let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) {
core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used');
}
if (version) {
return version;
}
if (versionFileInput) {
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
version = util_1.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
core.info(`Resolved ${versionFileInput} as ${version}`);
}
return version;
}


/***/ }),
Expand Down Expand Up @@ -72269,15 +72279,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.resolveVersionInput = exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
Expand Down Expand Up @@ -72347,26 +72352,6 @@ const unique = () => {
};
};
exports.unique = unique;
function resolveVersionInput() {
let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) {
core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used');
}
if (version) {
return version;
}
if (versionFileInput) {
const versionFilePath = path_1.default.join(process.env.GITHUB_WORKSPACE, versionFileInput);
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
version = parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
core.info(`Resolved ${versionFileInput} as ${version}`);
}
return version;
}
exports.resolveVersionInput = resolveVersionInput;


/***/ }),
Expand Down
4 changes: 1 addition & 3 deletions src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
repoHasYarn3ManagedCache,
PackageManagerInfo
} from './cache-utils';
import {resolveVersionInput} from './util';

export const restoreCache = async (
packageManager: string,
Expand All @@ -22,7 +21,6 @@ export const restoreCache = async (
throw new Error(`Caching for '${packageManager}' is not supported`);
}
const platform = process.env.RUNNER_OS;
const nodeVersion = resolveVersionInput();

const cachePaths = await getCacheDirectories(
packageManagerInfo,
Expand All @@ -40,7 +38,7 @@ export const restoreCache = async (
);
}

const keyPrefix = `node-cache-${platform}-${packageManager}-v2-${nodeVersion}`;
const keyPrefix = `node-cache-${platform}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);

Expand Down
20 changes: 5 additions & 15 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const getCacheDirectories = async (
};

/**
* Utility function check if the directory is a yarn project configured to manage
* A function to check if the directory is a yarn project configured to manage
* obsolete dependencies in the local cache
* @param directory - a path to the folder
* @return - true if the directory's project is yarn managed
Expand All @@ -244,22 +244,13 @@ const isCacheManagedByYarn3 = async (directory: string): Promise<boolean> => {
};

/**
* Memoization to avoid expensive walking through the directories tree
*/
let hasYarn3ManagedCacheMemoized: boolean | null = null;
/**
* Main function to report either the repo contains at least one Yarn managed directory
* A function to report either the repo contains at least one Yarn managed directory
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the report
* @return - true if there's at least one Yarn managed directory in the repo
*/
export const repoHasYarn3ManagedCache = async (
packageManagerInfo: PackageManagerInfo
): Promise<boolean> => {
if (hasYarn3ManagedCacheMemoized !== null)
return hasYarn3ManagedCacheMemoized;

hasYarn3ManagedCacheMemoized = false;

if (packageManagerInfo.name !== 'yarn') return false;

const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand All @@ -270,12 +261,11 @@ export const repoHasYarn3ManagedCache = async (

for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (await isCacheManagedByYarn3(dir)) {
hasYarn3ManagedCacheMemoized = true;
break;
return true;
}
}

return hasYarn3ManagedCacheMemoized;
return false;
};

export function isGhes(): boolean {
Expand Down
37 changes: 36 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as core from '@actions/core';

import fs from 'fs';
import os from 'os';

import * as auth from './authutil';
import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory';
import {printEnvDetailsAndSetOutput, resolveVersionInput} from './util';
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';

export async function run() {
try {
Expand Down Expand Up @@ -75,3 +76,37 @@ export async function run() {
core.setFailed(err.message);
}
}

function resolveVersionInput(): string {
let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file');

if (version && versionFileInput) {
core.warning(
'Both node-version and node-version-file inputs are specified, only node-version will be used'
);
}

if (version) {
return version;
}

if (versionFileInput) {
const versionFilePath = path.join(
process.env.GITHUB_WORKSPACE!,
versionFileInput
);

if (!fs.existsSync(versionFilePath)) {
throw new Error(
`The specified node version file at: ${versionFilePath} does not exist`
);
}

version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));

core.info(`Resolved ${versionFileInput} as ${version}`);
}

return version;
}

0 comments on commit 1db1d57

Please sign in to comment.