Skip to content

Commit

Permalink
fix(deployment): Error on CI build when GH_TOKEN not set for external…
Browse files Browse the repository at this point in the history
… PRs

Close #1178
  • Loading branch information
develar committed Jan 27, 2017
1 parent 2539cfb commit ee32575
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,31 @@ export class PublishManager {
private isPublish = false

constructor(packager: Packager, private readonly publishOptions: PublishOptions) {
if (publishOptions.publish === undefined) {
if (process.env.npm_lifecycle_event === "release") {
publishOptions.publish = "always"
}
else if (isAuthTokenSet() ) {
const tag = getCiTag()
if (tag != null) {
log(`Tag ${tag} is defined, so artifacts will be published`)
publishOptions.publish = "onTag"
this.isPublishOptionGuessed = true
if (!isPullRequest()) {
if (publishOptions.publish === undefined) {
if (process.env.npm_lifecycle_event === "release") {
publishOptions.publish = "always"
}
else if (isCi) {
log("CI detected, so artifacts will be published if draft release exists")
publishOptions.publish = "onTagOrDraft"
this.isPublishOptionGuessed = true
else if (isAuthTokenSet()) {
const tag = getCiTag()
if (tag != null) {
log(`Tag ${tag} is defined, so artifacts will be published`)
publishOptions.publish = "onTag"
this.isPublishOptionGuessed = true
}
else if (isCi) {
log("CI detected, so artifacts will be published if draft release exists")
publishOptions.publish = "onTagOrDraft"
this.isPublishOptionGuessed = true
}
}
}
}

if (publishOptions.publish != null && publishOptions.publish !== "never") {
this.isPublish = publishOptions.publish !== "onTag" || getCiTag() != null
if (this.isPublish && !isAuthTokenSet()) {
throw new Error(`Publish is set to ${publishOptions.publish}, but neither GH_TOKEN nor BT_TOKEN is not set`)
if (publishOptions.publish != null && publishOptions.publish !== "never") {
this.isPublish = publishOptions.publish !== "onTag" || getCiTag() != null
if (this.isPublish && !isAuthTokenSet()) {
throw new Error(`Publish is set to ${publishOptions.publish}, but neither GH_TOKEN nor BT_TOKEN is not set`)
}
}
}

Expand Down Expand Up @@ -323,4 +325,13 @@ function sha256(file: string) {
})
.pipe(hash, {end: false})
})
}

function isPullRequest() {
// TRAVIS_PULL_REQUEST is set to the pull request number if the current job is a pull request build, or false if it’s not.
function isSet(value: string) {
return value != null && value !== "false"
}

return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS)
}

0 comments on commit ee32575

Please sign in to comment.