mirror of
https://github.com/actions/setup-node.git
synced 2025-06-30 14:43:48 +00:00
Merge remote-tracking branch 'upstream/main' into feature/corepack
This commit is contained in:
commit
dfc689aeba
48 changed files with 27860 additions and 12127 deletions
|
@ -3,6 +3,7 @@ import * as core from '@actions/core';
|
|||
import * as glob from '@actions/glob';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
|
||||
import {State} from './constants';
|
||||
import {
|
||||
|
@ -21,6 +22,7 @@ export const restoreCache = async (
|
|||
throw new Error(`Caching for '${packageManager}' is not supported`);
|
||||
}
|
||||
const platform = process.env.RUNNER_OS;
|
||||
const arch = os.arch();
|
||||
|
||||
const cachePaths = await getCacheDirectories(
|
||||
packageManagerInfo,
|
||||
|
@ -38,7 +40,7 @@ export const restoreCache = async (
|
|||
);
|
||||
}
|
||||
|
||||
const keyPrefix = `node-cache-${platform}-${packageManager}`;
|
||||
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
|
||||
const primaryKey = `${keyPrefix}-${fileHash}`;
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
|
||||
|
|
|
@ -295,7 +295,13 @@ export function isGhes(): boolean {
|
|||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||
|
||||
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
|
||||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
|
|
|
@ -112,7 +112,11 @@ export default abstract class BaseDistribution {
|
|||
? `node-v${version}-win-${osArch}`
|
||||
: `node-v${version}-${this.osPlat}-${osArch}`;
|
||||
const urlFileName: string =
|
||||
this.osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
|
||||
this.osPlat == 'win32'
|
||||
? this.nodeInfo.arch === 'arm64'
|
||||
? `${fileName}.zip`
|
||||
: `${fileName}.7z`
|
||||
: `${fileName}.tar.gz`;
|
||||
const initialUrl = this.getDistributionUrl();
|
||||
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
||||
|
||||
|
@ -146,7 +150,7 @@ export default abstract class BaseDistribution {
|
|||
throw err;
|
||||
}
|
||||
|
||||
const toolPath = await this.extractArchive(downloadPath, info);
|
||||
const toolPath = await this.extractArchive(downloadPath, info, true);
|
||||
core.info('Done');
|
||||
|
||||
return toolPath;
|
||||
|
@ -206,7 +210,8 @@ export default abstract class BaseDistribution {
|
|||
|
||||
protected async extractArchive(
|
||||
downloadPath: string,
|
||||
info: INodeVersionInfo | null
|
||||
info: INodeVersionInfo | null,
|
||||
isOfficialArchive?: boolean
|
||||
) {
|
||||
//
|
||||
// Extract
|
||||
|
@ -215,12 +220,24 @@ export default abstract class BaseDistribution {
|
|||
let extPath: string;
|
||||
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
|
||||
if (this.osPlat == 'win32') {
|
||||
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
||||
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
||||
const extension = this.nodeInfo.arch === 'arm64' ? '.zip' : '.7z';
|
||||
// Rename archive to add extension because after downloading
|
||||
// archive does not contain extension type and it leads to some issues
|
||||
// on Windows runners without PowerShell Core.
|
||||
//
|
||||
// For default PowerShell Windows it should contain extension type to unpack it.
|
||||
if (extension === '.zip' && isOfficialArchive) {
|
||||
const renamedArchive = `${downloadPath}.zip`;
|
||||
fs.renameSync(downloadPath, renamedArchive);
|
||||
extPath = await tc.extractZip(renamedArchive);
|
||||
} else {
|
||||
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
||||
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
||||
}
|
||||
// 7z extracts to folder matching file name
|
||||
const nestedPath = path.join(
|
||||
extPath,
|
||||
path.basename(info.fileName, '.7z')
|
||||
path.basename(info.fileName, extension)
|
||||
);
|
||||
if (fs.existsSync(nestedPath)) {
|
||||
extPath = nestedPath;
|
||||
|
@ -260,7 +277,11 @@ export default abstract class BaseDistribution {
|
|||
dataFileName = `osx-${osArch}-tar`;
|
||||
break;
|
||||
case 'win32':
|
||||
dataFileName = `win-${osArch}-exe`;
|
||||
if (this.nodeInfo.arch === 'arm64') {
|
||||
dataFileName = `win-${osArch}-zip`;
|
||||
} else {
|
||||
dataFileName = `win-${osArch}-exe`;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected OS '${this.osPlat}'`);
|
||||
|
|
|
@ -88,7 +88,11 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
);
|
||||
|
||||
if (downloadPath) {
|
||||
toolPath = await this.extractArchive(downloadPath, versionInfo);
|
||||
toolPath = await this.extractArchive(
|
||||
downloadPath,
|
||||
versionInfo,
|
||||
false
|
||||
);
|
||||
}
|
||||
} else {
|
||||
core.info(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
@ -62,9 +63,9 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
|||
|
||||
export async function printEnvDetailsAndSetOutput() {
|
||||
core.startGroup('Environment details');
|
||||
|
||||
const promises = ['node', 'npm', 'yarn'].map(async tool => {
|
||||
const output = await getToolVersion(tool, ['--version']);
|
||||
const pathTool = await io.which(tool, false);
|
||||
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
||||
|
||||
return {tool, output};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue