Files
setup-java/src/cleanup-java.ts
Julien Dubois 634b0f0d18 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>
2026-08-05 12:05:36 -04:00

86 lines
2.3 KiB
TypeScript

import * as core from '@actions/core';
import * as gpg from './gpg.js';
import * as constants from './constants.js';
import {
getBooleanInput,
isJdkCacheEnabled,
isJobStatusSuccess
} from './util.js';
import {fileURLToPath} from 'url';
async function removeGpgHome() {
const gpgHome = core.getState(constants.STATE_GPG_HOME);
if (!gpgHome) {
return;
}
core.info('Removing private key from isolated GPG home');
try {
await gpg.removeGpgHome(gpgHome);
} catch (error) {
core.setFailed(
`Failed to remove isolated GPG home due to: ${(error as Error).message}`
);
}
}
/**
* Check given input and run a save process for the specified package manager
* @returns Promise that will be resolved when the save process finishes
*/
async function saveCaches() {
const jobStatus = isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
const cacheJdk = isJdkCacheEnabled(cache);
if (!jobStatus || (!cache && !cacheJdk)) {
return;
}
if (getBooleanInput(constants.INPUT_CACHE_READ_ONLY, false)) {
core.info('Cache saving is skipped because cache-read-only is enabled.');
return;
}
const saves: Promise<void>[] = [];
if (cache) {
const {save} = await import('./cache.js');
saves.push(save(cache));
}
if (cacheJdk) {
const {saveJdkCaches} = await import('./jdk-cache.js');
const {saveJdkResolutionCaches} = await import('./jdk-resolution-cache.js');
saves.push(saveJdkCaches());
saves.push(saveJdkResolutionCaches());
}
await Promise.all(saves);
}
/**
* The save process is best-effort, and it should not make the workflow fail
* even though this process throws an error.
* @param promise the promise to ignore error from
* @returns Promise that will ignore error reported by the given promise
*/
async function ignoreError(promise: Promise<void>) {
return new Promise(resolve => {
promise
.catch(error => {
core.warning(error);
resolve(void 0);
})
.then(resolve);
});
}
export async function run() {
await removeGpgHome();
await ignoreError(saveCaches());
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
run();
} else {
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
core.info('the script is loaded as a module, so skipping the execution');
}