Skip to content

Commit

Permalink
add type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-shibanov committed Nov 29, 2022
1 parent ece959c commit b7bdf8d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 58 deletions.
13 changes: 8 additions & 5 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60313,7 +60313,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand Down Expand Up @@ -60418,7 +60418,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand All @@ -60437,7 +60437,7 @@ 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);
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
if (exitCode) {
stderr = !stderr.trim()
Expand All @@ -60447,21 +60447,24 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu
}
return stdout.trim();
});
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
exports.getCommandOutput = getCommandOutput;
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
if (!package_managers_1.supportedPackageManagers[packageManager]) {
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
}
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
const emptyPaths = pathList.filter(item => !item);
if (emptyPaths.length) {
throw new Error(`Could not get cache folder paths.`);
}
return pathList;
});
exports.getCacheDirectoryPath = getCacheDirectoryPath;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
Expand Down
44 changes: 28 additions & 16 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63007,7 +63007,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand All @@ -63032,7 +63032,7 @@ 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);
exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
const platform = process.env.RUNNER_OS;
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
Expand All @@ -63056,6 +63056,7 @@ exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __a
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
core.info(`Cache restored from key: ${cacheKey}`);
});
exports.restoreCache = restoreCache;
const findDependencyFile = (packageManager) => {
let dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE;
Expand Down Expand Up @@ -63090,7 +63091,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand All @@ -63109,7 +63110,7 @@ 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);
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
if (exitCode) {
stderr = !stderr.trim()
Expand All @@ -63119,21 +63120,24 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu
}
return stdout.trim();
});
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
exports.getCommandOutput = getCommandOutput;
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
if (!package_managers_1.supportedPackageManagers[packageManager]) {
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
}
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
const emptyPaths = pathList.filter(item => !item);
if (emptyPaths.length) {
throw new Error(`Could not get cache folder paths.`);
}
return pathList;
});
exports.getCacheDirectoryPath = getCacheDirectoryPath;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
Expand Down Expand Up @@ -63196,7 +63200,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand All @@ -63223,11 +63227,13 @@ const sys = __importStar(__nccwpck_require__(4300));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const os_1 = __importDefault(__nccwpck_require__(2037));
const utils_1 = __nccwpck_require__(1314);
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), manifest) {
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
return __awaiter(this, void 0, void 0, function* () {
let manifest;
let osPlat = os_1.default.platform();
if (checkLatest) {
core.info('Attempting to resolve the latest version from the manifest...');
manifest = yield getManifest(auth);
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch, manifest);
if (resolvedVersion) {
versionSpec = resolvedVersion;
Expand All @@ -63239,6 +63245,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), manif
}
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) {
manifest !== null && manifest !== void 0 ? manifest : (manifest = yield getManifest(auth));
versionSpec = yield resolveStableVersionInput(versionSpec, auth, arch, manifest);
}
// check cache
Expand Down Expand Up @@ -63394,6 +63401,10 @@ function findMatch(versionSpec, arch = os_1.default.arch()) {
if (!candidates) {
throw new Error(`golang download url did not return results`);
}
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) {
versionSpec = yield resolveStableVersionInput(versionSpec, undefined, arch, candidates);
}
let goFile;
for (let i = 0; i < candidates.length; i++) {
let candidate = candidates[i];
Expand Down Expand Up @@ -63470,22 +63481,24 @@ function resolveStableVersionInput(versionSpec, auth, arch = os_1.default.arch()
return __awaiter(this, void 0, void 0, function* () {
if (!manifest) {
core.debug('No manifest cached');
manifest = yield getManifest(auth);
manifest = (yield getManifest(auth));
}
const releases = manifest.map(release => release.version);
const releases = manifest
.filter(release => !!release.files.find(file => file.arch === arch))
.map(release => release.version);
if (versionSpec === utils_1.StableReleaseAlias.Stable) {
core.info(`stable version resolved as ${releases[0]}`);
return releases[0];
}
else {
const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`);
const uniqueVersions = Array.from(new Set(versions));
const oldstableVersion = yield getInfoFromManifest(uniqueVersions[1], true, auth, arch, manifest);
core.info(`oldstable version resolved as ${oldstableVersion === null || oldstableVersion === void 0 ? void 0 : oldstableVersion.resolvedVersion}`);
const oldstableVersion = releases.find(item => item.startsWith(uniqueVersions[1]));
core.info(`oldstable version resolved as ${oldstableVersion}`);
if (!oldstableVersion) {
return versionSpec;
}
return oldstableVersion.resolvedVersion;
return oldstableVersion;
}
});
}
Expand Down Expand Up @@ -63514,7 +63527,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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;
};
Expand Down Expand Up @@ -63559,9 +63572,8 @@ function run() {
if (versionSpec) {
let token = core.getInput('token');
let auth = !token ? undefined : `token ${token}`;
const manifest = yield installer.getManifest(auth);
const checkLatest = core.getBooleanInput('check-latest');
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch, manifest);
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch);
const installDirVersion = path_1.default.basename(path_1.default.dirname(installDir));
core.addPath(path_1.default.join(installDir, 'bin'));
core.info('Added go to the path');
Expand Down
33 changes: 18 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"jest": "^27.2.5",
"jest-circus": "^27.2.5",
"nock": "^10.0.6",
"prettier": "^1.17.1",
"prettier": "^2.8.0",
"ts-jest": "^27.0.5",
"typescript": "^3.8.3"
"typescript": "^4.3.3"
}
}
42 changes: 26 additions & 16 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ export async function getGo(
versionSpec: string,
checkLatest: boolean,
auth: string | undefined,
arch = os.arch(),
manifest: tc.IToolRelease[] | undefined
arch = os.arch()
) {
let manifest: tc.IToolRelease[] | undefined;
let osPlat: string = os.platform();

if (checkLatest) {
core.info('Attempting to resolve the latest version from the manifest...');
manifest = await getManifest(auth);
const resolvedVersion = await resolveVersionFromManifest(
versionSpec,
true,
Expand All @@ -60,11 +61,12 @@ export async function getGo(
versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable
) {
manifest ??= await getManifest(auth);
versionSpec = await resolveStableVersionInput(
versionSpec,
auth,
arch,
manifest
manifest as (tc.IToolRelease & IGoVersion)[]
);
}

Expand Down Expand Up @@ -266,6 +268,18 @@ export async function findMatch(
throw new Error(`golang download url did not return results`);
}

if (
versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable
) {
versionSpec = await resolveStableVersionInput(
versionSpec,
undefined,
arch,
candidates as (tc.IToolRelease & IGoVersion)[]
);
}

let goFile: IGoVersionFile | undefined;
for (let i = 0; i < candidates.length; i++) {
let candidate: IGoVersion = candidates[i];
Expand Down Expand Up @@ -358,14 +372,16 @@ export async function resolveStableVersionInput(
versionSpec: string,
auth: string | undefined,
arch = os.arch(),
manifest: tc.IToolRelease[] | undefined
manifest: (tc.IToolRelease & IGoVersion)[] | undefined
): Promise<string> {
if (!manifest) {
core.debug('No manifest cached');
manifest = await getManifest(auth);
manifest = (await getManifest(auth)) as (tc.IToolRelease & IGoVersion)[];
}

const releases = manifest.map(release => release.version);
const releases = manifest
.filter(release => !!release.files.find(file => file.arch === arch))
.map(release => release.version);

if (versionSpec === StableReleaseAlias.Stable) {
core.info(`stable version resolved as ${releases[0]}`);
Expand All @@ -377,22 +393,16 @@ export async function resolveStableVersionInput(
);
const uniqueVersions = Array.from(new Set(versions));

const oldstableVersion = await getInfoFromManifest(
uniqueVersions[1],
true,
auth,
arch,
manifest
const oldstableVersion = releases.find(item =>
item.startsWith(uniqueVersions[1])
);

core.info(
`oldstable version resolved as ${oldstableVersion?.resolvedVersion}`
);
core.info(`oldstable version resolved as ${oldstableVersion}`);

if (!oldstableVersion) {
return versionSpec;
}

return oldstableVersion.resolvedVersion;
return oldstableVersion;
}
}
Loading

0 comments on commit b7bdf8d

Please sign in to comment.