mirror of
https://github.com/actions/setup-node.git
synced 2025-06-29 22:23:47 +00:00
mirrorurl code
This commit is contained in:
parent
802632921f
commit
0b66095a84
6 changed files with 210 additions and 62 deletions
|
@ -25,6 +25,7 @@ export default abstract class BaseDistribution {
|
|||
}
|
||||
|
||||
protected abstract getDistributionUrl(): string;
|
||||
|
||||
|
||||
public async setupNodeJs() {
|
||||
let nodeJsVersions: INodeVersion[] | undefined;
|
||||
|
@ -128,6 +129,31 @@ export default abstract class BaseDistribution {
|
|||
};
|
||||
}
|
||||
|
||||
protected getNodejsMirrorURLInfo(version: string) {
|
||||
const mirrorURL = this.nodeInfo.mirrorURL;
|
||||
const osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||
version = semver.clean(version) || '';
|
||||
const fileName: string =
|
||||
this.osPlat == 'win32'
|
||||
? `node-v${version}-win-${osArch}`
|
||||
: `node-v${version}-${this.osPlat}-${osArch}`;
|
||||
const urlFileName: string =
|
||||
this.osPlat == 'win32'
|
||||
? this.nodeInfo.arch === 'arm64'
|
||||
? `${fileName}.zip`
|
||||
: `${fileName}.7z`
|
||||
: `${fileName}.tar.gz`;
|
||||
|
||||
const url = `${mirrorURL}/v${version}/${urlFileName}`;
|
||||
|
||||
return <INodeVersionInfo>{
|
||||
downloadUrl: url,
|
||||
resolvedVersion: version,
|
||||
arch: osArch,
|
||||
fileName: fileName
|
||||
};
|
||||
}
|
||||
|
||||
protected async downloadNodejs(info: INodeVersionInfo) {
|
||||
let downloadPath = '';
|
||||
core.info(
|
||||
|
|
|
@ -4,6 +4,7 @@ export interface NodeInputs {
|
|||
auth?: string;
|
||||
checkLatest: boolean;
|
||||
stable: boolean;
|
||||
mirrorURL: string;
|
||||
}
|
||||
|
||||
export interface INodeVersionInfo {
|
||||
|
@ -11,6 +12,7 @@ export interface INodeVersionInfo {
|
|||
resolvedVersion: string;
|
||||
arch: string;
|
||||
fileName: string;
|
||||
|
||||
}
|
||||
|
||||
export interface INodeVersion {
|
||||
|
|
|
@ -12,9 +12,27 @@ interface INodeRelease extends tc.IToolRelease {
|
|||
export default class OfficialBuilds extends BaseDistribution {
|
||||
constructor(nodeInfo: NodeInputs) {
|
||||
super(nodeInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async setupNodeJs() {
|
||||
if(this.nodeInfo.mirrorURL){
|
||||
|
||||
let downloadPath = '';
|
||||
let toolPath = '';
|
||||
try {
|
||||
core.info(`Attempting to download using mirror URL...`);
|
||||
downloadPath = await this.downloadFromMirrorURL(); // Attempt to download from the mirror
|
||||
if (downloadPath) {
|
||||
toolPath = downloadPath;
|
||||
}
|
||||
} catch (err) {
|
||||
core.info((err as Error).message);
|
||||
core.debug((err as Error).stack ?? 'empty stack');
|
||||
}
|
||||
|
||||
}else{
|
||||
let manifest: tc.IToolRelease[] | undefined;
|
||||
let nodeJsVersions: INodeVersion[] | undefined;
|
||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||
|
@ -125,6 +143,8 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
|
||||
core.addPath(toolPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected addToolPath(toolPath: string) {
|
||||
if (this.osPlat != 'win32') {
|
||||
|
@ -180,6 +200,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
return `https://nodejs.org/dist`;
|
||||
}
|
||||
|
||||
|
||||
private getManifest(): Promise<tc.IToolRelease[]> {
|
||||
core.debug('Getting manifest from actions/node-versions@main');
|
||||
return tc.getManifestFromRepo(
|
||||
|
@ -291,4 +312,34 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
private isLatestSyntax(versionSpec): boolean {
|
||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||
}
|
||||
|
||||
protected async downloadFromMirrorURL() {
|
||||
const nodeJsVersions = await this.getNodeJsVersions();
|
||||
const versions = this.filterVersions(nodeJsVersions);
|
||||
const evaluatedVersion = this.evaluateVersions(versions);
|
||||
|
||||
if (!evaluatedVersion) {
|
||||
throw new Error(
|
||||
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
||||
);
|
||||
}
|
||||
|
||||
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
|
||||
|
||||
try {
|
||||
const toolPath = await this.downloadNodejs(toolName);
|
||||
return toolPath;
|
||||
} catch (error) {
|
||||
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
|
||||
core.warning(
|
||||
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
|
||||
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
|
||||
'To resolve this issue you may either fall back to the older version or try again later.'
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ export async function run() {
|
|||
arch = os.arch();
|
||||
}
|
||||
|
||||
const mirrorURL = core.getInput('mirrorURL').trim(); // .trim() to remove any accidental spaces
|
||||
|
||||
|
||||
if (version) {
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
|
@ -45,7 +48,8 @@ export async function run() {
|
|||
checkLatest,
|
||||
auth,
|
||||
stable,
|
||||
arch
|
||||
arch,
|
||||
mirrorURL
|
||||
};
|
||||
const nodeDistribution = getNodejsDistribution(nodejsInfo);
|
||||
await nodeDistribution.setupNodeJs();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue