Visitar URL original
Stop GPG agent before removing signature-verification home (#1273) · actions/setup-java@a78ec39 · GitHub
Skip to content

Commit a78ec39

Browse files
Copilotbrunoborges
andauthored
Stop GPG agent before removing signature-verification home (#1273)
* Initial plan * Stop GPG agent before verification home cleanup Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 97c5a5e commit a78ec39

6 files changed

Lines changed: 53 additions & 16 deletions

File tree

‎__tests__/gpg.test.ts‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ describe('gpg tests', () => {
236236
process.env['RUNNER_TEMP'] = tempDir;
237237
});
238238

239-
it.each(['success', 'import failure', 'verification failure'])(
239+
it.each([
240+
'success',
241+
'import failure',
242+
'verification failure',
243+
'gpgconf unavailable'
244+
])(
240245
'uses a short macOS home or RUNNER_TEMP elsewhere and cleans up after %s',
241246
async outcome => {
242247
const longRunnerTemp = path.join(
@@ -257,9 +262,16 @@ describe('gpg tests', () => {
257262
fs.writeFileSync(signaturePath, 'signature');
258263
(tc.downloadTool as jest.Mock<any>).mockResolvedValue(signaturePath);
259264
(exec.exec as jest.Mock<any>).mockImplementation(
260-
async (_command: string, args: string[]) => {
265+
async (command: string, args: string[]) => {
261266
gpgHome = path.join(expectedParent, path.posix.basename(args[1]));
262267
expect(args[1]).toBe(gpg.toGpgPath(gpgHome));
268+
if (command === 'gpgconf') {
269+
expect(fs.existsSync(gpgHome)).toBe(true);
270+
if (outcome === 'gpgconf unavailable') {
271+
throw new Error('gpgconf unavailable');
272+
}
273+
return 0;
274+
}
263275
if (process.platform === 'darwin') {
264276
expect(
265277
Buffer.byteLength(path.join(gpgHome, 'S.gpg-agent.browser'))
@@ -287,13 +299,18 @@ describe('gpg tests', () => {
287299
'https://example.com/jdk.tar.gz.sig',
288300
'public key'
289301
);
290-
if (outcome === 'success') {
302+
if (outcome === 'success' || outcome === 'gpgconf unavailable') {
291303
await verification;
292304
} else {
293305
await expect(verification).rejects.toThrow(outcome);
294306
}
295307
expect(exec.exec).toHaveBeenCalledTimes(
296-
outcome === 'import failure' ? 1 : 2
308+
outcome === 'import failure' ? 2 : 3
309+
);
310+
expect(exec.exec).toHaveBeenLastCalledWith(
311+
'gpgconf',
312+
['--homedir', gpg.toGpgPath(gpgHome), '--kill', 'gpg-agent'],
313+
{silent: true, ignoreReturnCode: true}
297314
);
298315
expect(fs.existsSync(gpgHome)).toBe(false);
299316
expect(fs.existsSync(signaturePath)).toBe(false);
@@ -368,7 +385,7 @@ describe('gpg tests', () => {
368385
],
369386
expect.objectContaining({silent: true})
370387
);
371-
expect(exec.exec).toHaveBeenCalledTimes(2);
388+
expect(exec.exec).toHaveBeenCalledTimes(3);
372389
});
373390
});
374391
});

‎dist/cleanup/index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35832,13 +35832,16 @@ async function removeGpgHome(gpgHome) {
3583235832
if (!external_fs_.existsSync(resolvedGpgHome)) {
3583335833
return;
3583435834
}
35835+
await stopGpgAgent(resolvedGpgHome);
35836+
await lib_io/* rmRF */.Yz(resolvedGpgHome);
35837+
}
35838+
async function stopGpgAgent(gpgHome) {
3583535839
try {
35836-
await lib_exec/* exec */.m('gpgconf', ['--homedir', toGpgPath(resolvedGpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
35840+
await lib_exec/* exec */.m('gpgconf', ['--homedir', toGpgPath(gpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
3583735841
}
3583835842
catch {
3583935843
// gpgconf may be unavailable, but directory removal must still be attempted.
3584035844
}
35841-
await lib_io/* rmRF */.Yz(resolvedGpgHome);
3584235845
}
3584335846
async function verifyPackageSignature(archivePath, signatureUrl, publicKeyContent) {
3584435847
const signaturePath = await tc.downloadTool(signatureUrl);
@@ -35884,6 +35887,7 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
3588435887
], options);
3588535888
}
3588635889
finally {
35890+
await stopGpgAgent(gpgHome);
3588735891
await io.rmRF(signaturePath);
3588835892
await io.rmRF(gpgHome);
3588935893
}

‎dist/setup/220.index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,16 @@ async function removeGpgHome(gpgHome) {
263263
if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(resolvedGpgHome)) {
264264
return;
265265
}
266+
await stopGpgAgent(resolvedGpgHome);
267+
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
268+
}
269+
async function stopGpgAgent(gpgHome) {
266270
try {
267-
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(resolvedGpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
271+
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(gpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
268272
}
269273
catch {
270274
// gpgconf may be unavailable, but directory removal must still be attempted.
271275
}
272-
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
273276
}
274277
async function verifyPackageSignature(archivePath, signatureUrl, publicKeyContent) {
275278
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
@@ -315,6 +318,7 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
315318
], options);
316319
}
317320
finally {
321+
await stopGpgAgent(gpgHome);
318322
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(signaturePath);
319323
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(gpgHome);
320324
}

‎dist/setup/463.index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,16 @@ async function removeGpgHome(gpgHome) {
375375
if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(resolvedGpgHome)) {
376376
return;
377377
}
378+
await stopGpgAgent(resolvedGpgHome);
379+
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
380+
}
381+
async function stopGpgAgent(gpgHome) {
378382
try {
379-
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(resolvedGpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
383+
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(gpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
380384
}
381385
catch {
382386
// gpgconf may be unavailable, but directory removal must still be attempted.
383387
}
384-
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
385388
}
386389
async function verifyPackageSignature(archivePath, signatureUrl, publicKeyContent) {
387390
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
@@ -427,6 +430,7 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
427430
], options);
428431
}
429432
finally {
433+
await stopGpgAgent(gpgHome);
430434
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(signaturePath);
431435
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(gpgHome);
432436
}

‎dist/setup/81.index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,16 @@ async function removeGpgHome(gpgHome) {
350350
if (!fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(resolvedGpgHome)) {
351351
return;
352352
}
353+
await stopGpgAgent(resolvedGpgHome);
354+
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
355+
}
356+
async function stopGpgAgent(gpgHome) {
353357
try {
354-
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(resolvedGpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
358+
await _actions_exec__WEBPACK_IMPORTED_MODULE_4__/* .exec */ .m('gpgconf', ['--homedir', toGpgPath(gpgHome), '--kill', 'gpg-agent'], { silent: true, ignoreReturnCode: true });
355359
}
356360
catch {
357361
// gpgconf may be unavailable, but directory removal must still be attempted.
358362
}
359-
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(resolvedGpgHome);
360363
}
361364
async function verifyPackageSignature(archivePath, signatureUrl, publicKeyContent) {
362365
const signaturePath = await _actions_tool_cache__WEBPACK_IMPORTED_MODULE_5__/* .downloadTool */ .bq(signatureUrl);
@@ -402,6 +405,7 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
402405
], options);
403406
}
404407
finally {
408+
await stopGpgAgent(gpgHome);
405409
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(signaturePath);
406410
await _actions_io__WEBPACK_IMPORTED_MODULE_3__/* .rmRF */ .Yz(gpgHome);
407411
}

‎src/gpg.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,20 @@ export async function removeGpgHome(gpgHome: string): Promise<void> {
8989
return;
9090
}
9191

92+
await stopGpgAgent(resolvedGpgHome);
93+
await io.rmRF(resolvedGpgHome);
94+
}
95+
96+
async function stopGpgAgent(gpgHome: string): Promise<void> {
9297
try {
9398
await exec.exec(
9499
'gpgconf',
95-
['--homedir', toGpgPath(resolvedGpgHome), '--kill', 'gpg-agent'],
100+
['--homedir', toGpgPath(gpgHome), '--kill', 'gpg-agent'],
96101
{silent: true, ignoreReturnCode: true}
97102
);
98103
} catch {
99104
// gpgconf may be unavailable, but directory removal must still be attempted.
100105
}
101-
102-
await io.rmRF(resolvedGpgHome);
103106
}
104107

105108
export async function verifyPackageSignature(
@@ -160,6 +163,7 @@ export async function verifyPackageSignature(
160163
options
161164
);
162165
} finally {
166+
await stopGpgAgent(gpgHome);
163167
await io.rmRF(signaturePath);
164168
await io.rmRF(gpgHome);
165169
}

0 commit comments

Comments
 (0)