Skip to content

Commit

Permalink
fix(deployment): check for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 1, 2017
1 parent d7c6eea commit 4c71fc0
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 28 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
excludeModules: ["path"]
}
],
"./packages/babel-plugin-version-transform.js",
],
},
test: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"repository": "electron-userland/electron-builder",
"///": "all dependencies for all packages (hoisted)",
"dependencies": {
"7zip-bin": "^2.0.4",
"7zip-bin": "^2.1.0",
"ajv": "^5.1.5",
"ajv-keywords": "^2.1.0",
"archiver": "^1.3.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/babel-plugin-version-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require("path")
const version = require(path.join(__dirname, "electron-builder/package.json")).version

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function versionTransform() {
return {
visitor: {
Identifier(path) {
if (path.node.name === 'PACKAGE_VERSION') {
path.replaceWithSourceString('"' + version + '"');
}
},
},
};
};

2 changes: 1 addition & 1 deletion packages/electron-builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"node-emoji": "^1.5.1",
"electron-builder-http": "~0.0.0-semantic-release",
"source-map-support": "^0.4.15",
"7zip-bin": "^2.0.4",
"7zip-bin": "^2.1.0",
"ini": "^1.3.4",
"tunnel-agent": "^0.6.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder-util/src/nodeHttpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { parse as parseIni } from "ini"
import { homedir } from "os"
import * as path from "path"
import { parse as parseUrl } from "url"
import { safeStringifyJson } from "./util"

const debug = _debug("electron-builder")

Expand Down Expand Up @@ -45,7 +46,7 @@ export class NodeHttpExecutor extends HttpExecutor<ClientRequest> {

doApiRequest<T>(options: RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, redirectCount: number = 0): Promise<T> {
if (debug.enabled) {
debug(`HTTPS request: ${JSON.stringify(options, null, 2)}`)
debug(`HTTPS request: ${safeStringifyJson(options)}`)
}

return cancellationToken.createPromise((resolve, reject, onCancel) => {
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 @@ -44,7 +44,7 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "^2.0.4",
"7zip-bin": "^2.1.0",
"ajv": "^5.1.5",
"ajv-keywords": "^2.1.0",
"bluebird-lst": "^1.0.2",
Expand Down
11 changes: 9 additions & 2 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function addHandler(emitter: EventEmitter, event: string, handler: Function) {
emitter.on(event, handler)
}

declare const PACKAGE_VERSION: string

export class Packager implements BuildInfo {
readonly projectDir: string
appDir: string
Expand Down Expand Up @@ -72,6 +74,8 @@ export class Packager implements BuildInfo {
this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir)

this.prepackaged = options.prepackaged == null ? null : path.resolve(this.projectDir, options.prepackaged)

log("electron-builder " + PACKAGE_VERSION)
}

addAfterPackHandler(handler: (context: AfterPackContext) => Promise<any> | null) {
Expand Down Expand Up @@ -155,8 +159,11 @@ export class Packager implements BuildInfo {
}

this.checkMetadata(appPackageFile, devPackageFile)

debug(`Effective config: ${safeStringifyJson(this.config)}`)

if (debug.enabled) {
debug(`Effective config: ${safeStringifyJson(this.config)}`)
}

checkConflictingOptions(this.config)

this.electronVersion = await getElectronVersion(this.config, projectDir, this.isPrepackedAppAsar ? this.metadata : null)
Expand Down
20 changes: 14 additions & 6 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ export class PublishManager implements PublishContext {
}

this.publishTasks.push(promise
.catch(it => this.errors.push(it)))
.catch(it => {
debug(`Publish error: ${it.toString()}`)
this.errors.push(it)
}))
}

private getOrCreatePublisher(publishConfig: PublishConfiguration, buildInfo: BuildInfo): Publisher | null {
Expand All @@ -180,17 +183,22 @@ export class PublishManager implements PublishContext {
}

async awaitTasks() {
if (this.errors.length > 0) {
this.cancelTasks()
throwError(this.errors)
return
const checkErrors = () => {
if (this.errors.length > 0) {
this.cancelTasks()
throwError(this.errors)
return
}
}

checkErrors()

const publishTasks = this.publishTasks
let list = publishTasks.slice()
publishTasks.length = 0
while (list.length > 0) {
await BluebirdPromise.all(list)
checkErrors()
if (publishTasks.length === 0) {
break
}
Expand Down Expand Up @@ -301,7 +309,7 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu

export function createPublisher(context: PublishContext, version: string, publishConfig: PublishConfiguration, options: PublishOptions): Publisher | null {
if (debug.enabled) {
debug(`create publisher: ${safeStringifyJson(publishConfig)} is not published: cancelled`)
debug(`create publisher: ${safeStringifyJson(publishConfig)}`)
}

const provider = publishConfig.provider
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.3.0",
"aws-sdk": "^2.59.0",
"aws-sdk": "^2.60.0",
"mime": "^1.3.6",
"electron-publish": "~0.0.0-semantic-release",
"electron-builder-util": "~0.0.0-semantic-release"
Expand Down
25 changes: 16 additions & 9 deletions test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,22 @@ function versionNumber() {
const token = new Buffer("Y2Y5NDdhZDJhYzJlMzg1OGNiNzQzYzcwOWZhNGI0OTk2NWQ4ZDg3Yg==", "base64").toString()
const iconPath = join(__dirname, "..", "fixtures", "test-app", "build", "icon.icns")

//test("GitHub unauthorized", async (t) => {
// t.throws(await new GitHubPublisher("github-releases-test", "test-repo", versionNumber(), "incorrect token")
// .releasePromise, /(Bad credentials|Unauthorized|API rate limit exceeded)/)
//})
const publishContext: PublishContext = {
cancellationToken: new CancellationToken(),
progress: null,
}

test("GitHub unauthorized", async () => {
try {
await new GitHubPublisher(publishContext, {provider: "github", owner: "actperepo", repo: "ecb2", token: "incorrect token"}, versionNumber()).releasePromise
}
catch (e) {
expect(e.message).toMatch(/(Bad credentials|Unauthorized|API rate limit exceeded)/)
return
}

throw new Error("must be error")
})

function isApiRateError(e: Error): boolean {
if (e.name === "HttpError") {
Expand Down Expand Up @@ -65,11 +77,6 @@ function testAndIgnoreApiRate(name: string, testFunction: () => Promise<any>) {
})
}

const publishContext: PublishContext = {
cancellationToken: new CancellationToken(),
progress: null,
}

test("Bintray upload", async () => {
const version = versionNumber()

Expand Down
1 change: 0 additions & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
// we test app-update.yml separately, don't want to complicate general assert (yes, it is not good that we write app-update.yml for squirrel.windows if we build nsis and squirrel.windows in parallel, but as squirrel.windows is deprecated, it is ok)
const files = pathSorter(fileDescriptors.map(it => it.path.replace(/\\/g, "/")).filter(it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp") && !it.endsWith("app-update.yml")))

// console.log(JSON.stringify(files, null, 2))
expect(files).toMatchSnapshot()

if (checkOptions == null) {
Expand Down
4 changes: 2 additions & 2 deletions test/src/helpers/wine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BluebirdPromise from "bluebird-lst"
import { exec } from "electron-builder-util"
import { exec, safeStringifyJson } from "electron-builder-util"
import { unlinkIfExists } from "electron-builder-util/out/fs"
import { emptyDir, ensureDir, readFile, writeFile } from "fs-extra-p"
import { homedir } from "os"
Expand All @@ -24,7 +24,7 @@ export class WineManager {
const env = process.env
const user = env.SUDO_USER || env.LOGNAME || env.USER || env.LNAME || env.USERNAME || (env.HOME === "/root" ? "root" : null)
if (user == null) {
throw new Error(`Cannot determinate user name: ${JSON.stringify(env, null, 2)}`)
throw new Error(`Cannot determinate user name: ${safeStringifyJson(env)}`)
}

this.userDir = path.join(this.wineDir, "drive_c", "users", user)
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
version "2.1.0"
resolved "https://registry.yarnpkg.com/7zip-bin-win/-/7zip-bin-win-2.1.0.tgz#ce632da797ec282c5d2a8d07b60e8df7ca7f164d"

"7zip-bin@^2.1.0":
"7zip-bin@^2.0.4":
version "2.1.0"
resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-2.1.0.tgz#d728d3f950895cfcfee1a166fe93afc07dfe35a9"
optionalDependencies:
Expand Down Expand Up @@ -265,7 +265,7 @@ asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"

aws-sdk@^2.60.0:
aws-sdk@^2.59.0:
version "2.60.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.60.0.tgz#5c1e678bd087753339d756ef7da0a4f5fa3393c9"
dependencies:
Expand Down Expand Up @@ -3305,7 +3305,7 @@ tslib@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"

tslint@^5.4.1:
tslint@^5.3.2:
version "5.4.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.4.1.tgz#4b6768f26e5efb14cf34ac0714465e62bebb795b"
dependencies:
Expand Down

0 comments on commit 4c71fc0

Please sign in to comment.