Compare commits

...

3 Commits

Author SHA1 Message Date
Raphaël
b7480e6723
Merge 7d1c5630d8 into 1c7b2db920 2024-09-09 16:11:47 -04:00
Priya Gupta
1c7b2db920
Fix: windows arm64 setup (#1126)
* Add condition to ensure ZIP extraction targets only Windows ARM64 official archives

* Bumps micromatch from 4.0.5 to 4.0.8
2024-09-06 14:30:34 -05:00
Raphaël
7d1c5630d8
Explicitly exit the process to not wait for hanging promises
See https://github.com/actions/setup-node/issues/878
2023-11-27 16:08:54 +01:00
10 changed files with 52 additions and 12 deletions

View File

@ -46,6 +46,7 @@ describe('setup-node', () => {
let isCacheActionAvailable: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance; let getExecOutputSpy: jest.SpyInstance;
let getJsonSpy: jest.SpyInstance; let getJsonSpy: jest.SpyInstance;
let processExitSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
// @actions/core // @actions/core
@ -63,6 +64,9 @@ describe('setup-node', () => {
archSpy = jest.spyOn(osm, 'arch'); archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']); archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync'); execSpy = jest.spyOn(cp, 'execSync');
processExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((() => {}) as () => never);
// @actions/tool-cache // @actions/tool-cache
findSpy = jest.spyOn(tc, 'find'); findSpy = jest.spyOn(tc, 'find');

View File

@ -38,6 +38,8 @@ describe('main tests', () => {
let setupNodeJsSpy: jest.SpyInstance; let setupNodeJsSpy: jest.SpyInstance;
let processExitSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
inputs = {}; inputs = {};
@ -76,6 +78,10 @@ describe('main tests', () => {
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs'); setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs');
setupNodeJsSpy.mockImplementation(() => {}); setupNodeJsSpy.mockImplementation(() => {});
processExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((() => {}) as () => never);
}); });
afterEach(() => { afterEach(() => {
@ -237,6 +243,12 @@ describe('main tests', () => {
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}` `::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
); );
}); });
it('should call process.exit() explicitly after running', async () => {
await main.run();
expect(processExitSpy).toHaveBeenCalled();
});
}); });
describe('cache on GHES', () => { describe('cache on GHES', () => {

View File

@ -46,6 +46,7 @@ describe('setup-node', () => {
let isCacheActionAvailable: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance; let getExecOutputSpy: jest.SpyInstance;
let getJsonSpy: jest.SpyInstance; let getJsonSpy: jest.SpyInstance;
let processExitSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
// @actions/core // @actions/core
@ -64,6 +65,9 @@ describe('setup-node', () => {
archSpy = jest.spyOn(osm, 'arch'); archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']); archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync'); execSpy = jest.spyOn(cp, 'execSync');
processExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((() => {}) as () => never);
// @actions/tool-cache // @actions/tool-cache
findSpy = jest.spyOn(tc, 'find'); findSpy = jest.spyOn(tc, 'find');

View File

@ -46,6 +46,7 @@ describe('setup-node', () => {
let isCacheActionAvailable: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance; let getExecOutputSpy: jest.SpyInstance;
let getJsonSpy: jest.SpyInstance; let getJsonSpy: jest.SpyInstance;
let processExitSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
// @actions/core // @actions/core
@ -63,6 +64,9 @@ describe('setup-node', () => {
archSpy = jest.spyOn(osm, 'arch'); archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']); archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync'); execSpy = jest.spyOn(cp, 'execSync');
processExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((() => {}) as () => never);
// @actions/tool-cache // @actions/tool-cache
findSpy = jest.spyOn(tc, 'find'); findSpy = jest.spyOn(tc, 'find');

View File

@ -41,6 +41,7 @@ describe('setup-node', () => {
let isCacheActionAvailable: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance; let getExecOutputSpy: jest.SpyInstance;
let getJsonSpy: jest.SpyInstance; let getJsonSpy: jest.SpyInstance;
let processExitSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
// @actions/core // @actions/core
@ -58,6 +59,9 @@ describe('setup-node', () => {
archSpy = jest.spyOn(osm, 'arch'); archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']); archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync'); execSpy = jest.spyOn(cp, 'execSync');
processExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((() => {}) as () => never);
// @actions/tool-cache // @actions/tool-cache
findSpy = jest.spyOn(tc, 'find'); findSpy = jest.spyOn(tc, 'find');

11
dist/setup/index.js vendored
View File

@ -93883,7 +93883,7 @@ class BaseDistribution {
} }
throw err; throw err;
} }
const toolPath = yield this.extractArchive(downloadPath, info); const toolPath = yield this.extractArchive(downloadPath, info, true);
core.info('Done'); core.info('Done');
return toolPath; return toolPath;
}); });
@ -93933,7 +93933,7 @@ class BaseDistribution {
return toolPath; return toolPath;
}); });
} }
extractArchive(downloadPath, info) { extractArchive(downloadPath, info, isOfficialArchive) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// //
// Extract // Extract
@ -93948,7 +93948,7 @@ class BaseDistribution {
// on Windows runners without PowerShell Core. // on Windows runners without PowerShell Core.
// //
// For default PowerShell Windows it should contain extension type to unpack it. // For default PowerShell Windows it should contain extension type to unpack it.
if (extension === '.zip') { if (extension === '.zip' && isOfficialArchive) {
const renamedArchive = `${downloadPath}.zip`; const renamedArchive = `${downloadPath}.zip`;
fs_1.default.renameSync(downloadPath, renamedArchive); fs_1.default.renameSync(downloadPath, renamedArchive);
extPath = yield tc.extractZip(renamedArchive); extPath = yield tc.extractZip(renamedArchive);
@ -94186,7 +94186,7 @@ class OfficialBuilds extends base_distribution_1.default {
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`); core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth); downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
if (downloadPath) { if (downloadPath) {
toolPath = yield this.extractArchive(downloadPath, versionInfo); toolPath = yield this.extractArchive(downloadPath, versionInfo, false);
} }
} }
else { else {
@ -94476,6 +94476,9 @@ function run() {
catch (err) { catch (err) {
core.setFailed(err.message); core.setFailed(err.message);
} }
// Explicit process.exit() to not wait for hanging promises,
// see https://github.com/actions/setup-node/issues/878
process.exit();
}); });
} }
exports.run = run; exports.run = run;

8
package-lock.json generated
View File

@ -4429,12 +4429,12 @@
} }
}, },
"node_modules/micromatch": { "node_modules/micromatch": {
"version": "4.0.5", "version": "4.0.8",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
"integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"braces": "^3.0.2", "braces": "^3.0.3",
"picomatch": "^2.3.1" "picomatch": "^2.3.1"
}, },
"engines": { "engines": {

View File

@ -150,7 +150,7 @@ export default abstract class BaseDistribution {
throw err; throw err;
} }
const toolPath = await this.extractArchive(downloadPath, info); const toolPath = await this.extractArchive(downloadPath, info, true);
core.info('Done'); core.info('Done');
return toolPath; return toolPath;
@ -210,7 +210,8 @@ export default abstract class BaseDistribution {
protected async extractArchive( protected async extractArchive(
downloadPath: string, downloadPath: string,
info: INodeVersionInfo | null info: INodeVersionInfo | null,
isOfficialArchive?: boolean
) { ) {
// //
// Extract // Extract
@ -225,7 +226,7 @@ export default abstract class BaseDistribution {
// on Windows runners without PowerShell Core. // on Windows runners without PowerShell Core.
// //
// For default PowerShell Windows it should contain extension type to unpack it. // For default PowerShell Windows it should contain extension type to unpack it.
if (extension === '.zip') { if (extension === '.zip' && isOfficialArchive) {
const renamedArchive = `${downloadPath}.zip`; const renamedArchive = `${downloadPath}.zip`;
fs.renameSync(downloadPath, renamedArchive); fs.renameSync(downloadPath, renamedArchive);
extPath = await tc.extractZip(renamedArchive); extPath = await tc.extractZip(renamedArchive);

View File

@ -88,7 +88,11 @@ export default class OfficialBuilds extends BaseDistribution {
); );
if (downloadPath) { if (downloadPath) {
toolPath = await this.extractArchive(downloadPath, versionInfo); toolPath = await this.extractArchive(
downloadPath,
versionInfo,
false
);
} }
} else { } else {
core.info( core.info(

View File

@ -76,6 +76,10 @@ export async function run() {
} catch (err) { } catch (err) {
core.setFailed((err as Error).message); core.setFailed((err as Error).message);
} }
// Explicit process.exit() to not wait for hanging promises,
// see https://github.com/actions/setup-node/issues/878
process.exit();
} }
function resolveVersionInput(): string { function resolveVersionInput(): string {