Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 553d427

Browse files
afooruslan-bikkinin
authored andcommitted
add privateKey support for release-cordova (#524)
* add privateKey support for release-cordova * Remove redundant warnings * Fix possible inclusion of signature to update when it shouldn't be * Add warning in case of cli couldn't delete redundate signature file * Extract deletion of previous signature into method * Minor refactor
1 parent 925f10f commit 553d427

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

cli/script/command-parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ var argv = yargs.usage(USAGE_PREFIX + " <command>")
398398
.option("description", { alias: "des", default: null, demand: false, description: "Description of the changes made to the app in this release", type: "string" })
399399
.option("disabled", { alias: "x", default: false, demand: false, description: "Specifies whether this release should be immediately downloadable", type: "boolean" })
400400
.option("mandatory", { alias: "m", default: false, demand: false, description: "Specifies whether this release should be considered mandatory", type: "boolean" })
401-
.option("privateKeyPath", { alias: "k", default: false, demand: false, description: "Specifies the location of a RSA private key to sign the release with. " + chalk.yellow("NOTICE:") + " use it for react native applications only, client SDK on other platforms will be ignoring signature verification for now!", type: "string" })
401+
.option("privateKeyPath", { alias: "k", default: false, demand: false, description: "Specifies the location of a RSA private key to sign the release with", type: "string" })
402402
.option("noDuplicateReleaseError", { default: false, demand: false, description: "When this flag is set, releasing a package that is identical to the latest release will produce a warning instead of an error", type: "boolean" })
403403
.option("rollout", { alias: "r", default: "100%", demand: false, description: "Percentage of users this release should be available to", type: "string" })
404404
.check((argv: any, aliases: { [aliases: string]: string }): any => { return checkValidReleaseOptions(argv); });
@@ -416,6 +416,7 @@ var argv = yargs.usage(USAGE_PREFIX + " <command>")
416416
.option("description", { alias: "des", default: null, demand: false, description: "Description of the changes made to the app in this release", type: "string" })
417417
.option("disabled", { alias: "x", default: false, demand: false, description: "Specifies whether this release should be immediately downloadable", type: "boolean" })
418418
.option("mandatory", { alias: "m", default: false, demand: false, description: "Specifies whether this release should be considered mandatory", type: "boolean" })
419+
.option("privateKeyPath", { alias: "k", default: false, demand: false, description: "Specifies the location of a RSA private key to sign the release with", type: "string" })
419420
.option("noDuplicateReleaseError", { default: false, demand: false, description: "When this flag is set, releasing a package that is identical to the latest release will produce a warning instead of an error", type: "boolean" })
420421
.option("rollout", { alias: "r", default: "100%", demand: false, description: "Percentage of users this release should be immediately available to", type: "string" })
421422
.option("targetBinaryVersion", { alias: "t", default: null, demand: false, description: "Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3). If omitted, the release will target the exact version specified in the config.xml file.", type: "string" })
@@ -831,6 +832,7 @@ function createCommand(): cli.ICommand {
831832
releaseCordovaCommand.rollout = getRolloutValue(argv["rollout"]);
832833
releaseCordovaCommand.appStoreVersion = argv["targetBinaryVersion"];
833834
releaseCordovaCommand.isReleaseBuildType = argv["isReleaseBuildType"];
835+
releaseCordovaCommand.privateKeyPath = argv["privateKeyPath"];
834836
}
835837
break;
836838

cli/script/release-hooks/signing.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,56 @@ var rimraf = require("rimraf");
1010
import AccountManager = require("code-push");
1111

1212
var CURRENT_CLAIM_VERSION: string = "1.0.0";
13-
var METADATA_FILE_NAME: string = ".codepushrelease"
13+
var METADATA_FILE_NAME: string = ".codepushrelease";
1414

1515
interface CodeSigningClaims {
1616
claimVersion: string;
1717
contentHash: string;
1818
}
1919

20+
const deletePreviousSignatureIfExists = (package: string): q.Promise<any> => {
21+
let signatureFilePath: string = path.join(package, METADATA_FILE_NAME);
22+
let prevSignatureExists: boolean = true;
23+
try {
24+
fs.accessSync(signatureFilePath, fs.R_OK);
25+
} catch (err) {
26+
if (err.code === "ENOENT") {
27+
prevSignatureExists = false;
28+
} else {
29+
return q.reject(new Error(
30+
`Could not delete previous release signature at ${signatureFilePath}.
31+
Please, check your access rights.`)
32+
);
33+
}
34+
}
35+
36+
if (prevSignatureExists) {
37+
console.log(`Deleting previous release signature at ${signatureFilePath}`);
38+
rimraf.sync(signatureFilePath);
39+
}
40+
41+
return q.resolve(<void>null);
42+
}
43+
2044
var sign: cli.ReleaseHook = (currentCommand: cli.IReleaseCommand, originalCommand: cli.IReleaseCommand, sdk: AccountManager): q.Promise<cli.IReleaseCommand> => {
45+
2146
if (!currentCommand.privateKeyPath) {
22-
return q.resolve<cli.IReleaseCommand>(currentCommand);
47+
if (fs.lstatSync(currentCommand.package).isDirectory()) {
48+
// If new update wasn't signed, but signature file for some reason still appears in the package directory - delete it
49+
return deletePreviousSignatureIfExists(currentCommand.package).then(() => {
50+
return q.resolve<cli.IReleaseCommand>(currentCommand);
51+
});
52+
} else {
53+
return q.resolve<cli.IReleaseCommand>(currentCommand);
54+
}
2355
}
2456

25-
var privateKey: Buffer;
26-
var signatureFilePath: string;
57+
let privateKey: Buffer;
58+
let signatureFilePath: string;
2759

2860
return q(<void>null)
2961
.then(() => {
62+
signatureFilePath = path.join(currentCommand.package, METADATA_FILE_NAME);
3063
try {
3164
privateKey = fs.readFileSync(currentCommand.privateKeyPath);
3265
} catch (err) {
@@ -45,26 +78,9 @@ var sign: cli.ReleaseHook = (currentCommand: cli.IReleaseCommand, originalComman
4578
currentCommand.package = outputFolderPath;
4679
}
4780

48-
signatureFilePath = path.join(currentCommand.package, METADATA_FILE_NAME);
49-
var prevSignatureExists = true;
50-
try {
51-
fs.accessSync(signatureFilePath, fs.F_OK);
52-
} catch (err) {
53-
if (err.code === "ENOENT") {
54-
prevSignatureExists = false;
55-
} else {
56-
return q.reject<string>(new Error(
57-
`Could not delete previous release signature at ${signatureFilePath}.
58-
Please, check your access rights.`)
59-
);
60-
}
61-
}
62-
63-
if (prevSignatureExists) {
64-
console.log(`Deleting previous release signature at ${signatureFilePath}`);
65-
rimraf.sync(signatureFilePath);
66-
}
67-
81+
return deletePreviousSignatureIfExists(currentCommand.package);
82+
})
83+
.then(() => {
6884
return hashUtils.generatePackageHashFromDirectory(currentCommand.package, path.join(currentCommand.package, ".."));
6985
})
7086
.then((hash: string) => {

0 commit comments

Comments
 (0)