resolve comments

This commit is contained in:
Dmitry Shibanov 2022-12-27 19:28:20 +01:00
parent f12d842f13
commit 7f2fa59092
6 changed files with 153 additions and 384 deletions

View file

@ -24,7 +24,6 @@ export default abstract class BaseDistribution {
}
protected abstract getDistributionUrl(): string;
protected abstract evaluateVersions(nodeVersions: string[]): string;
public async setupNodeJs() {
let nodeJsVersions: INodeVersion[] | undefined;
@ -50,7 +49,7 @@ export default abstract class BaseDistribution {
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion, this.osPlat);
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
}
@ -61,6 +60,31 @@ export default abstract class BaseDistribution {
core.addPath(toolPath);
}
protected evaluateVersions(versions: string[]) {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
for (let potential of versions) {
const satisfied: boolean = semver.satisfies(
potential,
this.nodeInfo.versionSpec
);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
return version;
}
protected findVersionInHostedToolCacheDirectory() {
return tc.find('node', this.nodeInfo.versionSpec, this.nodeInfo.arch);
}
@ -73,15 +97,15 @@ export default abstract class BaseDistribution {
return response.result || [];
}
protected getNodejsDistInfo(version: string, osPlat: string) {
protected getNodejsDistInfo(version: string) {
let osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
version = semver.clean(version) || '';
let fileName: string =
osPlat == 'win32'
this.osPlat == 'win32'
? `node-v${version}-win-${osArch}`
: `node-v${version}-${osPlat}-${osArch}`;
: `node-v${version}-${this.osPlat}-${osArch}`;
let urlFileName: string =
osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
this.osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
const initialUrl = this.getDistributionUrl();
const url = `${initialUrl}/v${version}/${urlFileName}`;
@ -205,8 +229,8 @@ export default abstract class BaseDistribution {
return toolPath;
}
protected getDistFileName(arch: string): string {
let osArch: string = this.translateArchToDistUrl(arch);
protected getDistFileName(): string {
let osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
// node offers a json list of versions
let dataFileName: string;
@ -230,7 +254,7 @@ export default abstract class BaseDistribution {
protected filterVersions(nodeJsVersions: INodeVersion[]) {
const versions: string[] = [];
const dataFileName = this.getDistFileName(this.nodeInfo.arch);
const dataFileName = this.getDistFileName();
nodeJsVersions.forEach((nodeVersion: INodeVersion) => {
// ensure this version supports your os and platform

View file

@ -12,31 +12,20 @@ enum Distributions {
RC = 'rc'
}
function identifyDistribution(versionSpec: string) {
let distribution = Distributions.DEFAULT;
export function getNodejsDistribution(
installerOptions: INodejs
): BaseDistribution {
const versionSpec = installerOptions.versionSpec;
let distribution: BaseDistribution;
if (versionSpec.includes(Distributions.NIGHTLY)) {
distribution = Distributions.NIGHTLY;
distribution = new NightlyNodejs(installerOptions);
} else if (versionSpec.includes(Distributions.CANARY)) {
distribution = Distributions.CANARY;
distribution = new CanaryBuild(installerOptions);
} else if (versionSpec.includes(Distributions.RC)) {
distribution = Distributions.RC;
distribution = new RcBuild(installerOptions);
} else {
distribution = new OfficialBuilds(installerOptions);
}
return distribution;
}
export function getNodejsDistribution(
installerOptions: INodejs
): BaseDistribution {
const distributionName = identifyDistribution(installerOptions.versionSpec);
switch (distributionName) {
case Distributions.NIGHTLY:
return new NightlyNodejs(installerOptions);
case Distributions.CANARY:
return new CanaryBuild(installerOptions);
case Distributions.RC:
return new RcBuild(installerOptions);
default:
return new OfficialBuilds(installerOptions);
}
}

View file

@ -1,7 +1,5 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as semver from 'semver';
import os from 'os';
import path from 'path';
import BaseDistribution from '../base-distribution';
@ -115,7 +113,7 @@ export default class OfficialBuilds extends BaseDistribution {
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion, this.osPlat);
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
}
}
@ -135,24 +133,7 @@ export default class OfficialBuilds extends BaseDistribution {
return versions[0];
}
core.debug(`evaluating ${versions.length} versions`);
for (let potential of versions) {
const satisfied: boolean = semver.satisfies(
potential,
this.nodeInfo.versionSpec
);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
version = super.evaluateVersions(versions);
return version;
}
@ -235,7 +216,7 @@ export default class OfficialBuilds extends BaseDistribution {
private async getInfoFromManifest(
versionSpec: string,
osArch: string = this.translateArchToDistUrl(os.arch()),
osArch: string,
manifest: tc.IToolRelease[] | undefined
): Promise<INodeVersionInfo | null> {
const stable = true;

View file

@ -1,7 +1,3 @@
import * as core from '@actions/core';
import * as semver from 'semver';
import BaseDistribution from '../base-distribution';
import {INodejs} from '../base-models';
@ -10,32 +6,6 @@ export default class RcBuild extends BaseDistribution {
super(nodeInfo);
}
protected evaluateVersions(versions: string[]): string {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
for (let i = 0; i < versions.length; i++) {
const potential: string = versions[i];
const satisfied: boolean = semver.satisfies(
potential,
this.nodeInfo.versionSpec
);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
return version;
}
getDistributionUrl(): string {
return 'https://nodejs.org/download/rc';
}