mirror of
https://github.com/actions/setup-node.git
synced 2025-01-31 04:17:10 +07:00
added mirror-url
This commit is contained in:
parent
1d0ff469b7
commit
86a10608fa
@ -7,6 +7,10 @@ inputs:
|
||||
default: 'false'
|
||||
node-version:
|
||||
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
||||
mirror-url:
|
||||
description: 'The URL to download Node.js from, bypassing any checks.'
|
||||
required: false
|
||||
default: ''
|
||||
node-version-file:
|
||||
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.'
|
||||
architecture:
|
||||
|
2934
dist/cache-save/index.js
vendored
2934
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
3680
dist/setup/index.js
vendored
3680
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
9
package-lock.json
generated
9
package-lock.json
generated
@ -26,7 +26,7 @@
|
||||
"@types/semver": "^7.5.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@vercel/ncc": "^0.38.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
@ -2132,10 +2132,11 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@vercel/ncc": {
|
||||
"version": "0.38.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
|
||||
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
|
||||
"version": "0.38.3",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.3.tgz",
|
||||
"integrity": "sha512-rnK6hJBS6mwc+Bkab+PGPs9OiS0i/3kdTO+CkI8V0/VrW3vmz7O2Pxjw/owOlmo6PKEIxRSeZKv/kuL9itnpYA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"ncc": "dist/ncc/cli.js"
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
"@types/semver": "^7.5.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@vercel/ncc": "^0.38.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
|
86
src/main.ts
86
src/main.ts
@ -1,17 +1,34 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
import os from 'os';
|
||||
|
||||
import * as auth from './authutil';
|
||||
import * as semver from 'semver';
|
||||
import * as path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
import {isCacheFeatureAvailable} from './cache-utils';
|
||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
||||
import {State} from './constants';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
const mirrorUrl = core.getInput('mirror-url');
|
||||
const versionSpec = core.getInput('node-version');
|
||||
|
||||
if (mirrorUrl && versionSpec) {
|
||||
const nodePath = await downloadNodeFromMirror(versionSpec, mirrorUrl);
|
||||
core.addPath(nodePath);
|
||||
await printEnvDetailsAndSetOutput();
|
||||
core.info(
|
||||
`Node.js version ${versionSpec} has been downloaded and added to PATH from mirror URL: ${mirrorUrl}`
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Version is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||
@ -78,6 +95,75 @@ export async function run() {
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadNodeFromMirror(
|
||||
versionSpec: string,
|
||||
mirrorUrl: string
|
||||
): Promise<string> {
|
||||
const osPlat = process.platform;
|
||||
const osArch = translateArchToDistUrl(process.arch);
|
||||
// Resolve the version to the latest matching version
|
||||
const resolvedVersion = await resolveVersionFromMirror(
|
||||
versionSpec,
|
||||
mirrorUrl
|
||||
);
|
||||
|
||||
if (!resolvedVersion) {
|
||||
throw new Error(`Invalid Node.js version: ${versionSpec}`);
|
||||
}
|
||||
const cleanVersion = semver.clean(resolvedVersion) || resolvedVersion;
|
||||
const fileName =
|
||||
osPlat === 'win32'
|
||||
? `node-v${cleanVersion}-win-${osArch}`
|
||||
: `node-v${cleanVersion}-${osPlat}-${osArch}`;
|
||||
const urlFileName =
|
||||
osPlat === 'win32' ? `${fileName}.zip` : `${fileName}.tar.gz`;
|
||||
const downloadUrl = `${mirrorUrl}/v${cleanVersion}/${urlFileName}`;
|
||||
|
||||
core.info(`Attempting to download Node.js from mirror URL: ${downloadUrl}`);
|
||||
const downloadPath = await tc.downloadTool(downloadUrl);
|
||||
core.info('Extracting ...');
|
||||
|
||||
// Check the file extension and extract accordingly
|
||||
let extractedPath: string;
|
||||
if (downloadUrl.endsWith('.tar.gz')) {
|
||||
extractedPath = await tc.extractTar(downloadPath);
|
||||
} else if (downloadUrl.endsWith('.zip')) {
|
||||
extractedPath = await tc.extractZip(downloadPath);
|
||||
} else {
|
||||
throw new Error('Unsupported file format');
|
||||
}
|
||||
|
||||
// Ensure the correct path is added to the system PATH
|
||||
const toolPath = path.join(extractedPath);
|
||||
core.addPath(toolPath);
|
||||
|
||||
return toolPath;
|
||||
}
|
||||
async function resolveVersionFromMirror(
|
||||
versionSpec: string,
|
||||
mirrorUrl: string
|
||||
): Promise<string | null> {
|
||||
const dataUrl = `${mirrorUrl}/index.json`;
|
||||
const httpClient = new HttpClient('setup-node');
|
||||
const response = await httpClient.getJson<any[]>(dataUrl);
|
||||
const versions = response.result || [];
|
||||
|
||||
const matchingVersions = versions
|
||||
.map(version => version.version)
|
||||
.filter(version => semver.satisfies(version, versionSpec))
|
||||
.sort(semver.rcompare);
|
||||
|
||||
return matchingVersions.length > 0 ? matchingVersions[0] : null;
|
||||
}
|
||||
function translateArchToDistUrl(arch: string): string {
|
||||
switch (arch) {
|
||||
case 'arm':
|
||||
return 'armv7l';
|
||||
default:
|
||||
return arch;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('node-version');
|
||||
const versionFileInput = core.getInput('node-version-file');
|
||||
|
Loading…
Reference in New Issue
Block a user