@@ -29,29 +29,31 @@ export class PublishManager {
29
29
private isPublish = false
30
30
31
31
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"
42
36
}
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
+ }
47
49
}
48
50
}
49
- }
50
51
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
+ }
55
57
}
56
58
}
57
59
@@ -323,4 +325,13 @@ function sha256(file: string) {
323
325
} )
324
326
. pipe ( hash , { end : false } )
325
327
} )
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 )
326
337
}
0 commit comments