mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:43:35 +00:00 
			
		
		
		
	Merge branch 'v-dmshib/add-nightly-support' of github.com:dmitry-shibanov/setup-node into v-sedoli/lkgr
This commit is contained in:
		
						commit
						fa20ef8ad2
					
				
							
								
								
									
										20
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										20
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							@ -51,6 +51,26 @@ jobs:
 | 
				
			|||||||
          __tests__/verify-node.sh "${BASH_REMATCH[1]}"
 | 
					          __tests__/verify-node.sh "${BASH_REMATCH[1]}"
 | 
				
			||||||
        shell: bash
 | 
					        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 "$majorVersion"
 | 
				
			||||||
 | 
					        shell: bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  manifest:
 | 
					  manifest:
 | 
				
			||||||
    runs-on: ${{ matrix.os }}
 | 
					    runs-on: ${{ matrix.os }}
 | 
				
			||||||
    strategy:
 | 
					    strategy:
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										107
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										107
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -73194,6 +73194,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
				
			|||||||
        // Store manifest data to avoid multiple calls
 | 
					        // Store manifest data to avoid multiple calls
 | 
				
			||||||
        let manifest;
 | 
					        let manifest;
 | 
				
			||||||
        let nodeVersions;
 | 
					        let nodeVersions;
 | 
				
			||||||
 | 
					        let isNightly = versionSpec.includes('nightly');
 | 
				
			||||||
        let osPlat = os.platform();
 | 
					        let osPlat = os.platform();
 | 
				
			||||||
        let osArch = translateArchToDistUrl(arch);
 | 
					        let osArch = translateArchToDistUrl(arch);
 | 
				
			||||||
        if (isLtsAlias(versionSpec)) {
 | 
					        if (isLtsAlias(versionSpec)) {
 | 
				
			||||||
@ -73203,11 +73204,15 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
				
			|||||||
            versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
 | 
					            versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (isLatestSyntax(versionSpec)) {
 | 
					        if (isLatestSyntax(versionSpec)) {
 | 
				
			||||||
            nodeVersions = yield getVersionsFromDist();
 | 
					            nodeVersions = yield getVersionsFromDist(versionSpec);
 | 
				
			||||||
            versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
					            versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
				
			||||||
            core.info(`getting latest node version...`);
 | 
					            core.info(`getting latest node version...`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (checkLatest) {
 | 
					        if (isNightly && checkLatest) {
 | 
				
			||||||
 | 
					            nodeVersions = yield getVersionsFromDist(versionSpec);
 | 
				
			||||||
 | 
					            versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (checkLatest && !isNightly) {
 | 
				
			||||||
            core.info('Attempt to resolve the latest version from manifest...');
 | 
					            core.info('Attempt to resolve the latest version from manifest...');
 | 
				
			||||||
            const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
 | 
					            const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
 | 
				
			||||||
            if (resolvedVersion) {
 | 
					            if (resolvedVersion) {
 | 
				
			||||||
@ -73219,8 +73224,15 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // check cache
 | 
					        // check cache
 | 
				
			||||||
 | 
					        core.debug('check toolcache');
 | 
				
			||||||
        let toolPath;
 | 
					        let toolPath;
 | 
				
			||||||
        toolPath = tc.find('node', versionSpec, osArch);
 | 
					        if (isNightly) {
 | 
				
			||||||
 | 
					            const nightlyVersion = findNightlyVersionInHostedToolcache(versionSpec, osArch);
 | 
				
			||||||
 | 
					            toolPath = nightlyVersion && tc.find('node', nightlyVersion, osArch);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            toolPath = tc.find('node', versionSpec, osArch);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        // If not found in cache, download
 | 
					        // If not found in cache, download
 | 
				
			||||||
        if (toolPath) {
 | 
					        if (toolPath) {
 | 
				
			||||||
            core.info(`Found in cache @ ${toolPath}`);
 | 
					            core.info(`Found in cache @ ${toolPath}`);
 | 
				
			||||||
@ -73233,7 +73245,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
				
			|||||||
            // Try download from internal distribution (popular versions only)
 | 
					            // Try download from internal distribution (popular versions only)
 | 
				
			||||||
            //
 | 
					            //
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                info = yield getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
 | 
					                info = yield getInfoFromManifest(versionSpec, !isNightly, auth, osArch, manifest);
 | 
				
			||||||
                if (info) {
 | 
					                if (info) {
 | 
				
			||||||
                    core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
 | 
					                    core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
 | 
				
			||||||
                    downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
 | 
					                    downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
 | 
				
			||||||
@ -73316,6 +73328,12 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
exports.getNode = getNode;
 | 
					exports.getNode = getNode;
 | 
				
			||||||
 | 
					function findNightlyVersionInHostedToolcache(versionsSpec, osArch) {
 | 
				
			||||||
 | 
					    const foundAllVersions = tc.findAllVersions('node', osArch);
 | 
				
			||||||
 | 
					    core.debug(foundAllVersions.join('\n'));
 | 
				
			||||||
 | 
					    const version = evaluateVersions(foundAllVersions, versionsSpec);
 | 
				
			||||||
 | 
					    return version;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
function isLtsAlias(versionSpec) {
 | 
					function isLtsAlias(versionSpec) {
 | 
				
			||||||
    return versionSpec.startsWith('lts/');
 | 
					    return versionSpec.startsWith('lts/');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -73382,7 +73400,8 @@ function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) {
 | 
				
			|||||||
            ? `node-v${version}-win-${osArch}`
 | 
					            ? `node-v${version}-win-${osArch}`
 | 
				
			||||||
            : `node-v${version}-${osPlat}-${osArch}`;
 | 
					            : `node-v${version}-${osPlat}-${osArch}`;
 | 
				
			||||||
        let urlFileName = osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
 | 
					        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 {
 | 
					        return {
 | 
				
			||||||
            downloadUrl: url,
 | 
					            downloadUrl: url,
 | 
				
			||||||
            resolvedVersion: version,
 | 
					            resolvedVersion: version,
 | 
				
			||||||
@ -73403,10 +73422,52 @@ 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(versions[1]);
 | 
				
			||||||
 | 
					    if (versionSpec.includes('nightly')) {
 | 
				
			||||||
 | 
					        return evaluateNightlyVersions(versions, 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;
 | 
				
			||||||
@ -73429,6 +73490,18 @@ function evaluateVersions(versions, versionSpec) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return version;
 | 
					    return version;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					function getNodejsDistUrl(version) {
 | 
				
			||||||
 | 
					    const prerelease = semver.prerelease(version);
 | 
				
			||||||
 | 
					    if (version.includes('nightly')) {
 | 
				
			||||||
 | 
					        return 'https://nodejs.org/download/nightly';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (!prerelease) {
 | 
				
			||||||
 | 
					        return 'https://nodejs.org/dist';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        return 'https://nodejs.org/download/rc';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
 | 
					function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        let osPlat = os.platform();
 | 
					        let osPlat = os.platform();
 | 
				
			||||||
@ -73450,7 +73523,7 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        if (!nodeVersions) {
 | 
					        if (!nodeVersions) {
 | 
				
			||||||
            core.debug('No dist manifest cached');
 | 
					            core.debug('No dist manifest cached');
 | 
				
			||||||
            nodeVersions = yield getVersionsFromDist();
 | 
					            nodeVersions = yield getVersionsFromDist(versionSpec);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let versions = [];
 | 
					        let versions = [];
 | 
				
			||||||
        if (isLatestSyntax(versionSpec)) {
 | 
					        if (isLatestSyntax(versionSpec)) {
 | 
				
			||||||
@ -73468,9 +73541,10 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
 | 
				
			|||||||
        return version;
 | 
					        return version;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
function getVersionsFromDist() {
 | 
					function getVersionsFromDist(versionSpec) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    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', [], {
 | 
					        let httpClient = new hc.HttpClient('setup-node', [], {
 | 
				
			||||||
            allowRetries: true,
 | 
					            allowRetries: true,
 | 
				
			||||||
            maxRetries: 3
 | 
					            maxRetries: 3
 | 
				
			||||||
@ -73494,6 +73568,7 @@ exports.getVersionsFromDist = getVersionsFromDist;
 | 
				
			|||||||
// and lib file in a folder, not zipped.
 | 
					// and lib file in a folder, not zipped.
 | 
				
			||||||
function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
 | 
					function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
 | 
					        const initialUrl = getNodejsDistUrl(version);
 | 
				
			||||||
        let osPlat = os.platform();
 | 
					        let osPlat = os.platform();
 | 
				
			||||||
        let osArch = translateArchToDistUrl(arch);
 | 
					        let osArch = translateArchToDistUrl(arch);
 | 
				
			||||||
        // Create temporary folder to download in to
 | 
					        // Create temporary folder to download in to
 | 
				
			||||||
@ -73505,8 +73580,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
 | 
				
			|||||||
        let exeUrl;
 | 
					        let exeUrl;
 | 
				
			||||||
        let libUrl;
 | 
					        let libUrl;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
 | 
					            exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
 | 
				
			||||||
            libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
 | 
					            libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
 | 
				
			||||||
            core.info(`Downloading only node binary from ${exeUrl}`);
 | 
					            core.info(`Downloading only node binary from ${exeUrl}`);
 | 
				
			||||||
            const exePath = yield tc.downloadTool(exeUrl);
 | 
					            const exePath = yield tc.downloadTool(exeUrl);
 | 
				
			||||||
            yield io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
					            yield io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
				
			||||||
@ -73515,8 +73590,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        catch (err) {
 | 
					        catch (err) {
 | 
				
			||||||
            if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
					            if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
				
			||||||
                exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
 | 
					                exeUrl = `${initialUrl}/v${version}/node.exe`;
 | 
				
			||||||
                libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
 | 
					                libUrl = `${initialUrl}/v${version}/node.lib`;
 | 
				
			||||||
                const exePath = yield tc.downloadTool(exeUrl);
 | 
					                const exePath = yield tc.downloadTool(exeUrl);
 | 
				
			||||||
                yield io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
					                yield io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
				
			||||||
                const libPath = yield tc.downloadTool(libUrl);
 | 
					                const libPath = yield tc.downloadTool(libUrl);
 | 
				
			||||||
@ -73615,7 +73690,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
 | 
				
			||||||
@ -73627,9 +73702,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);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										121
									
								
								src/installer.ts
									
									
									
									
									
								
							
							
						
						
									
										121
									
								
								src/installer.ts
									
									
									
									
									
								
							@ -11,6 +11,7 @@ import fs = require('fs');
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
// Node versions interface
 | 
					// Node versions interface
 | 
				
			||||||
// see https://nodejs.org/dist/index.json
 | 
					// see https://nodejs.org/dist/index.json
 | 
				
			||||||
 | 
					// for nightly https://nodejs.org/download/nightly/index.json
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
export interface INodeVersion {
 | 
					export interface INodeVersion {
 | 
				
			||||||
  version: string;
 | 
					  version: string;
 | 
				
			||||||
@ -38,6 +39,7 @@ export async function getNode(
 | 
				
			|||||||
  // Store manifest data to avoid multiple calls
 | 
					  // Store manifest data to avoid multiple calls
 | 
				
			||||||
  let manifest: INodeRelease[] | undefined;
 | 
					  let manifest: INodeRelease[] | undefined;
 | 
				
			||||||
  let nodeVersions: INodeVersion[] | undefined;
 | 
					  let nodeVersions: INodeVersion[] | undefined;
 | 
				
			||||||
 | 
					  let isNightly = versionSpec.includes('nightly');
 | 
				
			||||||
  let osPlat: string = os.platform();
 | 
					  let osPlat: string = os.platform();
 | 
				
			||||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
					  let osArch: string = translateArchToDistUrl(arch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -51,12 +53,17 @@ export async function getNode(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (isLatestSyntax(versionSpec)) {
 | 
					  if (isLatestSyntax(versionSpec)) {
 | 
				
			||||||
    nodeVersions = await getVersionsFromDist();
 | 
					    nodeVersions = await getVersionsFromDist(versionSpec);
 | 
				
			||||||
    versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
					    versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
				
			||||||
    core.info(`getting latest node version...`);
 | 
					    core.info(`getting latest node version...`);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (checkLatest) {
 | 
					  if (isNightly && checkLatest) {
 | 
				
			||||||
 | 
					    nodeVersions = await getVersionsFromDist(versionSpec);
 | 
				
			||||||
 | 
					    versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (checkLatest && !isNightly) {
 | 
				
			||||||
    core.info('Attempt to resolve the latest version from manifest...');
 | 
					    core.info('Attempt to resolve the latest version from manifest...');
 | 
				
			||||||
    const resolvedVersion = await resolveVersionFromManifest(
 | 
					    const resolvedVersion = await resolveVersionFromManifest(
 | 
				
			||||||
      versionSpec,
 | 
					      versionSpec,
 | 
				
			||||||
@ -74,8 +81,17 @@ export async function getNode(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // check cache
 | 
					  // check cache
 | 
				
			||||||
 | 
					  core.debug('check toolcache');
 | 
				
			||||||
  let toolPath: string;
 | 
					  let toolPath: string;
 | 
				
			||||||
  toolPath = tc.find('node', versionSpec, osArch);
 | 
					  if (isNightly) {
 | 
				
			||||||
 | 
					    const nightlyVersion = findNightlyVersionInHostedToolcache(
 | 
				
			||||||
 | 
					      versionSpec,
 | 
				
			||||||
 | 
					      osArch
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    toolPath = nightlyVersion && tc.find('node', nightlyVersion, osArch);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    toolPath = tc.find('node', versionSpec, osArch);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // If not found in cache, download
 | 
					  // If not found in cache, download
 | 
				
			||||||
  if (toolPath) {
 | 
					  if (toolPath) {
 | 
				
			||||||
@ -91,7 +107,7 @@ export async function getNode(
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
      info = await getInfoFromManifest(
 | 
					      info = await getInfoFromManifest(
 | 
				
			||||||
        versionSpec,
 | 
					        versionSpec,
 | 
				
			||||||
        stable,
 | 
					        !isNightly,
 | 
				
			||||||
        auth,
 | 
					        auth,
 | 
				
			||||||
        osArch,
 | 
					        osArch,
 | 
				
			||||||
        manifest
 | 
					        manifest
 | 
				
			||||||
@ -199,6 +215,17 @@ export async function getNode(
 | 
				
			|||||||
  core.addPath(toolPath);
 | 
					  core.addPath(toolPath);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function findNightlyVersionInHostedToolcache(
 | 
				
			||||||
 | 
					  versionsSpec: string,
 | 
				
			||||||
 | 
					  osArch: string
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					  const foundAllVersions = tc.findAllVersions('node', osArch);
 | 
				
			||||||
 | 
					  core.debug(foundAllVersions.join('\n'));
 | 
				
			||||||
 | 
					  const version = evaluateVersions(foundAllVersions, versionsSpec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return version;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function isLtsAlias(versionSpec: string): boolean {
 | 
					function isLtsAlias(versionSpec: string): boolean {
 | 
				
			||||||
  return versionSpec.startsWith('lts/');
 | 
					  return versionSpec.startsWith('lts/');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -306,7 +333,8 @@ async function getInfoFromDist(
 | 
				
			|||||||
      : `node-v${version}-${osPlat}-${osArch}`;
 | 
					      : `node-v${version}-${osPlat}-${osArch}`;
 | 
				
			||||||
  let urlFileName: string =
 | 
					  let urlFileName: string =
 | 
				
			||||||
    osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
 | 
					    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>{
 | 
					  return <INodeVersionInfo>{
 | 
				
			||||||
    downloadUrl: url,
 | 
					    downloadUrl: url,
 | 
				
			||||||
@ -338,10 +366,62 @@ 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(versions[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (versionSpec.includes('nightly')) {
 | 
				
			||||||
 | 
					    return evaluateNightlyVersions(versions, 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;
 | 
				
			||||||
@ -366,6 +446,17 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
 | 
				
			|||||||
  return version;
 | 
					  return version;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getNodejsDistUrl(version: string) {
 | 
				
			||||||
 | 
					  const prerelease = semver.prerelease(version);
 | 
				
			||||||
 | 
					  if (version.includes('nightly')) {
 | 
				
			||||||
 | 
					    return 'https://nodejs.org/download/nightly';
 | 
				
			||||||
 | 
					  } else if (!prerelease) {
 | 
				
			||||||
 | 
					    return 'https://nodejs.org/dist';
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return 'https://nodejs.org/download/rc';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function queryDistForMatch(
 | 
					async function queryDistForMatch(
 | 
				
			||||||
  versionSpec: string,
 | 
					  versionSpec: string,
 | 
				
			||||||
  arch: string = os.arch(),
 | 
					  arch: string = os.arch(),
 | 
				
			||||||
@ -392,7 +483,7 @@ async function queryDistForMatch(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if (!nodeVersions) {
 | 
					  if (!nodeVersions) {
 | 
				
			||||||
    core.debug('No dist manifest cached');
 | 
					    core.debug('No dist manifest cached');
 | 
				
			||||||
    nodeVersions = await getVersionsFromDist();
 | 
					    nodeVersions = await getVersionsFromDist(versionSpec);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let versions: string[] = [];
 | 
					  let versions: string[] = [];
 | 
				
			||||||
@ -410,12 +501,15 @@ 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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function getVersionsFromDist(): Promise<INodeVersion[]> {
 | 
					export async function getVersionsFromDist(
 | 
				
			||||||
  let dataUrl = 'https://nodejs.org/dist/index.json';
 | 
					  versionSpec: string
 | 
				
			||||||
 | 
					): Promise<INodeVersion[]> {
 | 
				
			||||||
 | 
					  const initialUrl = getNodejsDistUrl(versionSpec);
 | 
				
			||||||
 | 
					  const dataUrl = `${initialUrl}/index.json`;
 | 
				
			||||||
  let httpClient = new hc.HttpClient('setup-node', [], {
 | 
					  let httpClient = new hc.HttpClient('setup-node', [], {
 | 
				
			||||||
    allowRetries: true,
 | 
					    allowRetries: true,
 | 
				
			||||||
    maxRetries: 3
 | 
					    maxRetries: 3
 | 
				
			||||||
@ -440,6 +534,7 @@ async function acquireNodeFromFallbackLocation(
 | 
				
			|||||||
  version: string,
 | 
					  version: string,
 | 
				
			||||||
  arch: string = os.arch()
 | 
					  arch: string = os.arch()
 | 
				
			||||||
): Promise<string> {
 | 
					): Promise<string> {
 | 
				
			||||||
 | 
					  const initialUrl = getNodejsDistUrl(version);
 | 
				
			||||||
  let osPlat: string = os.platform();
 | 
					  let osPlat: string = os.platform();
 | 
				
			||||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
					  let osArch: string = translateArchToDistUrl(arch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -453,8 +548,8 @@ async function acquireNodeFromFallbackLocation(
 | 
				
			|||||||
  let exeUrl: string;
 | 
					  let exeUrl: string;
 | 
				
			||||||
  let libUrl: string;
 | 
					  let libUrl: string;
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
 | 
					    exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
 | 
				
			||||||
    libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
 | 
					    libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    core.info(`Downloading only node binary from ${exeUrl}`);
 | 
					    core.info(`Downloading only node binary from ${exeUrl}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -464,8 +559,8 @@ async function acquireNodeFromFallbackLocation(
 | 
				
			|||||||
    await io.cp(libPath, path.join(tempDir, 'node.lib'));
 | 
					    await io.cp(libPath, path.join(tempDir, 'node.lib'));
 | 
				
			||||||
  } catch (err) {
 | 
					  } catch (err) {
 | 
				
			||||||
    if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
					    if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
				
			||||||
      exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
 | 
					      exeUrl = `${initialUrl}/v${version}/node.exe`;
 | 
				
			||||||
      libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
 | 
					      libUrl = `${initialUrl}/v${version}/node.lib`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const exePath = await tc.downloadTool(exeUrl);
 | 
					      const exePath = await tc.downloadTool(exeUrl);
 | 
				
			||||||
      await io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
					      await io.cp(exePath, path.join(tempDir, 'node.exe'));
 | 
				
			||||||
 | 
				
			|||||||
@ -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,10 @@ 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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user