From 0d35e2c9381db3848e3293d567180384227ae4a9 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 13 Dec 2022 14:19:28 +0100 Subject: [PATCH] add possible improvement for canary --- dist/setup/index.js | 24 ++++++++-------- src/distibutions/v8-canary/canary_builds.ts | 31 ++++++++++++--------- src/main.ts | 4 +-- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ee068222..a588788c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73848,11 +73848,17 @@ const core = __importStar(__nccwpck_require__(2186)); const semver_1 = __importDefault(__nccwpck_require__(5911)); const base_distribution_1 = __importDefault(__nccwpck_require__(8653)); class CanaryBuild extends base_distribution_1.default { + constructor(nodeInfo) { + super(nodeInfo); + } + getDistributionUrl() { + return 'https://nodejs.org/download/v8-canary'; + } evaluateVersions(nodeVersions) { let version = ''; const versions = this.filterVersions(nodeVersions); core.debug(`evaluating ${versions.length} versions`); - const { includePrerelease, range } = this.createRangePreRelease(this.nodeInfo.versionSpec, '-v8-canary'); + const { includePrerelease, range } = this.createRangePreRelease(this.nodeInfo.versionSpec, 'v8-canary'); for (let i = 0; i < versions.length; i++) { const potential = versions[i]; const satisfied = semver_1.default.satisfies(potential.replace('v8-canary', 'v8-canary.'), range, { @@ -73871,12 +73877,6 @@ class CanaryBuild extends base_distribution_1.default { } return version; } - constructor(nodeInfo) { - super(nodeInfo); - } - getDistributionUrl() { - return 'https://nodejs.org/download/v8-canary'; - } getNodejsVersions() { return __awaiter(this, void 0, void 0, function* () { const initialUrl = this.getDistributionUrl(); @@ -73890,11 +73890,11 @@ class CanaryBuild extends base_distribution_1.default { const [raw, prerelease] = this.splitVersionSpec(versionSpec); const isValidVersion = semver_1.default.valid(raw); const rawVersion = (isValidVersion ? raw : semver_1.default.coerce(raw)); - if (`-${prerelease}` !== distribution) { - range = `${rawVersion}${`-${prerelease}`.replace(distribution, `${distribution}.`)}`; + if (prerelease !== distribution) { + range = `${rawVersion}-${prerelease.replace(distribution, `${distribution}.`)}`; } else { - range = `${semver_1.default.validRange(`^${rawVersion}${distribution}`)}-0`; + range = `${semver_1.default.validRange(`^${rawVersion}-${distribution}`)}-0`; } return { range, includePrerelease: !isValidVersion }; } @@ -74471,7 +74471,6 @@ function run() { if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; - const stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; const nodejsInfo = { versionSpec: version, @@ -74483,6 +74482,9 @@ function run() { if (nodeDistribution) { yield (nodeDistribution === null || nodeDistribution === void 0 ? void 0 : nodeDistribution.getNodeJsInfo()); } + else { + throw new Error(`Could not resolve version: ${version} for build`); + } // await installer.getNode(version, stable, checkLatest, auth, arch); } yield printEnvDetailsAndSetOutput(); diff --git a/src/distibutions/v8-canary/canary_builds.ts b/src/distibutions/v8-canary/canary_builds.ts index 19bc3b42..2ebf5321 100644 --- a/src/distibutions/v8-canary/canary_builds.ts +++ b/src/distibutions/v8-canary/canary_builds.ts @@ -6,6 +6,14 @@ import BaseDistribution from '../base-distribution'; import {INodejs, INodeVersion} from '../base-models'; export default class CanaryBuild extends BaseDistribution { + constructor(nodeInfo: INodejs) { + super(nodeInfo); + } + + protected getDistributionUrl(): string { + return 'https://nodejs.org/download/v8-canary'; + } + protected evaluateVersions(nodeVersions: INodeVersion[]): string { let version = ''; const versions = this.filterVersions(nodeVersions); @@ -14,7 +22,7 @@ export default class CanaryBuild extends BaseDistribution { const {includePrerelease, range} = this.createRangePreRelease( this.nodeInfo.versionSpec, - '-v8-canary' + 'v8-canary' ); for (let i = 0; i < versions.length; i++) { @@ -40,12 +48,6 @@ export default class CanaryBuild extends BaseDistribution { return version; } - constructor(nodeInfo: INodejs) { - super(nodeInfo); - } - protected getDistributionUrl(): string { - return 'https://nodejs.org/download/v8-canary'; - } async getNodejsVersions(): Promise { const initialUrl = this.getDistributionUrl(); @@ -55,25 +57,28 @@ export default class CanaryBuild extends BaseDistribution { return response.result || []; } - createRangePreRelease(versionSpec: string, distribution: string = '') { - let range: string | undefined; + protected createRangePreRelease( + versionSpec: string, + distribution: string = '' + ) { + let range: string; const [raw, prerelease] = this.splitVersionSpec(versionSpec); const isValidVersion = semver.valid(raw); const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!; - if (`-${prerelease}` !== distribution) { - range = `${rawVersion}${`-${prerelease}`.replace( + if (prerelease !== distribution) { + range = `${rawVersion}-${prerelease.replace( distribution, `${distribution}.` )}`; } else { - range = `${semver.validRange(`^${rawVersion}${distribution}`)}-0`; + range = `${semver.validRange(`^${rawVersion}-${distribution}`)}-0`; } return {range, includePrerelease: !isValidVersion}; } - splitVersionSpec(versionSpec: string) { + protected splitVersionSpec(versionSpec: string) { return versionSpec.split(/-(.*)/s); } } diff --git a/src/main.ts b/src/main.ts index b250085c..fb7e9286 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,8 +35,6 @@ export async function run() { if (version) { const token = core.getInput('token'); const auth = !token ? undefined : `token ${token}`; - const stable = - (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; const nodejsInfo = { @@ -48,6 +46,8 @@ export async function run() { const nodeDistribution = getNodejsDistribution(nodejsInfo); if (nodeDistribution) { await nodeDistribution?.getNodeJsInfo(); + } else { + throw new Error(`Could not resolve version: ${version} for build`); } // await installer.getNode(version, stable, checkLatest, auth, arch);