From 8fa256cc0c30e7f49eea96e97a4ca5fd8e3b4374 Mon Sep 17 00:00:00 2001 From: kceballos Date: Wed, 26 Feb 2020 15:44:44 -0800 Subject: [PATCH] feat: Make key password optional --- README.md | 2 +- action.yml | 2 +- lib/signing.js | 25 +++++++++++++++---------- src/signing.ts | 35 ++++++++++++++++++++++------------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index d968eddb..ddc54b0b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Then copy the contents of the `.txt` file to your GH secrets ### `keyPassword` -**Required:** The private key password for your signing keystore +**Optional:** The private key password for your signing keystore ## Outputs diff --git a/action.yml b/action.yml index f064b36d..5bda3c5f 100644 --- a/action.yml +++ b/action.yml @@ -19,7 +19,7 @@ inputs: required: true keyPassword: description: 'The password for the key' - required: true + required: false outputs: signedReleaseFile: description: 'The signed release APK or AAB file' diff --git a/lib/signing.js b/lib/signing.js index 79c98b4c..ecad2e69 100644 --- a/lib/signing.js +++ b/lib/signing.js @@ -45,15 +45,18 @@ function signApkFile(apkFile, signingKeyFile, alias, keyStorePassword, keyPasswo core.debug(`Found 'apksigner' @ ${apkSigner}`); // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk const signedApkFile = apkFile.replace('.apk', '-signed.apk'); - yield exec.exec(`"${apkSigner}"`, [ + const args = [ 'sign', '--ks', signingKeyFile, '--ks-key-alias', alias, '--ks-pass', `pass:${keyStorePassword}`, - '--key-pass', `pass:${keyPassword}`, - '--out', signedApkFile, - alignedApkFile - ]); + '--out', signedApkFile + ]; + if (keyPassword) { + args.push('--key-pass', `pass:${keyPassword}`); + } + args.push(alignedApkFile); + yield exec.exec(`"${apkSigner}"`, args); // Verify core.debug("Verifying Signed APK"); yield exec.exec(`"${apkSigner}"`, [ @@ -69,13 +72,15 @@ function signAabFile(aabFile, signingKeyFile, alias, keyStorePassword, keyPasswo core.debug("Signing AAB file"); const jarSignerPath = yield io.which('jarsigner', true); core.debug(`Found 'jarsigner' @ ${jarSignerPath}`); - yield exec.exec(`"${jarSignerPath}"`, [ + const args = [ '-keystore', signingKeyFile, '-storepass', keyStorePassword, - '-keypass', keyPassword, - aabFile, - alias - ]); + ]; + if (keyPassword) { + args.push('-keypass', keyPassword); + } + args.push(aabFile, alias); + yield exec.exec(`"${jarSignerPath}"`, args); return aabFile; }); } diff --git a/src/signing.ts b/src/signing.ts index 3ad3d8a6..d92ce3d6 100644 --- a/src/signing.ts +++ b/src/signing.ts @@ -9,7 +9,7 @@ export async function signApkFile( signingKeyFile: string, alias: string, keyStorePassword: string, - keyPassword: string + keyPassword?: string ): Promise { core.debug("Zipaligning APK file"); @@ -41,15 +41,20 @@ export async function signApkFile( // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk const signedApkFile = apkFile.replace('.apk', '-signed.apk'); - await exec.exec(`"${apkSigner}"`, [ + const args = [ 'sign', '--ks', signingKeyFile, '--ks-key-alias', alias, '--ks-pass', `pass:${keyStorePassword}`, - '--key-pass', `pass:${keyPassword}`, - '--out', signedApkFile, - alignedApkFile - ]); + '--out', signedApkFile + ]; + + if (keyPassword) { + args.push('--key-pass', `pass:${keyPassword}`); + } + args.push(alignedApkFile); + + await exec.exec(`"${apkSigner}"`, args); // Verify core.debug("Verifying Signed APK"); @@ -66,19 +71,23 @@ export async function signAabFile( signingKeyFile: string, alias: string, keyStorePassword: string, - keyPassword: string + keyPassword?: string, ): Promise { core.debug("Signing AAB file"); const jarSignerPath = await io.which('jarsigner', true); core.debug(`Found 'jarsigner' @ ${jarSignerPath}`); - - await exec.exec(`"${jarSignerPath}"`, [ + const args = [ '-keystore', signingKeyFile, '-storepass', keyStorePassword, - '-keypass', keyPassword, - aabFile, - alias - ]); + ]; + + if (keyPassword) { + args.push('-keypass', keyPassword); + } + + args.push(aabFile, alias); + + await exec.exec(`"${jarSignerPath}"`, args); return aabFile } \ No newline at end of file