remove changing prerelease

This commit is contained in:
Dmitry Shibanov 2022-12-27 20:58:46 +01:00
parent 7f2fa59092
commit 363785e8f4
4 changed files with 29 additions and 128 deletions

View file

@ -60,16 +60,15 @@ export default abstract class BaseDistribution {
core.addPath(toolPath);
}
protected evaluateVersions(versions: string[]) {
protected evaluateVersions(versions: string[]): string {
let version = '';
const {range, options} = this.validRange(this.nodeInfo.versionSpec);
core.debug(`evaluating ${versions.length} versions`);
for (let potential of versions) {
const satisfied: boolean = semver.satisfies(
potential,
this.nodeInfo.versionSpec
);
const satisfied: boolean = semver.satisfies(potential, range, options);
if (satisfied) {
version = potential;
break;
@ -141,6 +140,14 @@ export default abstract class BaseDistribution {
return toolPath;
}
protected validRange(versionSpec: string) {
let options: semver.Options | undefined;
const c = semver.clean(versionSpec) || '';
const valid = semver.valid(c) ?? versionSpec;
return {range: valid, options};
}
protected async acquireNodeFromFallbackLocation(
version: string,
arch: string = os.arch()

View file

@ -1,4 +1,3 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import semver from 'semver';
@ -33,44 +32,11 @@ export default class NightlyNodejs extends BaseDistribution {
return toolPath;
}
protected evaluateVersions(versions: string[]): string {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
const {includePrerelease, range} = this.createRangePreRelease(
this.nodeInfo.versionSpec
);
for (let i = 0; i < versions.length; i++) {
const potential: string = versions[i];
const satisfied: boolean = semver.satisfies(
potential.replace(this.distribution, `${this.distribution}.`),
range,
{
includePrerelease: includePrerelease
}
);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
return version;
}
protected getDistributionUrl(): string {
return 'https://nodejs.org/download/nightly';
}
protected createRangePreRelease(versionSpec: string) {
protected validRange(versionSpec: string) {
let range: string;
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver.valid(raw);
@ -85,7 +51,7 @@ export default class NightlyNodejs extends BaseDistribution {
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return {range, includePrerelease: !isValidVersion};
return {range, options: {includePrerelease: !isValidVersion}};
}
protected splitVersionSpec(versionSpec: string) {

View file

@ -1,4 +1,3 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import semver from 'semver';
@ -37,40 +36,7 @@ export default class CanaryBuild extends BaseDistribution {
return 'https://nodejs.org/download/v8-canary';
}
protected evaluateVersions(versions: string[]): string {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
const {includePrerelease, range} = this.createRangePreRelease(
this.nodeInfo.versionSpec
);
for (let i = 0; i < versions.length; i++) {
const potential: string = versions[i];
const satisfied: boolean = semver.satisfies(
potential.replace(this.distribution, `${this.distribution}.`),
range,
{
includePrerelease: includePrerelease
}
);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
return version;
}
protected createRangePreRelease(versionSpec: string) {
protected validRange(versionSpec: string) {
let range: string;
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver.valid(raw);
@ -85,7 +51,7 @@ export default class CanaryBuild extends BaseDistribution {
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return {range, includePrerelease: !isValidVersion};
return {range, options: {includePrerelease: !isValidVersion}};
}
protected splitVersionSpec(versionSpec: string) {