Skip to content

Commit

Permalink
feat: retry code sign if failed due to network failure
Browse files Browse the repository at this point in the history
Close #1414
  • Loading branch information
develar committed Mar 30, 2017
1 parent 624311b commit 9b60518
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"path-sort": "^0.1.0",
"source-map-support": "^0.4.14",
"ts-babel": "^3.0.0",
"tslint": "^4.5.1",
"tslint": "^5.0.0",
"typescript": "^2.2.2",
"typescript-json-schema": "0.11.0",
"whitespace": "^2.1.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/electron-builder/src/util/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ajv from "ajv"
import { debug } from "electron-builder-util"
import { log, warn } from "electron-builder-util/out/log"
import { readFile, readJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
Expand Down Expand Up @@ -148,7 +149,8 @@ export async function validateConfig(config: Config) {

const validator = await validatorPromise
if (!validator(config)) {
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2) + "\n\nRaw validation errors: " + JSON.stringify(validator.errors, null, 2))
debug(JSON.stringify(validator.errors, null, 2))
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2))
}
}

Expand Down
20 changes: 17 additions & 3 deletions packages/electron-builder/src/winPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { DIR_TARGET, Platform, Target } from "electron-builder-core"
import { asArray, exec, Lazy, use } from "electron-builder-util"
import { log } from "electron-builder-util/out/log"
import { log, warn } from "electron-builder-util/out/log"
import { close, open, read, readFile, rename } from "fs-extra-p"
import * as forge from "node-forge"
import * as path from "path"
Expand Down Expand Up @@ -196,8 +196,22 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
}

//noinspection JSMethodCanBeStatic
protected doSign(options: SignOptions): Promise<any> {
return sign(options)
protected async doSign(options: SignOptions) {
for (let i = 0; i < 3; i++) {
try {
await sign(options)
break
}
catch (e) {
// https://github.com/electron-userland/electron-builder/issues/1414
const message = e.message
if (message != null && message.includes("Couldn't resolve host name")) {
warn(`Cannot sign, attempt ${i + 1}: ${message}`)
continue
}
throw e
}
}
}

async signAndEditResources(file: string) {
Expand Down
14 changes: 0 additions & 14 deletions packages/electron-builder/src/windowsCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,6 @@ async function spawnSign(options: SignOptions, inputPath: string, outputPath: st
return await exec(await getToolPath(), args)
}

// async function verify(options: any) {
// const out = await exec(await getToolPath(options), [
// "verify",
// "-in", options.path,
// "-require-leaf-hash", options.hash
// ])
// if (out.includes("No signature found.")) {
// throw new Error("No signature found")
// }
// else if (out.includes("Leaf hash match: failed")) {
// throw new Error("Leaf hash match failed")
// }
// }

function getOutputPath(inputPath: string, hash: string) {
const extension = path.extname(inputPath)
return path.join(path.dirname(inputPath), `${path.basename(inputPath, extension)}-signed-${hash}${extension}`)
Expand Down
7 changes: 4 additions & 3 deletions packages/lint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict"

const { Linter } = require("tslint")
const { Linter, Configuration } = require("tslint")
const path = require("path")

const configuration = {
const configuration = Configuration.parseConfigFile({
"extends": "tslint:latest",
"rules": {
"no-invalid-this": [true],
Expand Down Expand Up @@ -60,7 +60,8 @@ const configuration = {
"jsdoc-format": false,
"no-for-in-array": true,
}
}
})

const options = {
formatter: "stylish",
}
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ aws4@^1.2.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"

babel-code-frame@^6.20.0, babel-code-frame@^6.22.0:
babel-code-frame@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
dependencies:
Expand Down Expand Up @@ -1011,7 +1011,7 @@ detect-newline@^1.0.3:
get-stdin "^4.0.1"
minimist "^1.1.0"

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

Expand Down Expand Up @@ -2781,7 +2781,7 @@ [email protected]:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@^1.1.7, resolve@^1.2.0:
resolve@^1.2.0, resolve@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235"
dependencies:
Expand Down Expand Up @@ -3179,21 +3179,21 @@ ts-jsdoc@^1.2.1:
fs-extra-p "^4.1.0"
source-map-support "^0.4.14"

tslint@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-4.5.1.tgz#05356871bef23a434906734006fc188336ba824b"
tslint@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.0.0.tgz#ad3b7952f8a9b21079248bee01c2eaf92167e185"
dependencies:
babel-code-frame "^6.20.0"
babel-code-frame "^6.22.0"
colors "^1.1.2"
diff "^3.0.1"
diff "^3.2.0"
findup-sync "~0.3.0"
glob "^7.1.1"
optimist "~0.6.0"
resolve "^1.1.7"
tsutils "^1.1.0"
update-notifier "^2.0.0"
resolve "^1.3.2"
semver "^5.3.0"
tsutils "^1.4.0"

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

Expand Down Expand Up @@ -3279,7 +3279,7 @@ unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"

update-notifier@^2.0.0, update-notifier@^2.1.0:
update-notifier@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-2.1.0.tgz#ec0c1e53536b76647a24b77cb83966d9315123d9"
dependencies:
Expand Down

0 comments on commit 9b60518

Please sign in to comment.