mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
fixing bugs
This commit is contained in:
parent
d7c7dfa509
commit
a4ae07903c
5 changed files with 110 additions and 32 deletions
|
@ -1,4 +1,4 @@
|
||||||
import os = require('os');
|
import os from 'os';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as im from '../src/installer';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import osm = require('os');
|
import osm from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import each from 'jest-each';
|
import each from 'jest-each';
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
|
@ -138,7 +138,8 @@ describe('setup-node', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can mock dist versions', async () => {
|
it('can mock dist versions', async () => {
|
||||||
let versions: im.INodeVersion[] = await im.getVersionsFromDist();
|
const versionSpec = '1.2.3';
|
||||||
|
let versions: im.INodeVersion[] = await im.getVersionsFromDist(versionSpec);
|
||||||
expect(versions).toBeDefined();
|
expect(versions).toBeDefined();
|
||||||
expect(versions?.length).toBe(23);
|
expect(versions?.length).toBe(23);
|
||||||
});
|
});
|
||||||
|
|
59
dist/setup/index.js
vendored
59
dist/setup/index.js
vendored
|
@ -73410,16 +73410,51 @@ function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translat
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function evaluateNightlyVersions(versions, versionSpec) {
|
||||||
|
let version = '';
|
||||||
|
let range;
|
||||||
|
const [raw, prerelease] = versionSpec.split('-');
|
||||||
|
const isValidVersion = semver.valid(raw);
|
||||||
|
const rawVersion = isValidVersion ? raw : semver.coerce(raw);
|
||||||
|
if (rawVersion) {
|
||||||
|
if (prerelease !== 'nightly') {
|
||||||
|
range = `${rawVersion}+${prerelease.replace('nightly', 'nightly.')}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
range = semver.validRange(`^${rawVersion}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (range) {
|
||||||
|
versions = versions.sort((a, b) => {
|
||||||
|
if (semver.gt(a, b)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
|
const potential = versions[i];
|
||||||
|
const satisfied = semver.satisfies(potential.replace('-nightly', '+nightly.'), range);
|
||||||
|
if (satisfied) {
|
||||||
|
version = potential;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
core.debug(`matched: ${version}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug('match not found');
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
||||||
function evaluateVersions(versions, versionSpec) {
|
function evaluateVersions(versions, versionSpec) {
|
||||||
let version = '';
|
let version = '';
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
core.debug(`version 1 is ${versions[0]}`);
|
if (versionSpec.includes('nightly')) {
|
||||||
core.debug(`version spec is ${versionSpec}`);
|
return evaluateNightlyVersions(versions, versionSpec);
|
||||||
versionSpec =
|
}
|
||||||
versionSpec.includes('nightly') && !semver.valid(versionSpec.split('-')[0])
|
|
||||||
? versionSpec.split('-')[0]
|
|
||||||
: versionSpec;
|
|
||||||
versions = versions.sort((a, b) => {
|
versions = versions.sort((a, b) => {
|
||||||
if (semver.gt(a, b)) {
|
if (semver.gt(a, b)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -73428,7 +73463,7 @@ function evaluateVersions(versions, versionSpec) {
|
||||||
});
|
});
|
||||||
for (let i = versions.length - 1; i >= 0; i--) {
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
const potential = versions[i];
|
const potential = versions[i];
|
||||||
const satisfied = semver.satisfies(potential.replace('-nightly', '+nightly.'), versionSpec.replace('-nightly', '+nightly'));
|
const satisfied = semver.satisfies(potential, versionSpec);
|
||||||
if (satisfied) {
|
if (satisfied) {
|
||||||
version = potential;
|
version = potential;
|
||||||
break;
|
break;
|
||||||
|
@ -73447,7 +73482,7 @@ function getNodejsDistUrl(version) {
|
||||||
if (!prerelease || !prerelease.length) {
|
if (!prerelease || !prerelease.length) {
|
||||||
return 'https://nodejs.org/dist';
|
return 'https://nodejs.org/dist';
|
||||||
}
|
}
|
||||||
else if (prerelease[0] === 'nightly') {
|
else if (version.includes('nightly')) {
|
||||||
return 'https://nodejs.org/download/nightly';
|
return 'https://nodejs.org/download/nightly';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -73642,7 +73677,7 @@ function run() {
|
||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||||
//
|
//
|
||||||
let version = resolveVersionInput();
|
const version = resolveVersionInput();
|
||||||
let arch = core.getInput('architecture');
|
let arch = core.getInput('architecture');
|
||||||
const cache = core.getInput('cache');
|
const cache = core.getInput('cache');
|
||||||
// if architecture supplied but node-version is not
|
// if architecture supplied but node-version is not
|
||||||
|
@ -73654,9 +73689,9 @@ function run() {
|
||||||
arch = os.arch();
|
arch = os.arch();
|
||||||
}
|
}
|
||||||
if (version) {
|
if (version) {
|
||||||
let token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`;
|
const auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`;
|
||||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
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';
|
||||||
yield installer.getNode(version, stable, checkLatest, auth, arch);
|
yield installer.getNode(version, stable, checkLatest, auth, arch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,16 +347,61 @@ async function resolveVersionFromManifest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function evaluateNightlyVersions(
|
||||||
|
versions: string[],
|
||||||
|
versionSpec: string
|
||||||
|
): string {
|
||||||
|
let version = '';
|
||||||
|
let range: string | null | undefined;
|
||||||
|
const [raw, prerelease] = versionSpec.split('-');
|
||||||
|
const isValidVersion = semver.valid(raw);
|
||||||
|
const rawVersion = isValidVersion ? raw : semver.coerce(raw);
|
||||||
|
if (rawVersion) {
|
||||||
|
if (prerelease !== 'nightly') {
|
||||||
|
range = `${rawVersion}+${prerelease.replace('nightly', 'nightly.')}`;
|
||||||
|
} else {
|
||||||
|
range = semver.validRange(`^${rawVersion}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (range) {
|
||||||
|
versions = versions.sort((a, b) => {
|
||||||
|
if (semver.gt(a, b)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
|
const potential: string = versions[i];
|
||||||
|
const satisfied: boolean = semver.satisfies(
|
||||||
|
potential.replace('-nightly', '+nightly.'),
|
||||||
|
range
|
||||||
|
);
|
||||||
|
if (satisfied) {
|
||||||
|
version = potential;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
core.debug(`matched: ${version}`);
|
||||||
|
} else {
|
||||||
|
core.debug('match not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
||||||
function evaluateVersions(versions: string[], versionSpec: string): string {
|
function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
let version = '';
|
let version = '';
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
core.debug(`version 1 is ${versions[0]}`);
|
|
||||||
core.debug(`version spec is ${versionSpec}`);
|
if(versionSpec.includes('nightly')) {
|
||||||
versionSpec =
|
return evaluateNightlyVersions(versions, versionSpec);
|
||||||
versionSpec.includes('nightly') && !semver.valid(versionSpec.split('-')[0])
|
}
|
||||||
? versionSpec.split('-')[0]
|
|
||||||
: versionSpec;
|
|
||||||
versions = versions.sort((a, b) => {
|
versions = versions.sort((a, b) => {
|
||||||
if (semver.gt(a, b)) {
|
if (semver.gt(a, b)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -365,10 +410,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
});
|
});
|
||||||
for (let i = versions.length - 1; i >= 0; i--) {
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
const potential: string = versions[i];
|
const potential: string = versions[i];
|
||||||
const satisfied: boolean = semver.satisfies(
|
const satisfied: boolean = semver.satisfies(potential, versionSpec);
|
||||||
potential.replace('-nightly', '+nightly.'),
|
|
||||||
versionSpec.replace('-nightly', '+nightly')
|
|
||||||
);
|
|
||||||
if (satisfied) {
|
if (satisfied) {
|
||||||
version = potential;
|
version = potential;
|
||||||
break;
|
break;
|
||||||
|
@ -384,11 +426,11 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNodejsDistUrl(version: string | semver.SemVer) {
|
function getNodejsDistUrl(version: string) {
|
||||||
const prerelease = semver.prerelease(version);
|
const prerelease = semver.prerelease(version);
|
||||||
if (!prerelease || !prerelease.length) {
|
if (!prerelease || !prerelease.length) {
|
||||||
return 'https://nodejs.org/dist';
|
return 'https://nodejs.org/dist';
|
||||||
} else if (prerelease[0] === 'nightly') {
|
} else if (version.includes('nightly')) {
|
||||||
return 'https://nodejs.org/download/nightly';
|
return 'https://nodejs.org/download/nightly';
|
||||||
} else {
|
} else {
|
||||||
return 'https://nodejs.org/download/rc';
|
return 'https://nodejs.org/download/rc';
|
||||||
|
@ -439,7 +481,7 @@ async function queryDistForMatch(
|
||||||
});
|
});
|
||||||
|
|
||||||
// get the latest version that matches the version spec
|
// get the latest version that matches the version spec
|
||||||
let version: string = evaluateVersions(versions, versionSpec);
|
let version = evaluateVersions(versions, versionSpec);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ export async function run() {
|
||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||||
//
|
//
|
||||||
let version = resolveVersionInput();
|
const version = resolveVersionInput();
|
||||||
|
|
||||||
let arch = core.getInput('architecture');
|
let arch = core.getInput('architecture');
|
||||||
const cache = core.getInput('cache');
|
const cache = core.getInput('cache');
|
||||||
|
@ -32,9 +32,9 @@ export async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
let token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
const auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
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';
|
||||||
await installer.getNode(version, stable, checkLatest, auth, arch);
|
await installer.getNode(version, stable, checkLatest, auth, arch);
|
||||||
|
|
Loading…
Add table
Reference in a new issue