Skip to content

Commit 9b60518

Browse files
committed
feat: retry code sign if failed due to network failure
Close #1414
1 parent 624311b commit 9b60518

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"path-sort": "^0.1.0",
8989
"source-map-support": "^0.4.14",
9090
"ts-babel": "^3.0.0",
91-
"tslint": "^4.5.1",
91+
"tslint": "^5.0.0",
9292
"typescript": "^2.2.2",
9393
"typescript-json-schema": "0.11.0",
9494
"whitespace": "^2.1.0",

packages/electron-builder/src/util/readPackageJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Ajv from "ajv"
2+
import { debug } from "electron-builder-util"
23
import { log, warn } from "electron-builder-util/out/log"
34
import { readFile, readJson } from "fs-extra-p"
45
import { safeLoad } from "js-yaml"
@@ -148,7 +149,8 @@ export async function validateConfig(config: Config) {
148149

149150
const validator = await validatorPromise
150151
if (!validator(config)) {
151-
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2) + "\n\nRaw validation errors: " + JSON.stringify(validator.errors, null, 2))
152+
debug(JSON.stringify(validator.errors, null, 2))
153+
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2))
152154
}
153155
}
154156

packages/electron-builder/src/winPackager.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BluebirdPromise from "bluebird-lst"
22
import { DIR_TARGET, Platform, Target } from "electron-builder-core"
33
import { asArray, exec, Lazy, use } from "electron-builder-util"
4-
import { log } from "electron-builder-util/out/log"
4+
import { log, warn } from "electron-builder-util/out/log"
55
import { close, open, read, readFile, rename } from "fs-extra-p"
66
import * as forge from "node-forge"
77
import * as path from "path"
@@ -196,8 +196,22 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
196196
}
197197

198198
//noinspection JSMethodCanBeStatic
199-
protected doSign(options: SignOptions): Promise<any> {
200-
return sign(options)
199+
protected async doSign(options: SignOptions) {
200+
for (let i = 0; i < 3; i++) {
201+
try {
202+
await sign(options)
203+
break
204+
}
205+
catch (e) {
206+
// https://github.com/electron-userland/electron-builder/issues/1414
207+
const message = e.message
208+
if (message != null && message.includes("Couldn't resolve host name")) {
209+
warn(`Cannot sign, attempt ${i + 1}: ${message}`)
210+
continue
211+
}
212+
throw e
213+
}
214+
}
201215
}
202216

203217
async signAndEditResources(file: string) {

packages/electron-builder/src/windowsCodeSign.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,6 @@ async function spawnSign(options: SignOptions, inputPath: string, outputPath: st
136136
return await exec(await getToolPath(), args)
137137
}
138138

139-
// async function verify(options: any) {
140-
// const out = await exec(await getToolPath(options), [
141-
// "verify",
142-
// "-in", options.path,
143-
// "-require-leaf-hash", options.hash
144-
// ])
145-
// if (out.includes("No signature found.")) {
146-
// throw new Error("No signature found")
147-
// }
148-
// else if (out.includes("Leaf hash match: failed")) {
149-
// throw new Error("Leaf hash match failed")
150-
// }
151-
// }
152-
153139
function getOutputPath(inputPath: string, hash: string) {
154140
const extension = path.extname(inputPath)
155141
return path.join(path.dirname(inputPath), `${path.basename(inputPath, extension)}-signed-${hash}${extension}`)

packages/lint.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict"
22

3-
const { Linter } = require("tslint")
3+
const { Linter, Configuration } = require("tslint")
44
const path = require("path")
55

6-
const configuration = {
6+
const configuration = Configuration.parseConfigFile({
77
"extends": "tslint:latest",
88
"rules": {
99
"no-invalid-this": [true],
@@ -60,7 +60,8 @@ const configuration = {
6060
"jsdoc-format": false,
6161
"no-for-in-array": true,
6262
}
63-
}
63+
})
64+
6465
const options = {
6566
formatter: "stylish",
6667
}

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ aws4@^1.2.1:
293293
version "1.6.0"
294294
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
295295

296-
babel-code-frame@^6.20.0, babel-code-frame@^6.22.0:
296+
babel-code-frame@^6.22.0:
297297
version "6.22.0"
298298
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
299299
dependencies:
@@ -1011,7 +1011,7 @@ detect-newline@^1.0.3:
10111011
get-stdin "^4.0.1"
10121012
minimist "^1.1.0"
10131013

1014-
diff@^3.0.0, diff@^3.0.1:
1014+
diff@^3.0.0, diff@^3.2.0:
10151015
version "3.2.0"
10161016
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"
10171017

@@ -2781,7 +2781,7 @@ resolve@1.1.7:
27812781
version "1.1.7"
27822782
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
27832783

2784-
resolve@^1.1.7, resolve@^1.2.0:
2784+
resolve@^1.2.0, resolve@^1.3.2:
27852785
version "1.3.2"
27862786
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235"
27872787
dependencies:
@@ -3179,21 +3179,21 @@ ts-jsdoc@^1.2.1:
31793179
fs-extra-p "^4.1.0"
31803180
source-map-support "^0.4.14"
31813181

3182-
tslint@^4.5.1:
3183-
version "4.5.1"
3184-
resolved "https://registry.yarnpkg.com/tslint/-/tslint-4.5.1.tgz#05356871bef23a434906734006fc188336ba824b"
3182+
tslint@^5.0.0:
3183+
version "5.0.0"
3184+
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.0.0.tgz#ad3b7952f8a9b21079248bee01c2eaf92167e185"
31853185
dependencies:
3186-
babel-code-frame "^6.20.0"
3186+
babel-code-frame "^6.22.0"
31873187
colors "^1.1.2"
3188-
diff "^3.0.1"
3188+
diff "^3.2.0"
31893189
findup-sync "~0.3.0"
31903190
glob "^7.1.1"
31913191
optimist "~0.6.0"
3192-
resolve "^1.1.7"
3193-
tsutils "^1.1.0"
3194-
update-notifier "^2.0.0"
3192+
resolve "^1.3.2"
3193+
semver "^5.3.0"
3194+
tsutils "^1.4.0"
31953195

3196-
tsutils@^1.1.0:
3196+
tsutils@^1.4.0:
31973197
version "1.4.0"
31983198
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.4.0.tgz#84f8a83df9967d35bf1ff3aa48c7339593d64e19"
31993199

@@ -3279,7 +3279,7 @@ unzip-response@^2.0.1:
32793279
version "2.0.1"
32803280
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
32813281

3282-
update-notifier@^2.0.0, update-notifier@^2.1.0:
3282+
update-notifier@^2.1.0:
32833283
version "2.1.0"
32843284
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-2.1.0.tgz#ec0c1e53536b76647a24b77cb83966d9315123d9"
32853285
dependencies:

0 commit comments

Comments
 (0)