add nightly build support

This commit is contained in:
Dmitry Shibanov 2022-10-13 14:15:49 +02:00
parent 8c91899e58
commit ccb6d0562b
3 changed files with 81 additions and 20 deletions

View File

@ -51,6 +51,26 @@ jobs:
__tests__/verify-node.sh "${BASH_REMATCH[1]}"
shell: bash
nightly-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [17-nightly, 18-nightly, 19-nightly]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: |
nightlyVersion="${{ matrix.node-version }}"
majorVersion=$(echo $nightlyVersion | cut -d- -f1)
__tests__/verify-node.sh "${BASH_REMATCH[1]}"
shell: bash
manifest:
runs-on: ${{ matrix.os }}
strategy:

40
dist/setup/index.js vendored
View File

@ -73194,6 +73194,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
// Store manifest data to avoid multiple calls
let manifest;
let nodeVersions;
let isNightly = versionSpec.includes('nightly');
let osPlat = os.platform();
let osArch = translateArchToDistUrl(arch);
if (isLtsAlias(versionSpec)) {
@ -73203,10 +73204,14 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}
if (isLatestSyntax(versionSpec)) {
nodeVersions = yield getVersionsFromDist();
nodeVersions = yield getVersionsFromDist(versionSpec);
versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
core.info(`getting latest node version...`);
}
if (isNightly) {
nodeVersions = yield getVersionsFromDist(versionSpec);
versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
}
if (checkLatest) {
core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
@ -73382,7 +73387,8 @@ function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) {
? `node-v${version}-win-${osArch}`
: `node-v${version}-${osPlat}-${osArch}`;
let urlFileName = osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let url = `https://nodejs.org/dist/v${version}/${urlFileName}`;
const initialUrl = getNodejsDistUrl(versionSpec);
let url = `${initialUrl}/v${version}/${urlFileName}`;
return {
downloadUrl: url,
resolvedVersion: version,
@ -73407,7 +73413,7 @@ function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translat
function evaluateVersions(versions, versionSpec) {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
versions = versions.sort((a, b) => {
versions = versions.map(item => item.replace('nightly', 'nightly.')).sort((a, b) => {
if (semver.gt(a, b)) {
return 1;
}
@ -73429,6 +73435,18 @@ function evaluateVersions(versions, versionSpec) {
}
return version;
}
function getNodejsDistUrl(version) {
const prerelease = semver.prerelease(version);
if (!prerelease || !prerelease.length) {
return 'https://nodejs.org/dist';
}
else if (prerelease[0] === 'nightly') {
return 'https://nodejs.org/download/nightly';
}
else {
return 'https://nodejs.org/download/rc';
}
}
function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
@ -73450,7 +73468,7 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
}
if (!nodeVersions) {
core.debug('No dist manifest cached');
nodeVersions = yield getVersionsFromDist();
nodeVersions = yield getVersionsFromDist(versionSpec);
}
let versions = [];
if (isLatestSyntax(versionSpec)) {
@ -73468,9 +73486,10 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
return version;
});
}
function getVersionsFromDist() {
function getVersionsFromDist(versionSpec) {
return __awaiter(this, void 0, void 0, function* () {
let dataUrl = 'https://nodejs.org/dist/index.json';
const initialUrl = getNodejsDistUrl(versionSpec);
const dataUrl = `${initialUrl}/index.json`;
let httpClient = new hc.HttpClient('setup-node', [], {
allowRetries: true,
maxRetries: 3
@ -73494,6 +73513,7 @@ exports.getVersionsFromDist = getVersionsFromDist;
// and lib file in a folder, not zipped.
function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
const initialUrl = getNodejsDistUrl(version);
let osPlat = os.platform();
let osArch = translateArchToDistUrl(arch);
// Create temporary folder to download in to
@ -73505,8 +73525,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
let exeUrl;
let libUrl;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
core.info(`Downloading only node binary from ${exeUrl}`);
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
@ -73515,8 +73535,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
}
catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
exeUrl = `${initialUrl}/v${version}/node.exe`;
libUrl = `${initialUrl}/v${version}/node.lib`;
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = yield tc.downloadTool(libUrl);

View File

@ -11,6 +11,7 @@ import fs = require('fs');
//
// Node versions interface
// see https://nodejs.org/dist/index.json
// for nightly https://nodejs.org/download/nightly/index.json
//
export interface INodeVersion {
version: string;
@ -38,6 +39,7 @@ export async function getNode(
// Store manifest data to avoid multiple calls
let manifest: INodeRelease[] | undefined;
let nodeVersions: INodeVersion[] | undefined;
let isNightly = versionSpec.includes('nightly');
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch);
@ -51,11 +53,16 @@ export async function getNode(
}
if (isLatestSyntax(versionSpec)) {
nodeVersions = await getVersionsFromDist();
nodeVersions = await getVersionsFromDist(versionSpec);
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
core.info(`getting latest node version...`);
}
if (isNightly) {
nodeVersions = await getVersionsFromDist(versionSpec);
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
}
if (checkLatest) {
core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = await resolveVersionFromManifest(
@ -306,7 +313,8 @@ async function getInfoFromDist(
: `node-v${version}-${osPlat}-${osArch}`;
let urlFileName: string =
osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let url = `https://nodejs.org/dist/v${version}/${urlFileName}`;
const initialUrl = getNodejsDistUrl(versionSpec);
let url = `${initialUrl}/v${version}/${urlFileName}`;
return <INodeVersionInfo>{
downloadUrl: url,
@ -342,7 +350,7 @@ async function resolveVersionFromManifest(
function evaluateVersions(versions: string[], versionSpec: string): string {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
versions = versions.sort((a, b) => {
versions = versions.map(item => item.replace('nightly', 'nightly.')).sort((a, b) => {
if (semver.gt(a, b)) {
return 1;
}
@ -366,6 +374,17 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
return version;
}
function getNodejsDistUrl(version: string | semver.SemVer) {
const prerelease = semver.prerelease(version);
if (!prerelease || !prerelease.length) {
return 'https://nodejs.org/dist';
} else if (prerelease[0] === 'nightly') {
return 'https://nodejs.org/download/nightly';
} else {
return 'https://nodejs.org/download/rc';
}
}
async function queryDistForMatch(
versionSpec: string,
arch: string = os.arch(),
@ -392,7 +411,7 @@ async function queryDistForMatch(
if (!nodeVersions) {
core.debug('No dist manifest cached');
nodeVersions = await getVersionsFromDist();
nodeVersions = await getVersionsFromDist(versionSpec);
}
let versions: string[] = [];
@ -414,8 +433,9 @@ async function queryDistForMatch(
return version;
}
export async function getVersionsFromDist(): Promise<INodeVersion[]> {
let dataUrl = 'https://nodejs.org/dist/index.json';
export async function getVersionsFromDist(versionSpec: string): Promise<INodeVersion[]> {
const initialUrl = getNodejsDistUrl(versionSpec);
const dataUrl = `${initialUrl}/index.json`;
let httpClient = new hc.HttpClient('setup-node', [], {
allowRetries: true,
maxRetries: 3
@ -440,6 +460,7 @@ async function acquireNodeFromFallbackLocation(
version: string,
arch: string = os.arch()
): Promise<string> {
const initialUrl = getNodejsDistUrl(version);
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch);
@ -453,8 +474,8 @@ async function acquireNodeFromFallbackLocation(
let exeUrl: string;
let libUrl: string;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
core.info(`Downloading only node binary from ${exeUrl}`);
@ -464,8 +485,8 @@ async function acquireNodeFromFallbackLocation(
await io.cp(libPath, path.join(tempDir, 'node.lib'));
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
exeUrl = `${initialUrl}/v${version}/node.exe`;
libUrl = `${initialUrl}/v${version}/node.lib`;
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));