Skip to content

Commit e1dda14

Browse files
committed
feat: Don't build when CI run is a pull request
Close #1354
1 parent eedfd54 commit e1dda14

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

packages/electron-builder-util/src/util.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,14 @@ export function getPlatformIconFileName(value: string | null | undefined, isMac:
294294
}
295295

296296
return value.replace(isMac ? ".ico" : ".icns", isMac ? ".icns" : ".ico")
297+
}
298+
299+
export function isPullRequest() {
300+
// 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.
301+
function isSet(value: string) {
302+
// value can be or null, or empty string
303+
return value && value !== "false"
304+
}
305+
306+
return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS)
297307
}

packages/electron-builder/src/macPackager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import BluebirdPromise from "bluebird-lst"
22
import { Arch, DIR_TARGET, Platform, Target } from "electron-builder-core"
3-
import { exec } from "electron-builder-util"
3+
import { exec, isPullRequest } from "electron-builder-util"
44
import { deepAssign } from "electron-builder-util/out/deepAssign"
55
import { log, task, warn } from "electron-builder-util/out/log"
66
import { signAsync, SignOptions } from "electron-macos-sign"
@@ -115,6 +115,10 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
115115
warn("macOS application code signing is supported only on macOS, skipping.")
116116
return
117117
}
118+
if (isPullRequest()) {
119+
log("Current build is a part of pull request, code signing will be skipped")
120+
return
121+
}
118122

119123
const keychainName = (await this.codeSigningInfo).keychainName
120124
const isMas = masOptions != null

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createHash } from "crypto"
33
import { Arch, Platform, Target } from "electron-builder-core"
44
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
55
import { GenericServerOptions, GithubOptions, githubUrl, PublishConfiguration, PublishProvider, S3Options, s3Url, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions"
6-
import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util"
6+
import { asArray, debug, isEmptyOrSpaces, isPullRequest } from "electron-builder-util"
77
import { log } from "electron-builder-util/out/log"
88
import { throwError } from "electron-builder-util/out/promise"
99
import { HttpPublisher, PublishContext, Publisher, PublishOptions } from "electron-publish"
@@ -410,16 +410,6 @@ function sha256(file: string) {
410410
})
411411
}
412412

413-
function isPullRequest() {
414-
// 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.
415-
function isSet(value: string) {
416-
// value can be or null, or empty string
417-
return value && value !== "false"
418-
}
419-
420-
return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS)
421-
}
422-
423413
function isSuitableWindowsTarget(target: Target) {
424414
return target.name === "nsis" || target.name.startsWith("nsis-")
425415
}

0 commit comments

Comments
 (0)