Skip to content

Commit ee32575

Browse files
committed
fix(deployment): Error on CI build when GH_TOKEN not set for external PRs
Close #1178
1 parent 2539cfb commit ee32575

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

packages/electron-builder/src/publish/PublishManager.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,31 @@ export class PublishManager {
2929
private isPublish = false
3030

3131
constructor(packager: Packager, private readonly publishOptions: PublishOptions) {
32-
if (publishOptions.publish === undefined) {
33-
if (process.env.npm_lifecycle_event === "release") {
34-
publishOptions.publish = "always"
35-
}
36-
else if (isAuthTokenSet() ) {
37-
const tag = getCiTag()
38-
if (tag != null) {
39-
log(`Tag ${tag} is defined, so artifacts will be published`)
40-
publishOptions.publish = "onTag"
41-
this.isPublishOptionGuessed = true
32+
if (!isPullRequest()) {
33+
if (publishOptions.publish === undefined) {
34+
if (process.env.npm_lifecycle_event === "release") {
35+
publishOptions.publish = "always"
4236
}
43-
else if (isCi) {
44-
log("CI detected, so artifacts will be published if draft release exists")
45-
publishOptions.publish = "onTagOrDraft"
46-
this.isPublishOptionGuessed = true
37+
else if (isAuthTokenSet()) {
38+
const tag = getCiTag()
39+
if (tag != null) {
40+
log(`Tag ${tag} is defined, so artifacts will be published`)
41+
publishOptions.publish = "onTag"
42+
this.isPublishOptionGuessed = true
43+
}
44+
else if (isCi) {
45+
log("CI detected, so artifacts will be published if draft release exists")
46+
publishOptions.publish = "onTagOrDraft"
47+
this.isPublishOptionGuessed = true
48+
}
4749
}
4850
}
49-
}
5051

51-
if (publishOptions.publish != null && publishOptions.publish !== "never") {
52-
this.isPublish = publishOptions.publish !== "onTag" || getCiTag() != null
53-
if (this.isPublish && !isAuthTokenSet()) {
54-
throw new Error(`Publish is set to ${publishOptions.publish}, but neither GH_TOKEN nor BT_TOKEN is not set`)
52+
if (publishOptions.publish != null && publishOptions.publish !== "never") {
53+
this.isPublish = publishOptions.publish !== "onTag" || getCiTag() != null
54+
if (this.isPublish && !isAuthTokenSet()) {
55+
throw new Error(`Publish is set to ${publishOptions.publish}, but neither GH_TOKEN nor BT_TOKEN is not set`)
56+
}
5557
}
5658
}
5759

@@ -323,4 +325,13 @@ function sha256(file: string) {
323325
})
324326
.pipe(hash, {end: false})
325327
})
328+
}
329+
330+
function isPullRequest() {
331+
// 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.
332+
function isSet(value: string) {
333+
return value != null && value !== "false"
334+
}
335+
336+
return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS)
326337
}

0 commit comments

Comments
 (0)