Skip to content

Commit

Permalink
feat: Make key password optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kceballos committed Feb 27, 2020
1 parent 204ae17 commit 8fa256c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
25 changes: 15 additions & 10 deletions lib/signing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`, [
Expand All @@ -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;
});
}
Expand Down
35 changes: 22 additions & 13 deletions src/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function signApkFile(
signingKeyFile: string,
alias: string,
keyStorePassword: string,
keyPassword: string
keyPassword?: string
): Promise<string> {

core.debug("Zipaligning APK file");
Expand Down Expand Up @@ -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");
Expand All @@ -66,19 +71,23 @@ export async function signAabFile(
signingKeyFile: string,
alias: string,
keyStorePassword: string,
keyPassword: string
keyPassword?: string,
): Promise<string> {
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
}

0 comments on commit 8fa256c

Please sign in to comment.