From 4bd0bfb1af29147c3c703aa7e1608dce5e4e99b1 Mon Sep 17 00:00:00 2001 From: Soren Mathiasen Date: Fri, 12 Nov 2021 12:32:25 +0100 Subject: [PATCH] fix: check if cert is in keystore when using the shared cache the cert is already in the keystore --- dist/setup/index.js | 20 ++++++++++++++++---- src/maven.ts | 25 ++++++++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b9e6727f..6ebcf09a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -11102,15 +11102,27 @@ function setupMaven(opts) { params.push('-cacerts'); } try { - yield exec.exec(path.join(opts.javaPath, 'bin/keytool'), params.concat([ + const certexists = yield exec.exec(path.join(opts.javaPath, 'bin/keytool'), [ + '-list', '-storepass', 'changeit', '-noprompt', '-alias', 'mycert', - '-file', - rootCaPath - ])); + '-keystore', + `${opts.javaPath}/jre/lib/security/cacerts` + ]); + if (certexists !== 0) { + yield exec.exec(path.join(opts.javaPath, 'bin/keytool'), params.concat([ + '-storepass', + 'changeit', + '-noprompt', + '-alias', + 'mycert', + '-file', + rootCaPath + ])); + } } catch (e) { core.warning(`keytool return an error: ${e.message}`); diff --git a/src/maven.ts b/src/maven.ts index 244b94f3..59365040 100644 --- a/src/maven.ts +++ b/src/maven.ts @@ -76,18 +76,33 @@ export async function setupMaven(opts: MavenOpts): Promise { } try { - await exec.exec( + const certexists = await exec.exec( path.join(opts.javaPath, 'bin/keytool'), - params.concat([ + [ + '-list', '-storepass', 'changeit', '-noprompt', '-alias', 'mycert', - '-file', - rootCaPath - ]) + '-keystore', + `${opts.javaPath}/jre/lib/security/cacerts` + ] ); + if (certexists !== 0) { + await exec.exec( + path.join(opts.javaPath, 'bin/keytool'), + params.concat([ + '-storepass', + 'changeit', + '-noprompt', + '-alias', + 'mycert', + '-file', + rootCaPath + ]) + ); + } } catch (e) { core.warning(`keytool return an error: ${(e as Error).message}`); }