Skip to content

Commit

Permalink
extract platform-specific checks for building and packaging into new …
Browse files Browse the repository at this point in the history
…build
  • Loading branch information
Brendan Forster committed Sep 16, 2018
1 parent dd831bc commit 5431018
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 33 deletions.
91 changes: 91 additions & 0 deletions script/build-platforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export function getSha() {
if (isCircleCI() && process.env.CIRCLE_SHA1 != null) {
return process.env.CIRCLE_SHA1
}

if (isAppveyor() && process.env.APPVEYOR_REPO_COMMIT != null) {
return process.env.APPVEYOR_REPO_COMMIT
}

if (isTravis() && process.env.TRAVIS_COMMIT != null) {
return process.env.TRAVIS_COMMIT
}

const branchCommitId = process.env.BUILD_SOURCEVERSION
// this check is for a CI build from a local branch
if (isAzurePipelines() && branchCommitId != null) {
return branchCommitId
}

const pullRequestCommitId = process.env.SYSTEM_PULLREQUEST_SOURCECOMMITID
if (isAzurePipelines() && pullRequestCommitId != null) {
return pullRequestCommitId
}

throw new Error(
`Unable to get the SHA for the current platform. Check the documentation for the expected environment variables.`
)
}

export function isRunningOnFork() {
if (isCircleCI() && process.env.CIRCLE_PR_USERNAME == null) {
return true
}

if (
isAppveyor() &&
process.env.APPVEYOR_PULL_REQUEST_NUMBER != null &&
process.env.APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME !== 'desktop/desktop'
) {
return true
}

if (
isTravis() &&
process.env.TRAVIS_PULL_REQUEST_SLUG != null &&
// empty string denotes a `push` build
process.env.TRAVIS_PULL_REQUEST_SLUG !== '' &&
process.env.TRAVIS_PULL_REQUEST_SLUG !== 'desktop/desktop'
) {
return true
}

if (
isAzurePipelines() &&
process.env.SYSTEM_PULLREQUEST_ISFORK != null &&
process.env.SYSTEM_PULLREQUEST_ISFORK === 'True'
) {
return true
}

return false
}

export function isTravis() {
return process.platform === 'linux' && process.env.TRAVIS === 'true'
}

export function isCircleCI() {
return process.platform === 'darwin' && process.env.CIRCLECI === 'true'
}

export function isAppveyor() {
return process.platform === 'win32' && process.env.APPVEYOR === 'True'
}

export function isAzurePipelines() {
return (
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI ===
'https://github.visualstudio.com/'
)
}

export function getReleaseBranchName(): string {
return (
process.env.CIRCLE_BRANCH || // macOS
process.env.APPVEYOR_REPO_BRANCH || // Windows
process.env.TRAVIS_BRANCH || // Travis CI
process.env.BUILD_SOURCEBRANCHNAME || // Azure Pipelines
''
)
}
6 changes: 3 additions & 3 deletions script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ import {
} from '../app/package-info'

import { getReleaseChannel, getDistRoot, getExecutableName } from './dist-info'
import { getSha, isRunningOnFork, isCircleCI } from './build-platforms'

const projectRoot = path.join(__dirname, '..')
const outRoot = path.join(projectRoot, 'out')

const isPublishableBuild = getReleaseChannel() !== 'development'

console.log(`Building for ${getReleaseChannel()}…`)
console.log(`Building for ${getReleaseChannel()} from commit id ${getSha()}…`)

console.log('Removing old distribution…')
fs.removeSync(getDistRoot())
Expand All @@ -68,8 +69,7 @@ generateLicenseMetadata(outRoot)

moveAnalysisFiles()

const isFork = process.env.CIRCLE_PR_USERNAME
if (process.platform === 'darwin' && process.env.CIRCLECI && !isFork) {
if (process.platform === 'darwin' && isCircleCI() && !isRunningOnFork()) {
console.log('Setting up keychain…')
cp.execSync(path.join(__dirname, 'setup-macos-keychain'))
}
Expand Down
9 changes: 1 addition & 8 deletions script/dist-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Path from 'path'
import * as Fs from 'fs'

import { getProductName, getVersion } from '../app/package-info'
import { getReleaseBranchName } from './build-platforms'

const productName = getProductName()
const version = getVersion()
Expand Down Expand Up @@ -97,14 +98,6 @@ export function getBundleSizes() {
return { rendererSize: rendererStats.size, mainSize: mainStats.size }
}

export function getReleaseBranchName(): string {
return (
process.env.CIRCLE_BRANCH || // macOS
process.env.APPVEYOR_REPO_BRANCH || // Windows
''
)
}

export function getReleaseChannel() {
// Branch name format: __release-CHANNEL-DEPLOY_ID
const pieces = getReleaseBranchName().split('-')
Expand Down
5 changes: 3 additions & 2 deletions script/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
shouldMakeDelta,
getUpdatesURL,
} from './dist-info'
import { isAppveyor } from './build-platforms'

const distPath = getDistPath()
const productName = getProductName()
Expand Down Expand Up @@ -50,7 +51,7 @@ function packageWindows() {
'cleanup-windows-certificate.ps1'
)

if (process.env.APPVEYOR) {
if (isAppveyor()) {
cp.execSync(`powershell ${setupCertificatePath}`)
}

Expand Down Expand Up @@ -101,7 +102,7 @@ function packageWindows() {
options.remoteReleases = getUpdatesURL()
}

if (process.env.APPVEYOR) {
if (isAppveyor()) {
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
options.signWithParams = `/f ${certificatePath} /p ${
process.env.WINDOWS_CERT_PASSWORD
Expand Down
20 changes: 3 additions & 17 deletions script/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const PUBLISH_CHANNELS = ['production', 'test', 'beta']
import * as distInfo from './dist-info'
import * as gitInfo from '../app/git-info'
import * as packageInfo from '../app/package-info'
import * as platforms from './build-platforms'

if (PUBLISH_CHANNELS.indexOf(distInfo.getReleaseChannel()) < 0) {
console.log('Not a publishable build. Skipping publish.')
Expand Down Expand Up @@ -31,22 +32,7 @@ import * as request from 'request'
console.log('Packaging…')
execSync('yarn package')

function getSha() {
if (process.platform === 'darwin' && process.env.CIRCLE_SHA1 != null) {
return process.env.CIRCLE_SHA1
} else if (
process.platform === 'win32' &&
process.env.APPVEYOR_REPO_COMMIT != null
) {
return process.env.APPVEYOR_REPO_COMMIT
}

throw new Error(
`Unable to get the SHA for the current platform. Check the vendor docs for the desired environment variables.`
)
}

const sha = getSha().substr(0, 8)
const sha = platforms.getSha().substr(0, 8)

function getSecret() {
if (process.env.DEPLOYMENT_SECRET != null) {
Expand Down Expand Up @@ -179,7 +165,7 @@ function updateDeploy(artifacts: ReadonlyArray<IUploadResult>, secret: string) {
const { rendererSize, mainSize } = distInfo.getBundleSizes()
const body = {
context: process.platform,
branch_name: distInfo.getReleaseBranchName(),
branch_name: platforms.getReleaseBranchName(),
artifacts,
stats: {
platform: process.platform,
Expand Down
5 changes: 2 additions & 3 deletions script/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import * as cp from 'child_process'
import { getLogFiles } from './review-logs'
import { getProductName } from '../app/package-info'
import { getDistPath } from './dist-info'
import { isCircleCI, isRunningOnFork } from './build-platforms'

const isFork = process.env.CIRCLE_PR_USERNAME

if (process.platform === 'darwin' && process.env.CIRCLECI && !isFork) {
if (isCircleCI() && !isRunningOnFork()) {
const archive = `${getDistPath()}/${getProductName()}.app`
try {
console.log('validating signature of Desktop app')
Expand Down

0 comments on commit 5431018

Please sign in to comment.