5
0
mirror of https://gitea.com/actions/setup-java.git synced 2026-08-07 02:31:20 +00:00

Import Maven signing keys into an isolated GPG home (#1214)

* Isolate Maven signing keys

Import signing keys into an action-owned temporary GPG home, export GNUPGHOME, and remove the owned directory in the post action. Cover import failure, multiple keys and invocations, unrelated keyrings, missing state, and Windows path conversion.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fix cleanup state assertion

Account for isolated GPG-home cleanup when cache saving is disabled.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Update generated action bundles

Apply repository formatting and commit the setup and cleanup bundles produced by the validated Node 24 build.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address isolated GPG home review feedback

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bruno Borges <brborges@microsoft.com>
This commit is contained in:
Julien Dubois
2026-08-05 18:05:36 +02:00
committed by GitHub
parent f4bfb3ddea
commit 634b0f0d18
17 changed files with 715 additions and 309 deletions
+58 -1
View File
@@ -63,6 +63,8 @@ const core = await import('@actions/core');
const cache = await import('@actions/cache');
const {run: cleanup} = await import('../src/cleanup-java.js');
const util = await import('../src/util.js');
const constants = await import('../src/constants.js');
const {GPG_HOME_PREFIX} = await import('../src/gpg.js');
const {registerJdk, buildJdkCacheKey} = await import('../src/jdk-cache.js');
const jdkTempRoots: string[] = [];
@@ -114,11 +116,65 @@ describe('cleanup', () => {
(core.getInput as jest.Mock<any>).mockImplementation((name: string) => {
return name === 'cache' ? 'gradle' : '';
});
await cleanup();
expect(spyCacheSave).toHaveBeenCalled();
expect(spyWarning).not.toHaveBeenCalled();
});
it('removes the isolated GPG home without touching unrelated key material', async () => {
const tempDir = util.getTempDir();
fs.mkdirSync(tempDir, {recursive: true});
const gpgHome = fs.mkdtempSync(path.join(tempDir, GPG_HOME_PREFIX));
const unrelatedGpgHome = fs.mkdtempSync(
path.join(tempDir, 'user-gpg-home-')
);
fs.writeFileSync(
path.join(unrelatedGpgHome, 'private.key'),
'pre-existing'
);
(core.getInput as jest.Mock<any>).mockReturnValue('');
(core.getState as jest.Mock<any>).mockImplementation((name: string) =>
name === constants.STATE_GPG_HOME ? gpgHome : ''
);
await cleanup();
expect(fs.existsSync(gpgHome)).toBe(false);
expect(
fs.readFileSync(path.join(unrelatedGpgHome, 'private.key'), 'utf8')
).toBe('pre-existing');
fs.rmSync(unrelatedGpgHome, {recursive: true, force: true});
});
it('makes repeated cleanup of the same GPG home idempotent', async () => {
const tempDir = util.getTempDir();
fs.mkdirSync(tempDir, {recursive: true});
const gpgHome = fs.mkdtempSync(path.join(tempDir, GPG_HOME_PREFIX));
(core.getInput as jest.Mock<any>).mockReturnValue('');
(core.getState as jest.Mock<any>).mockImplementation((name: string) =>
name === constants.STATE_GPG_HOME ? gpgHome : ''
);
await cleanup();
await cleanup();
expect(fs.existsSync(gpgHome)).toBe(false);
expect(core.setFailed).not.toHaveBeenCalled();
});
it('skips GPG cleanup when no home was persisted', async () => {
(core.getInput as jest.Mock<any>).mockReturnValue('');
(core.getState as jest.Mock<any>).mockReturnValue('');
await cleanup();
expect(spyInfo).not.toHaveBeenCalledWith(
'Removing private key from isolated GPG home'
);
expect(core.setFailed).not.toHaveBeenCalled();
});
it('does not fail even though the save process throws error', async () => {
spyCacheSave.mockImplementation((paths: string[], key: string) =>
Promise.reject(new Error('Unexpected error'))
@@ -148,7 +204,8 @@ describe('cleanup', () => {
await cleanup();
expect(spyCacheSave).not.toHaveBeenCalled();
expect(core.getState).not.toHaveBeenCalled();
expect(core.getState).toHaveBeenCalledTimes(1);
expect(core.getState).toHaveBeenCalledWith(constants.STATE_GPG_HOME);
expect(spyInfo).toHaveBeenCalledWith(
'Cache saving is skipped because cache-read-only is enabled.'
);