add possible improvement for canary

This commit is contained in:
Dmitry Shibanov 2022-12-13 14:19:28 +01:00
parent 7fc684f251
commit 0d35e2c938
3 changed files with 33 additions and 26 deletions

24
dist/setup/index.js vendored
View file

@ -73848,11 +73848,17 @@ const core = __importStar(__nccwpck_require__(2186));
const semver_1 = __importDefault(__nccwpck_require__(5911)); const semver_1 = __importDefault(__nccwpck_require__(5911));
const base_distribution_1 = __importDefault(__nccwpck_require__(8653)); const base_distribution_1 = __importDefault(__nccwpck_require__(8653));
class CanaryBuild extends base_distribution_1.default { class CanaryBuild extends base_distribution_1.default {
constructor(nodeInfo) {
super(nodeInfo);
}
getDistributionUrl() {
return 'https://nodejs.org/download/v8-canary';
}
evaluateVersions(nodeVersions) { evaluateVersions(nodeVersions) {
let version = ''; let version = '';
const versions = this.filterVersions(nodeVersions); const versions = this.filterVersions(nodeVersions);
core.debug(`evaluating ${versions.length} versions`); 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++) { for (let i = 0; i < versions.length; i++) {
const potential = versions[i]; const potential = versions[i];
const satisfied = semver_1.default.satisfies(potential.replace('v8-canary', 'v8-canary.'), range, { 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; return version;
} }
constructor(nodeInfo) {
super(nodeInfo);
}
getDistributionUrl() {
return 'https://nodejs.org/download/v8-canary';
}
getNodejsVersions() { getNodejsVersions() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const initialUrl = this.getDistributionUrl(); const initialUrl = this.getDistributionUrl();
@ -73890,11 +73890,11 @@ class CanaryBuild extends base_distribution_1.default {
const [raw, prerelease] = this.splitVersionSpec(versionSpec); const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver_1.default.valid(raw); const isValidVersion = semver_1.default.valid(raw);
const rawVersion = (isValidVersion ? raw : semver_1.default.coerce(raw)); const rawVersion = (isValidVersion ? raw : semver_1.default.coerce(raw));
if (`-${prerelease}` !== distribution) { if (prerelease !== distribution) {
range = `${rawVersion}${`-${prerelease}`.replace(distribution, `${distribution}.`)}`; range = `${rawVersion}-${prerelease.replace(distribution, `${distribution}.`)}`;
} }
else { else {
range = `${semver_1.default.validRange(`^${rawVersion}${distribution}`)}-0`; range = `${semver_1.default.validRange(`^${rawVersion}-${distribution}`)}-0`;
} }
return { range, includePrerelease: !isValidVersion }; return { range, includePrerelease: !isValidVersion };
} }
@ -74471,7 +74471,6 @@ function run() {
if (version) { if (version) {
const token = core.getInput('token'); const token = core.getInput('token');
const auth = !token ? undefined : `token ${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 checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
const nodejsInfo = { const nodejsInfo = {
versionSpec: version, versionSpec: version,
@ -74483,6 +74482,9 @@ function run() {
if (nodeDistribution) { if (nodeDistribution) {
yield (nodeDistribution === null || nodeDistribution === void 0 ? void 0 : nodeDistribution.getNodeJsInfo()); 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); // await installer.getNode(version, stable, checkLatest, auth, arch);
} }
yield printEnvDetailsAndSetOutput(); yield printEnvDetailsAndSetOutput();

View file

@ -6,6 +6,14 @@ import BaseDistribution from '../base-distribution';
import {INodejs, INodeVersion} from '../base-models'; import {INodejs, INodeVersion} from '../base-models';
export default class CanaryBuild extends BaseDistribution { 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 { protected evaluateVersions(nodeVersions: INodeVersion[]): string {
let version = ''; let version = '';
const versions = this.filterVersions(nodeVersions); const versions = this.filterVersions(nodeVersions);
@ -14,7 +22,7 @@ export default class CanaryBuild extends BaseDistribution {
const {includePrerelease, range} = this.createRangePreRelease( const {includePrerelease, range} = this.createRangePreRelease(
this.nodeInfo.versionSpec, this.nodeInfo.versionSpec,
'-v8-canary' 'v8-canary'
); );
for (let i = 0; i < versions.length; i++) { for (let i = 0; i < versions.length; i++) {
@ -40,12 +48,6 @@ export default class CanaryBuild extends BaseDistribution {
return version; return version;
} }
constructor(nodeInfo: INodejs) {
super(nodeInfo);
}
protected getDistributionUrl(): string {
return 'https://nodejs.org/download/v8-canary';
}
async getNodejsVersions(): Promise<INodeVersion[]> { async getNodejsVersions(): Promise<INodeVersion[]> {
const initialUrl = this.getDistributionUrl(); const initialUrl = this.getDistributionUrl();
@ -55,25 +57,28 @@ export default class CanaryBuild extends BaseDistribution {
return response.result || []; return response.result || [];
} }
createRangePreRelease(versionSpec: string, distribution: string = '') { protected createRangePreRelease(
let range: string | undefined; versionSpec: string,
distribution: string = ''
) {
let range: string;
const [raw, prerelease] = this.splitVersionSpec(versionSpec); const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver.valid(raw); const isValidVersion = semver.valid(raw);
const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!; const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!;
if (`-${prerelease}` !== distribution) { if (prerelease !== distribution) {
range = `${rawVersion}${`-${prerelease}`.replace( range = `${rawVersion}-${prerelease.replace(
distribution, distribution,
`${distribution}.` `${distribution}.`
)}`; )}`;
} else { } else {
range = `${semver.validRange(`^${rawVersion}${distribution}`)}-0`; range = `${semver.validRange(`^${rawVersion}-${distribution}`)}-0`;
} }
return {range, includePrerelease: !isValidVersion}; return {range, includePrerelease: !isValidVersion};
} }
splitVersionSpec(versionSpec: string) { protected splitVersionSpec(versionSpec: string) {
return versionSpec.split(/-(.*)/s); return versionSpec.split(/-(.*)/s);
} }
} }

View file

@ -35,8 +35,6 @@ export async function run() {
if (version) { if (version) {
const token = core.getInput('token'); const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`; const auth = !token ? undefined : `token ${token}`;
const stable =
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const checkLatest = const checkLatest =
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
const nodejsInfo = { const nodejsInfo = {
@ -48,6 +46,8 @@ export async function run() {
const nodeDistribution = getNodejsDistribution(nodejsInfo); const nodeDistribution = getNodejsDistribution(nodejsInfo);
if (nodeDistribution) { if (nodeDistribution) {
await nodeDistribution?.getNodeJsInfo(); await nodeDistribution?.getNodeJsInfo();
} else {
throw new Error(`Could not resolve version: ${version} for build`);
} }
// await installer.getNode(version, stable, checkLatest, auth, arch); // await installer.getNode(version, stable, checkLatest, auth, arch);