mirror of
https://github.com/actions/setup-java.git
synced 2026-11-23 04:43:06 +00:00
Compare commits
2 Commits
0781fc6af3
...
v6.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de7274f081 | ||
|
|
134912a529 |
87
__tests__/entrypoints.test.ts
Normal file
87
__tests__/entrypoints.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import {afterAll, beforeAll, describe, expect, it} from '@jest/globals';
|
||||
import {spawnSync} from 'child_process';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import {fileURLToPath, pathToFileURL} from 'url';
|
||||
|
||||
const dist = fileURLToPath(new URL('../dist/', import.meta.url));
|
||||
let tempDir: string;
|
||||
let linkedDist: string;
|
||||
|
||||
beforeAll(() => {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-java-entrypoints-'));
|
||||
linkedDist = path.join(tempDir, 'linked # dist');
|
||||
fs.symlinkSync(dist, linkedDist, 'junction');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
fs.rmSync(tempDir, {recursive: true, force: true});
|
||||
});
|
||||
|
||||
function execute(args: string[], input?: string) {
|
||||
return spawnSync(process.execPath, args, {
|
||||
encoding: 'utf8',
|
||||
input,
|
||||
timeout: 10000,
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
SystemRoot: process.env.SystemRoot
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe.each([
|
||||
['setup', 1, 'java-version or java-version-file input expected'],
|
||||
['cleanup', 0, '']
|
||||
] as const)('%s entrypoint', (name, exitCode, output) => {
|
||||
it.each(['direct', 'symlink', 'preserved symlink'])(
|
||||
'executes through a %s path',
|
||||
mode => {
|
||||
const entry = path.join(
|
||||
mode === 'direct' ? dist : linkedDist,
|
||||
name,
|
||||
'index.js'
|
||||
);
|
||||
const args =
|
||||
mode === 'preserved symlink'
|
||||
? ['--preserve-symlinks-main', entry]
|
||||
: [entry];
|
||||
const result = execute(args);
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.status).toBe(exitCode);
|
||||
expect(result.stderr).toBe('');
|
||||
expect(result.stdout).not.toContain('skipping the execution');
|
||||
if (output) {
|
||||
expect(result.stdout).toContain(output);
|
||||
} else {
|
||||
expect(result.stdout).toBe('');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['eval', 'stdin', 'file'])(
|
||||
'does not execute when imported from %s',
|
||||
mode => {
|
||||
const moduleUrl = pathToFileURL(path.join(dist, name, 'index.js')).href;
|
||||
const source = `const {run} = await import(${JSON.stringify(moduleUrl)}); console.log(typeof run);`;
|
||||
const importer = path.join(tempDir, `${name}-importer.mjs`);
|
||||
fs.writeFileSync(importer, source);
|
||||
const args =
|
||||
mode === 'file'
|
||||
? [importer]
|
||||
: mode === 'eval'
|
||||
? ['--input-type=module', '-e', source]
|
||||
: ['--input-type=module', '-'];
|
||||
const result = execute(args, mode === 'stdin' ? source : undefined);
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stderr).toBe('');
|
||||
expect(result.stdout).toContain('skipping the execution');
|
||||
expect(result.stdout).toContain('function');
|
||||
expect(result.stdout).not.toContain('::error::');
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -9,10 +9,18 @@ import {
|
||||
} from '@jest/globals';
|
||||
import {fileURLToPath} from 'url';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as io from '@actions/io';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const mockTmpDir = jest.fn(os.tmpdir);
|
||||
|
||||
jest.unstable_mockModule('os', () => ({
|
||||
...os,
|
||||
default: {...os, tmpdir: mockTmpDir},
|
||||
tmpdir: mockTmpDir
|
||||
}));
|
||||
|
||||
jest.unstable_mockModule('@actions/exec', () => ({
|
||||
exec: jest.fn()
|
||||
@@ -34,6 +42,7 @@ describe('gpg tests', () => {
|
||||
await io.rmRF(tempDir);
|
||||
await io.mkdirP(tempDir);
|
||||
jest.clearAllMocks();
|
||||
mockTmpDir.mockImplementation(os.tmpdir);
|
||||
(exec.exec as jest.Mock<any>).mockResolvedValue(0);
|
||||
});
|
||||
|
||||
@@ -222,6 +231,77 @@ describe('gpg tests', () => {
|
||||
});
|
||||
|
||||
describe('verifyPackageSignature', () => {
|
||||
describe.each(['long', 'canonical macOS'])('%s TMPDIR', tempDirKind => {
|
||||
afterEach(() => {
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
});
|
||||
|
||||
it.each(['success', 'import failure', 'verification failure'])(
|
||||
'uses a short macOS home or RUNNER_TEMP elsewhere and cleans up after %s',
|
||||
async outcome => {
|
||||
const longRunnerTemp = path.join(
|
||||
tempDir,
|
||||
'long-runner-path-'.repeat(8)
|
||||
);
|
||||
const signaturePath = path.join(tempDir, 'jdk.tar.gz.sig');
|
||||
const expectedParent =
|
||||
process.platform === 'darwin' ? '/tmp' : longRunnerTemp;
|
||||
let gpgHome = '';
|
||||
process.env['RUNNER_TEMP'] = longRunnerTemp;
|
||||
mockTmpDir.mockReturnValue(
|
||||
tempDirKind === 'long'
|
||||
? longRunnerTemp
|
||||
: `/private/var/folders/ab/${'c'.repeat(31)}/T`
|
||||
);
|
||||
fs.mkdirSync(longRunnerTemp, {recursive: true});
|
||||
fs.writeFileSync(signaturePath, 'signature');
|
||||
(tc.downloadTool as jest.Mock<any>).mockResolvedValue(signaturePath);
|
||||
(exec.exec as jest.Mock<any>).mockImplementation(
|
||||
async (_command: string, args: string[]) => {
|
||||
gpgHome = path.join(expectedParent, path.posix.basename(args[1]));
|
||||
expect(args[1]).toBe(gpg.toGpgPath(gpgHome));
|
||||
if (process.platform === 'darwin') {
|
||||
expect(
|
||||
Buffer.byteLength(path.join(gpgHome, 'S.gpg-agent.browser'))
|
||||
).toBeLessThan(104);
|
||||
}
|
||||
expect(
|
||||
fs.readFileSync(path.join(gpgHome, 'public-key-0.asc'), 'utf8')
|
||||
).toBe('public key');
|
||||
if (process.platform !== 'win32') {
|
||||
expect(fs.statSync(gpgHome).mode & 0o777).toBe(0o700);
|
||||
}
|
||||
if (
|
||||
(outcome === 'import failure' && args.includes('--import')) ||
|
||||
(outcome === 'verification failure' &&
|
||||
args.includes('--verify'))
|
||||
) {
|
||||
throw new Error(outcome);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
const verification = gpg.verifyPackageSignature(
|
||||
path.join(tempDir, 'jdk.tar.gz'),
|
||||
'https://example.com/jdk.tar.gz.sig',
|
||||
'public key'
|
||||
);
|
||||
if (outcome === 'success') {
|
||||
await verification;
|
||||
} else {
|
||||
await expect(verification).rejects.toThrow(outcome);
|
||||
}
|
||||
expect(exec.exec).toHaveBeenCalledTimes(
|
||||
outcome === 'import failure' ? 1 : 2
|
||||
);
|
||||
expect(fs.existsSync(gpgHome)).toBe(false);
|
||||
expect(fs.existsSync(signaturePath)).toBe(false);
|
||||
expect(fs.readdirSync(longRunnerTemp)).toEqual([]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('imports bundled key and verifies package', async () => {
|
||||
const publicKeyContent =
|
||||
'-----BEGIN PGP PUBLIC KEY BLOCK-----\ntest\n-----END PGP PUBLIC KEY BLOCK-----';
|
||||
|
||||
52
__tests__/is-main-module.test.ts
Normal file
52
__tests__/is-main-module.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||
import fs from 'fs';
|
||||
import {isMainModule} from '../src/is-main-module.js';
|
||||
|
||||
describe('main module detection', () => {
|
||||
const originalArgv = process.argv;
|
||||
|
||||
beforeEach(() => {
|
||||
process.argv = [process.execPath, 'entrypoint.js'];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = originalArgv;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it.each([undefined, '-'])(
|
||||
'skips filesystem access when argv[1] is %s',
|
||||
entrypoint => {
|
||||
process.argv =
|
||||
entrypoint === undefined
|
||||
? [process.execPath]
|
||||
: [process.execPath, entrypoint];
|
||||
const realpath = jest.spyOn(fs, 'realpathSync');
|
||||
|
||||
expect(isMainModule(import.meta.url)).toBe(false);
|
||||
expect(realpath).not.toHaveBeenCalled();
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['ENOENT', 'ENOTDIR'])(
|
||||
'treats a non-file entrypoint returning %s as an import',
|
||||
code => {
|
||||
jest.spyOn(fs, 'realpathSync').mockImplementation(() => {
|
||||
throw Object.assign(new Error('No file-based entrypoint'), {code});
|
||||
});
|
||||
|
||||
expect(isMainModule(import.meta.url)).toBe(false);
|
||||
}
|
||||
);
|
||||
|
||||
it('propagates unexpected filesystem errors', () => {
|
||||
const error = Object.assign(new Error('Permission denied'), {
|
||||
code: 'EACCES'
|
||||
});
|
||||
jest.spyOn(fs, 'realpathSync').mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
expect(() => isMainModule(import.meta.url)).toThrow(error);
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,7 @@ jest.unstable_mockModule('@actions/core', () => ({
|
||||
|
||||
jest.unstable_mockModule('fs', () => ({
|
||||
default: {
|
||||
...jest.requireActual<typeof import('fs')>('fs'),
|
||||
readFileSync: jest.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -27,6 +27,7 @@ jest.unstable_mockModule('@actions/core', () => ({
|
||||
|
||||
jest.unstable_mockModule('fs', () => ({
|
||||
default: {
|
||||
...jest.requireActual<typeof import('fs')>('fs'),
|
||||
readFileSync: jest.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
35
dist/cleanup/index.js
vendored
35
dist/cleanup/index.js
vendored
@@ -35747,6 +35747,7 @@ __nccwpck_require__.d(__webpack_exports__, {
|
||||
var cleanup_java_core = __nccwpck_require__(3838);
|
||||
// EXTERNAL MODULE: external "fs"
|
||||
var external_fs_ = __nccwpck_require__(9896);
|
||||
var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_);
|
||||
// EXTERNAL MODULE: external "path"
|
||||
var external_path_ = __nccwpck_require__(6928);
|
||||
// EXTERNAL MODULE: external "crypto"
|
||||
@@ -35783,8 +35784,8 @@ function toGpgPath(p) {
|
||||
.replace(/\\/g, '/')
|
||||
.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
||||
}
|
||||
function createGpgHome(prefix) {
|
||||
const gpgHome = fs.mkdtempSync(path.join(util.getTempDir(), prefix));
|
||||
function createGpgHome(prefix, tempDir = util.getTempDir()) {
|
||||
const gpgHome = fs.mkdtempSync(path.join(tempDir, prefix));
|
||||
if (process.platform !== 'win32') {
|
||||
fs.chmodSync(gpgHome, 0o700);
|
||||
}
|
||||
@@ -35843,7 +35844,9 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
const signaturePath = await tc.downloadTool(signatureUrl);
|
||||
let gpgHome;
|
||||
try {
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX);
|
||||
// Both RUNNER_TEMP and TMPDIR can exceed macOS's 104-byte agent socket limit.
|
||||
const tempDir = process.platform === 'darwin' ? '/tmp' : util.getTempDir();
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX, tempDir);
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
@@ -35890,6 +35893,30 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
var constants = __nccwpck_require__(7242);
|
||||
// EXTERNAL MODULE: external "url"
|
||||
var external_url_ = __nccwpck_require__(7016);
|
||||
;// CONCATENATED MODULE: ./src/is-main-module.ts
|
||||
|
||||
|
||||
function isMainModule(moduleUrl) {
|
||||
const entrypoint = process.argv[1];
|
||||
if (!entrypoint || entrypoint === '-') {
|
||||
return false;
|
||||
}
|
||||
let entrypointPath;
|
||||
try {
|
||||
entrypointPath = external_fs_default().realpathSync(entrypoint);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error &&
|
||||
'code' in error &&
|
||||
(error.code === 'ENOENT' || error.code === 'ENOTDIR')) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
// Resolve both paths for runtimes using --preserve-symlinks-main.
|
||||
return entrypointPath === external_fs_default().realpathSync((0,external_url_.fileURLToPath)(moduleUrl));
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/cleanup-java.ts
|
||||
|
||||
|
||||
@@ -35957,7 +35984,7 @@ async function run() {
|
||||
await cleanup_java_removeGpgHome();
|
||||
await ignoreError(saveCaches());
|
||||
}
|
||||
if (process.argv[1] === (0,external_url_.fileURLToPath)(import.meta.url)) {
|
||||
if (isMainModule(import.meta.url)) {
|
||||
run();
|
||||
}
|
||||
else {
|
||||
|
||||
8
dist/setup/220.index.js
vendored
8
dist/setup/220.index.js
vendored
@@ -215,8 +215,8 @@ function toGpgPath(p) {
|
||||
.replace(/\\/g, '/')
|
||||
.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
||||
}
|
||||
function createGpgHome(prefix) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(_util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4(), prefix));
|
||||
function createGpgHome(prefix, tempDir = _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4()) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(tempDir, prefix));
|
||||
if (process.platform !== 'win32') {
|
||||
fs__WEBPACK_IMPORTED_MODULE_0__.chmodSync(gpgHome, 0o700);
|
||||
}
|
||||
@@ -275,7 +275,9 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
|
||||
let gpgHome;
|
||||
try {
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX);
|
||||
// Both RUNNER_TEMP and TMPDIR can exceed macOS's 104-byte agent socket limit.
|
||||
const tempDir = process.platform === 'darwin' ? '/tmp' : _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4();
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX, tempDir);
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
|
||||
8
dist/setup/463.index.js
vendored
8
dist/setup/463.index.js
vendored
@@ -327,8 +327,8 @@ function toGpgPath(p) {
|
||||
.replace(/\\/g, '/')
|
||||
.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
||||
}
|
||||
function createGpgHome(prefix) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(_util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4(), prefix));
|
||||
function createGpgHome(prefix, tempDir = _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4()) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(tempDir, prefix));
|
||||
if (process.platform !== 'win32') {
|
||||
fs__WEBPACK_IMPORTED_MODULE_0__.chmodSync(gpgHome, 0o700);
|
||||
}
|
||||
@@ -387,7 +387,9 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
|
||||
let gpgHome;
|
||||
try {
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX);
|
||||
// Both RUNNER_TEMP and TMPDIR can exceed macOS's 104-byte agent socket limit.
|
||||
const tempDir = process.platform === 'darwin' ? '/tmp' : _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4();
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX, tempDir);
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
|
||||
8
dist/setup/81.index.js
vendored
8
dist/setup/81.index.js
vendored
@@ -302,8 +302,8 @@ function toGpgPath(p) {
|
||||
.replace(/\\/g, '/')
|
||||
.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
||||
}
|
||||
function createGpgHome(prefix) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(_util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4(), prefix));
|
||||
function createGpgHome(prefix, tempDir = _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4()) {
|
||||
const gpgHome = fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(path__WEBPACK_IMPORTED_MODULE_1__.join(tempDir, prefix));
|
||||
if (process.platform !== 'win32') {
|
||||
fs__WEBPACK_IMPORTED_MODULE_0__.chmodSync(gpgHome, 0o700);
|
||||
}
|
||||
@@ -362,7 +362,9 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
|
||||
let gpgHome;
|
||||
try {
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX);
|
||||
// Both RUNNER_TEMP and TMPDIR can exceed macOS's 104-byte agent socket limit.
|
||||
const tempDir = process.platform === 'darwin' ? '/tmp' : _util_js__WEBPACK_IMPORTED_MODULE_6__/* .getTempDir */ .G4();
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX, tempDir);
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
|
||||
27
dist/setup/index.js
vendored
27
dist/setup/index.js
vendored
@@ -36354,6 +36354,30 @@ function configureProblemMatcher(matcherPath) {
|
||||
|
||||
// EXTERNAL MODULE: ./src/toolchain-ids.ts
|
||||
var toolchain_ids = __nccwpck_require__(7083);
|
||||
;// CONCATENATED MODULE: ./src/is-main-module.ts
|
||||
|
||||
|
||||
function isMainModule(moduleUrl) {
|
||||
const entrypoint = process.argv[1];
|
||||
if (!entrypoint || entrypoint === '-') {
|
||||
return false;
|
||||
}
|
||||
let entrypointPath;
|
||||
try {
|
||||
entrypointPath = external_fs_default().realpathSync(entrypoint);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error &&
|
||||
'code' in error &&
|
||||
(error.code === 'ENOENT' || error.code === 'ENOTDIR')) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
// Resolve both paths for runtimes using --preserve-symlinks-main.
|
||||
return entrypointPath === external_fs_default().realpathSync((0,external_url_.fileURLToPath)(moduleUrl));
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/setup-java.ts
|
||||
|
||||
|
||||
@@ -36364,6 +36388,7 @@ var toolchain_ids = __nccwpck_require__(7083);
|
||||
|
||||
|
||||
|
||||
|
||||
async function run() {
|
||||
const versions = setup_java_core/* getMultilineInput */.q3(constants/* INPUT_JAVA_VERSION */.QM);
|
||||
let distributionName = setup_java_core/* getInput */.V4(constants/* INPUT_DISTRIBUTION */.g_);
|
||||
@@ -36480,7 +36505,7 @@ async function validateCacheInput(cache) {
|
||||
function settle(promise) {
|
||||
return promise.then(value => ({ status: 'fulfilled', value }), reason => ({ status: 'rejected', reason }));
|
||||
}
|
||||
if (process.argv[1] === (0,external_url_.fileURLToPath)(import.meta.url)) {
|
||||
if (isMainModule(import.meta.url)) {
|
||||
run();
|
||||
}
|
||||
else {
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -4830,9 +4830,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "3.15.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.1.tgz",
|
||||
"integrity": "sha512-S99WuO3HlhO3XN41EtYUNl9zzXjoJx7QvmipxsJVxtCBT0YHEFy+iOJhjSvrmV12nYhWpZaM8lPHkJm0yUMbag==",
|
||||
"version": "3.15.2",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.2.tgz",
|
||||
"integrity": "sha512-6EuL879VkRA+1Cz578mKMiKvjPNEuk6+r1JaFzoSWejZmtf7xWbIyw1e3KkxlkzTIt9Taw6JBhEppG7utc1P+w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
isJdkCacheEnabled,
|
||||
isJobStatusSuccess
|
||||
} from './util.js';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {isMainModule} from './is-main-module.js';
|
||||
|
||||
async function removeGpgHome() {
|
||||
const gpgHome = core.getState(constants.STATE_GPG_HOME);
|
||||
@@ -77,7 +77,7 @@ export async function run() {
|
||||
await ignoreError(saveCaches());
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
if (isMainModule(import.meta.url)) {
|
||||
run();
|
||||
} else {
|
||||
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
|
||||
|
||||
11
src/gpg.ts
11
src/gpg.ts
@@ -26,8 +26,11 @@ export function toGpgPath(p: string): string {
|
||||
.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
||||
}
|
||||
|
||||
function createGpgHome(prefix: string): string {
|
||||
const gpgHome = fs.mkdtempSync(path.join(util.getTempDir(), prefix));
|
||||
function createGpgHome(
|
||||
prefix: string,
|
||||
tempDir: string = util.getTempDir()
|
||||
): string {
|
||||
const gpgHome = fs.mkdtempSync(path.join(tempDir, prefix));
|
||||
if (process.platform !== 'win32') {
|
||||
fs.chmodSync(gpgHome, 0o700);
|
||||
}
|
||||
@@ -107,7 +110,9 @@ export async function verifyPackageSignature(
|
||||
const signaturePath = await tc.downloadTool(signatureUrl);
|
||||
let gpgHome: string;
|
||||
try {
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX);
|
||||
// Both RUNNER_TEMP and TMPDIR can exceed macOS's 104-byte agent socket limit.
|
||||
const tempDir = process.platform === 'darwin' ? '/tmp' : util.getTempDir();
|
||||
gpgHome = createGpgHome(VERIFY_GPG_HOME_PREFIX, tempDir);
|
||||
} catch (error) {
|
||||
try {
|
||||
await io.rmRF(signaturePath);
|
||||
|
||||
26
src/is-main-module.ts
Normal file
26
src/is-main-module.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import fs from 'fs';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
export function isMainModule(moduleUrl: string): boolean {
|
||||
const entrypoint = process.argv[1];
|
||||
if (!entrypoint || entrypoint === '-') {
|
||||
return false;
|
||||
}
|
||||
|
||||
let entrypointPath: string;
|
||||
try {
|
||||
entrypointPath = fs.realpathSync(entrypoint);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
'code' in error &&
|
||||
(error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Resolve both paths for runtimes using --preserve-symlinks-main.
|
||||
return entrypointPath === fs.realpathSync(fileURLToPath(moduleUrl));
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import {getJavaDistribution} from './distributions/distribution-factory.js';
|
||||
import {JavaInstallerOptions} from './distributions/base-models.js';
|
||||
import {configureProblemMatcher} from './problem-matcher.js';
|
||||
import {validateToolchainIds} from './toolchain-ids.js';
|
||||
import {isMainModule} from './is-main-module.js';
|
||||
|
||||
export async function run() {
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
@@ -172,7 +173,7 @@ function settle<T>(promise: Promise<T>): Promise<PromiseSettledResult<T>> {
|
||||
);
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
if (isMainModule(import.meta.url)) {
|
||||
run();
|
||||
} else {
|
||||
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
|
||||
|
||||
Reference in New Issue
Block a user