Skip to content

Commit

Permalink
fix(electron-publish): wait after github error
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 2, 2019
1 parent 6853b37 commit 6fc9fc5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 46 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/debug": "^4.1.4",
"@types/is-ci": "^2.0.0",
"@types/semver": "^6.0.1",
"app-builder-bin": "3.1.3",
"app-builder-bin": "3.1.4",
"archiver": "^3.0.0",
"async-exit-hook": "^2.0.1",
"bluebird-lst": "^1.0.9",
Expand All @@ -61,13 +61,13 @@
"read-config-file": "4.0.0",
"sanitize-filename": "^1.6.1",
"sax": "^1.2.4",
"semver": "^6.1.3",
"semver": "^6.2.0",
"source-map-support": "^0.5.12",
"stat-mode": "^0.3.0",
"sumchecker": "^3.0.0",
"temp-file": "^3.3.3",
"tunnel-agent": "^0.6.0",
"update-notifier": "^3.0.0",
"update-notifier": "^3.0.1",
"yargs": "^13.2.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"minimatch": "^3.0.4",
"normalize-package-data": "^2.5.0",
"sanitize-filename": "^1.6.1",
"semver": "^6.1.3",
"semver": "^6.2.0",
"debug": "^4.1.1",
"lazy-val": "^1.0.4",
"temp-file": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out"
],
"dependencies": {
"app-builder-bin": "3.1.3",
"app-builder-bin": "3.1.4",
"temp-file": "^3.3.3",
"fs-extra": "^8.1.0",
"is-ci": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"is-ci": "^2.0.0",
"read-config-file": "4.0.0",
"sanitize-filename": "^1.6.1",
"update-notifier": "^3.0.0",
"update-notifier": "^3.0.1",
"yargs": "^13.2.4",
"lazy-val": "^1.0.4",
"app-builder-lib": "0.0.0-semantic-release",
Expand Down
51 changes: 30 additions & 21 deletions packages/electron-publish/src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { httpExecutor } from "builder-util/out/nodeHttpExecutor"
import { ClientRequest } from "http"
import { Lazy } from "lazy-val"
import mime from "mime"
import { parse as parseUrl } from "url"
import { parse as parseUrl, UrlWithStringQuery } from "url"
import { getCiTag, HttpPublisher, PublishContext, PublishOptions } from "./publisher"

export interface Release {
Expand Down Expand Up @@ -167,31 +167,40 @@ export class GitHubPublisher extends HttpPublisher {
}

const parsedUrl = parseUrl(release.upload_url.substring(0, release.upload_url.indexOf("{")) + "?name=" + fileName)
let attemptNumber = 0
for (let i = 0; i < 3; i++) {
try {
return await httpExecutor.doApiRequest(configureRequestOptions({
hostname: parsedUrl.hostname,
path: parsedUrl.path,
method: "POST",
headers: {
accept: "application/vnd.github.v3+json",
"Content-Type": mime.getType(fileName) || "application/octet-stream",
"Content-Length": dataLength
}
}, this.token), this.context.cancellationToken, requestProcessor)
return await this.doUploadFile(0, parsedUrl, fileName, dataLength, requestProcessor, release)
}

private doUploadFile(attemptNumber: number, parsedUrl: UrlWithStringQuery, fileName: string, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, release: any): Promise<any> {
return httpExecutor.doApiRequest(configureRequestOptions({
hostname: parsedUrl.hostname,
path: parsedUrl.path,
method: "POST",
headers: {
accept: "application/vnd.github.v3+json",
"Content-Type": mime.getType(fileName) || "application/octet-stream",
"Content-Length": dataLength
}
catch (e) {
}, this.token), this.context.cancellationToken, requestProcessor)
.catch(e => {
if ((e as any).statusCode === 422 && e.description != null && e.description.errors != null && e.description.errors[0].code === "already_exists") {
await this.overwriteArtifact(fileName, release)
continue
return this.overwriteArtifact(fileName, release)
.then(() => this.doUploadFile(attemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release))
}

if (!(attemptNumber++ < 3 && ((e.code != null && e.code.startsWith("HTTP_ERROR_")) || e.code === "EPIPE" || e.code === "ECONNRESET"))) {
throw e
if (attemptNumber > 3) {
return Promise.reject(e)
}
}
}
else {
return new Promise((resolve, reject) => {
const newAttemptNumber = attemptNumber + 1
setTimeout(() => {
this.doUploadFile(newAttemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release)
.then(resolve)
.catch(reject)
}, newAttemptNumber * 2000)
})
}
})
}

private createRelease() {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lazy-val": "^1.0.4",
"fs-extra": "^8.1.0",
"js-yaml": "^3.13.1",
"semver": "^6.1.3",
"semver": "^6.2.0",
"builder-util-runtime": "0.0.0-semantic-release",
"lodash.isequal": "^4.5.0",
"pako": "^1.0.10"
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,10 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"

[email protected].3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-3.1.3.tgz#ab2ef3827bf8ac0959925f6b854c1b40143715d4"
integrity sha512-uqBpfTx8DsOJlogKx6Ft22PiuNrc6Ww/LjJPtIduDOQTtJf4Sy7bRaSNmMeTwQqXy7ATWudHaNsfYKlEwKdwhQ==
[email protected].4:
version "3.1.4"
resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-3.1.4.tgz#7f13ce5ba677286fe443758c73ff7dfdb0b0f6de"
integrity sha512-W72acDbPD99SvwttRDh2aD7Q02HYleGJewGXER2rmloajLbbLSM8tZ/K5+znwu1bCRPI/at0W35qmNjXjN8Kdg==

aproba@^1.0.3:
version "1.2.0"
Expand Down Expand Up @@ -2408,9 +2408,9 @@ [email protected]:
plist "^3.0.1"

electron-to-chromium@^1.3.164:
version "1.3.181"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.181.tgz#1c538401af8f3eb285db893b66e43f4bea72fd83"
integrity sha512-xf1dCoc6FSCVcNQu8VGiMSH55rOT/ov6U7UpMgw4Erg5KfD1LHTXqm34/IGp55TLX4WqwuT4IIeJWhdGhO8mYw==
version "1.3.183"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.183.tgz#d6ecf177d3388ae5913844ea46b4b4c9cc726e52"
integrity sha512-WbKCYs7yAFOfpuoa2pK5kbOngriUtlPC+8mcQW5L/686wv04w7hYXfw5ScDrsl9kixFw1SPsALEob5V/gtlDxw==

emoji-regex@^7.0.1:
version "7.0.3"
Expand Down Expand Up @@ -4885,9 +4885,9 @@ pseudomap@^1.0.2:
integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM=

psl@^1.1.24, psl@^1.1.28:
version "1.1.33"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.33.tgz#5533d9384ca7aab86425198e10e8053ebfeab661"
integrity sha512-LTDP2uSrsc7XCb5lO7A8BI1qYxRe/8EqlRvMeEl6rsnYAqDOl8xHR+8lSAIVfrNaSAlTPTNOCgNjWcoUL3AZsw==
version "1.2.0"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.2.0.tgz#df12b5b1b3a30f51c329eacbdef98f3a6e136dc6"
integrity sha512-GEn74ZffufCmkDDLNcl3uuyF/aSD6exEyh1v/ZSdAomB82t6G9hzJVRx0jBmLDW+VfZqks3aScmMw9DszwUalA==

pump@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -5302,10 +5302,10 @@ semver-diff@^2.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==

semver@^6.0.0, semver@^6.1.1, semver@^6.1.3:
version "6.1.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.3.tgz#ef997a1a024f67dd48a7f155df88bb7b5c6c3fc7"
integrity sha512-aymF+56WJJMyXQHcd4hlK4N75rwj5RQpfW8ePlQnJsTYOBLlLbcIErR/G1s9SkIvKBqOudR3KAx4wEqP+F1hNQ==
semver@^6.0.0, semver@^6.1.1, semver@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.2.0.tgz#4d813d9590aaf8a9192693d6c85b9344de5901db"
integrity sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A==

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -5996,10 +5996,10 @@ unset-value@^1.0.0:
has-value "^0.3.1"
isobject "^3.0.0"

update-notifier@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-3.0.0.tgz#e9bbf8f0f5b7a2ce6666ca46334fdb29492e8fab"
integrity sha512-6Xe3oF2bvuoj4YECUc52yxVs94yWrxwqHbzyveDktTS1WhnlTRpNcQMxUshcB7nRVGi1jEXiqL5cW1S5WSyzKg==
update-notifier@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-3.0.1.tgz#78ecb68b915e2fd1be9f767f6e298ce87b736250"
integrity sha512-grrmrB6Zb8DUiyDIaeRTBCkgISYUgETNe7NglEbVsrLWXeESnlCSP50WfRSj/GmzMPl6Uchj24S/p80nP/ZQrQ==
dependencies:
boxen "^3.0.0"
chalk "^2.0.1"
Expand Down

0 comments on commit 6fc9fc5

Please sign in to comment.