Merge pull request #3 from kceb/master

feat: Make key password optional
This commit is contained in:
Drew Heavner
2020-04-01 13:58:04 -04:00
committed by GitHub
4 changed files with 39 additions and 25 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ Then copy the contents of the `.txt` file to your GH secrets
### `keyPassword` ### `keyPassword`
**Required:** The private key password for your signing keystore **Optional:** The private key password for your signing keystore
## Outputs ## Outputs
+1 -1
View File
@@ -19,7 +19,7 @@ inputs:
required: true required: true
keyPassword: keyPassword:
description: 'The password for the key' description: 'The password for the key'
required: true required: false
outputs: outputs:
signedReleaseFile: signedReleaseFile:
description: 'The signed release APK or AAB file' description: 'The signed release APK or AAB file'
+15 -10
View File
@@ -45,15 +45,18 @@ function signApkFile(apkFile, signingKeyFile, alias, keyStorePassword, keyPasswo
core.debug(`Found 'apksigner' @ ${apkSigner}`); core.debug(`Found 'apksigner' @ ${apkSigner}`);
// apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
const signedApkFile = apkFile.replace('.apk', '-signed.apk'); const signedApkFile = apkFile.replace('.apk', '-signed.apk');
yield exec.exec(`"${apkSigner}"`, [ const args = [
'sign', 'sign',
'--ks', signingKeyFile, '--ks', signingKeyFile,
'--ks-key-alias', alias, '--ks-key-alias', alias,
'--ks-pass', `pass:${keyStorePassword}`, '--ks-pass', `pass:${keyStorePassword}`,
'--key-pass', `pass:${keyPassword}`, '--out', signedApkFile
'--out', signedApkFile, ];
alignedApkFile if (keyPassword) {
]); args.push('--key-pass', `pass:${keyPassword}`);
}
args.push(alignedApkFile);
yield exec.exec(`"${apkSigner}"`, args);
// Verify // Verify
core.debug("Verifying Signed APK"); core.debug("Verifying Signed APK");
yield exec.exec(`"${apkSigner}"`, [ yield exec.exec(`"${apkSigner}"`, [
@@ -69,13 +72,15 @@ function signAabFile(aabFile, signingKeyFile, alias, keyStorePassword, keyPasswo
core.debug("Signing AAB file"); core.debug("Signing AAB file");
const jarSignerPath = yield io.which('jarsigner', true); const jarSignerPath = yield io.which('jarsigner', true);
core.debug(`Found 'jarsigner' @ ${jarSignerPath}`); core.debug(`Found 'jarsigner' @ ${jarSignerPath}`);
yield exec.exec(`"${jarSignerPath}"`, [ const args = [
'-keystore', signingKeyFile, '-keystore', signingKeyFile,
'-storepass', keyStorePassword, '-storepass', keyStorePassword,
'-keypass', keyPassword, ];
aabFile, if (keyPassword) {
alias args.push('-keypass', keyPassword);
]); }
args.push(aabFile, alias);
yield exec.exec(`"${jarSignerPath}"`, args);
return aabFile; return aabFile;
}); });
} }
+22 -13
View File
@@ -9,7 +9,7 @@ export async function signApkFile(
signingKeyFile: string, signingKeyFile: string,
alias: string, alias: string,
keyStorePassword: string, keyStorePassword: string,
keyPassword: string keyPassword?: string
): Promise<string> { ): Promise<string> {
core.debug("Zipaligning APK file"); 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 // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
const signedApkFile = apkFile.replace('.apk', '-signed.apk'); const signedApkFile = apkFile.replace('.apk', '-signed.apk');
await exec.exec(`"${apkSigner}"`, [ const args = [
'sign', 'sign',
'--ks', signingKeyFile, '--ks', signingKeyFile,
'--ks-key-alias', alias, '--ks-key-alias', alias,
'--ks-pass', `pass:${keyStorePassword}`, '--ks-pass', `pass:${keyStorePassword}`,
'--key-pass', `pass:${keyPassword}`, '--out', signedApkFile
'--out', signedApkFile, ];
alignedApkFile
]); if (keyPassword) {
args.push('--key-pass', `pass:${keyPassword}`);
}
args.push(alignedApkFile);
await exec.exec(`"${apkSigner}"`, args);
// Verify // Verify
core.debug("Verifying Signed APK"); core.debug("Verifying Signed APK");
@@ -66,19 +71,23 @@ export async function signAabFile(
signingKeyFile: string, signingKeyFile: string,
alias: string, alias: string,
keyStorePassword: string, keyStorePassword: string,
keyPassword: string keyPassword?: string,
): Promise<string> { ): Promise<string> {
core.debug("Signing AAB file"); core.debug("Signing AAB file");
const jarSignerPath = await io.which('jarsigner', true); const jarSignerPath = await io.which('jarsigner', true);
core.debug(`Found 'jarsigner' @ ${jarSignerPath}`); core.debug(`Found 'jarsigner' @ ${jarSignerPath}`);
const args = [
await exec.exec(`"${jarSignerPath}"`, [
'-keystore', signingKeyFile, '-keystore', signingKeyFile,
'-storepass', keyStorePassword, '-storepass', keyStorePassword,
'-keypass', keyPassword, ];
aabFile,
alias if (keyPassword) {
]); args.push('-keypass', keyPassword);
}
args.push(aabFile, alias);
await exec.exec(`"${jarSignerPath}"`, args);
return aabFile return aabFile
} }