Skip to content

Commit

Permalink
switch to electron-builder to code sign and notarize Cypress ap… (#6013)
Browse files Browse the repository at this point in the history
* [email protected]

* node12.8.1-chrome78-ff70

* Revert "node12.8.1-chrome78-ff70" for now

This reverts commit db2d521.

* update sendCommand to log on all sendcommands

* promisification in 6.x

* Revert "Revert "node12.8.1-chrome78-ff70" for now"

This reverts commit 57fe764.

* fix sendcommand

* fix cdp in electron

* fix desktop-gui test

* skip tests that will be fixed by #4973

* bump MAX_ALLOWED_FILE_SIZE :/

* update electron browser spec

* make new dialog code null-proof

* add failing e2e test for issue 5475

* bump electron packager

* add e2e snapshot

* update deprecated electron getters/setters

https://github.com/electron/electron/blob/7-1-x/docs/api/modernization/property-updates.md

* build and test on Mac

* use electron-builder 20.41.0

that adds an option to use hardened Mac OS, which is necessary
for code notarization later.

See https://github.com/electron-userland/electron-builder/releases/tag/v20.41.0
and electron-userland/electron-builder#3858

* electron-builder and pass hardenedRuntime: true

* uncomment build

* upload built binary on mac

* back to 20.41.0, trying after sign hook without success

* use current electron-builder alias instead of build

* retry smoke test on first failure

* testing

* trying to notarize signed app (that does not have node_modules yet)

* env variable names

* copy node_modules ourselves

* build and bundle binary on mac on circle, inject new context

* enable build steps before electron build

* increase mac build timeout

* update build folder on mac

* uncomment actual electron build command

* set linux target to zip

* set zip as target for all platforms

* updated steps

* put notarization hook back

* tweaks for icons

* remove dist electron before code sign

* icons per platform

* make node_modules copy path platform-specific

* fix linux build unpacked folder

* build mac

* fix lint

* test new mac binary against kitchensink

* working on Linux build

* try building entire thing on Linux

* removing correct electron dist folder

* increase zip size limit for now

* add folder rename on Linux from linux-unpacked to Cypress

* print file sizes before zipping

* move linux-unpacked to build dir function

* try deleting second electron file, but code signing probably would not work

* test windows build [build binary]

* ignore tsc errors

* windows build path

* windows [build binary]

* update windows build folder

* increase binary build timeout on Mac

* no need to pass our dist folder

* adding explicit list of additional binaries to code sign on mac

* yarn lock

* uncomment necessary build steps

* electron dir for Linux

* yarn lock again

* back to execa v3

* use execa v4 in packages launcher

* yarn lock again and again

* updated tests that use execa

* print build folder

* add executable name on Linux

* get rid of execa.shell in build scripts

* remove old and commented out code

* need to test building binary on Windows

* throw error from after sign hook if fails

* use execa to zip

* yarn lock

* fix after merge variable

* update test

* add nohoist ffmpeg installer

* patch

* yarn types pass

* yarn lock has binary

Co-authored-by: Zach Bloomquist <[email protected]>
Co-authored-by: Brian Mann <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2020
1 parent aee0517 commit abf4d85
Show file tree
Hide file tree
Showing 25 changed files with 1,532 additions and 799 deletions.
28 changes: 11 additions & 17 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ macBuildFilters: &macBuildFilters
branches:
only:
- develop
- try-new-electron-sign

defaults: &defaults
parallelism: 1
Expand Down Expand Up @@ -729,6 +730,11 @@ jobs:
- run:
environment:
DEBUG: electron-builder,electron-osx-sign*
# notarization on Mac can take a while
no_output_timeout: "30m"
# if this is a forked pull request, the NEXT_DEV_VERSION environment variable
# won't be set and we will use default version, since we are not going to
# upload the dev binary build anywhere
command: yarn binary-build --platform $PLATFORM --version ${NEXT_DEV_VERSION:-0.0.0-development}
- run: yarn binary-zip --platform $PLATFORM
# Cypress binary file should be zipped to cypress.zip
Expand Down Expand Up @@ -1405,25 +1411,19 @@ mac-workflow: &mac-workflow
executor: mac
requires:
- Mac build
filters:
branches:
only:
- develop
<<: *macBuildFilters

- upload-npm-package:
name: Mac NPM package upload
context: test-runner:upload
executor: mac
filters:
branches:
only:
- develop
<<: *macBuildFilters
requires:
- Mac NPM package

- build-binary:
name: Mac binary
context: org-global
context: test-runner:sign-mac-binary
executor: mac
<<: *macBuildFilters
requires:
Expand All @@ -1433,10 +1433,7 @@ mac-workflow: &mac-workflow
name: Mac binary upload
executor: mac
context: test-runner:upload
filters:
branches:
only:
- develop
<<: *macBuildFilters
requires:
- Mac binary

Expand All @@ -1450,10 +1447,7 @@ mac-workflow: &mac-workflow
- test-binary-against-kitchensink:
name: Test Mac binary against kitchensink
executor: mac
filters:
branches:
only:
- develop
<<: *macBuildFilters
requires:
- Mac NPM package
- Mac binary
Expand Down
31 changes: 29 additions & 2 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
{
"productName": "Cypress",
"appId": "com.electron.cypress",
"target": "zip",
"mac": {
"target": "zip",
"forceCodeSigning": true,
"publish": null,
"target": "zip"
}
"hardenedRuntime": true,
"entitlements": "./scripts/entitlements.mac.inherit.plist",
"entitlementsInherit": "./scripts/entitlements.mac.inherit.plist",
"type": "distribution",
"binaries": [
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/@ffmpeg-installer/darwin-x64/ffmpeg",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/watchify/node_modules/fsevents/build/Release/.node",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/watchify/node_modules/fsevents/build/Release/fse.node",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/registry-js/build/Release/registry.node",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/term-size/vendor/macos/term-size",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/trash/lib/macos-trash",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/babel-plugin-add-module-exports/node_modules/fsevents/build/Release/.node",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/babel-plugin-add-module-exports/node_modules/fsevents/build/Release/fse.node",
"./build/mac/Cypress.app/Contents/Resources/app/packages/server/node_modules/fsevents/fsevents.node"
]
},
"linux": {
"target": "dir",
"executableName": "Cypress"
},
"win": {
"target": "dir"
},
"afterPack": "./scripts/after-pack-hook.js",
"afterSign": "./scripts/after-sign-hook.js"
}
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@types/mocha": "5.2.7",
"@types/node": "12.12.21",
"@types/ramda": "0.25.47",
"@types/react": "16.9.23",
"@types/react": "16.9.25",
"@types/react-dom": "16.9.4",
"@types/request-promise": "4.1.45",
"@types/sinon-chai": "3.2.3",
Expand All @@ -127,19 +127,21 @@
"debug": "4.1.1",
"decaffeinate": "6.0.9",
"del": "3.0.0",
"electron-builder": "20.39.0",
"electron-builder": "22.3.6",
"electron-notarize": "0.2.1",
"enzyme-adapter-react-16": "1.12.1",
"eslint": "6.8.0",
"eslint-plugin-cypress": "2.10.3",
"eslint-plugin-json-format": "2.0.0",
"eslint-plugin-mocha": "6.1.0",
"eslint-plugin-react": "7.18.3",
"execa": "1.0.0",
"execa": "4.0.0",
"execa-wrap": "1.4.0",
"filesize": "4.1.2",
"find-package-json": "1.2.0",
"fs-extra": "8.1.0",
"gift": "0.10.2",
"globby": "10.0.1",
"gulp": "4.0.2",
"gulp-awspublish": "4.0.0",
"gulp-coffee": "3.0.3",
Expand Down Expand Up @@ -227,6 +229,10 @@
"packages": [
"cli",
"packages/*"
],
"nohoist": [
"**/@ffmpeg-installer",
"**/@ffmpeg-installer/**"
]
},
"lint-staged": {
Expand Down
8 changes: 8 additions & 0 deletions packages/electron/lib/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ module.exports = {
return install.package.apply(install, args)
},

getElectronVersion () {
return install.getElectronVersion()
},

icons () {
return install.icons()
},

cli (argv = []) {
const opts = minimist(argv)

Expand Down
10 changes: 10 additions & 0 deletions packages/electron/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ if (!(electronVersion = pkg.devDependencies.electron)) {
}

module.exports = {
getElectronVersion () {
return electronVersion
},

// returns icons package so that the caller code can find
// paths to the icons without hard-coding them
icons () {
return require('@cypress/icons')
},

checkCurrentVersion () {
const pathToVersion = paths.getPathToVersion()

Expand Down
6 changes: 3 additions & 3 deletions packages/launcher/lib/darwin/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from '../log'
import { notInstalledErr } from '../errors'
import { prop, tap } from 'ramda'
import execa from 'execa'
import { utils } from '../utils'
import fs from 'fs-extra'
import * as path from 'path'
import * as plist from 'plist'
Expand Down Expand Up @@ -45,8 +45,8 @@ export function mdfind (id: string): Promise<string> {
throw notInstalledErr(id)
}

return execa
.stdout(cmd)
return utils.execa(cmd)
.then(prop('stdout'))
.then(tap(logFound))
.catch(failedToFind)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/launcher/lib/linux/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { log } from '../log'
import { partial, trim, tap } from 'ramda'
import { partial, trim, tap, prop } from 'ramda'
import { FoundBrowser, Browser } from '../types'
import { notInstalledErr } from '../errors'
import execa from 'execa'
import { utils } from '../utils'

function getLinuxBrowser (
name: string,
Expand Down Expand Up @@ -51,8 +51,8 @@ function getLinuxBrowser (
export function getVersionString (path: string) {
log('finding version string using command "%s --version"', path)

return execa
.stdout(path, ['--version'])
return utils.execa(path, ['--version'])
.then(prop('stdout'))
.then(trim)
.then(tap(partial(log, ['stdout: "%s"'])))
}
Expand Down
6 changes: 6 additions & 0 deletions packages/launcher/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import execa from 'execa'

// export an object for easy method stubbing
export const utils = {
execa,
}
7 changes: 4 additions & 3 deletions packages/launcher/lib/windows/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import execa from 'execa'
import fse from 'fs-extra'
import os from 'os'
import { join, normalize } from 'path'
import { tap, trim } from 'ramda'
import { tap, trim, prop } from 'ramda'
import { get } from 'lodash'
import { notInstalledErr } from '../errors'
import { log } from '../log'
import { Browser, FoundBrowser } from '../types'
import { utils } from '../utils'

function formFullAppPath (name: string) {
const prefix = 'C:/Program Files (x86)/Google/Chrome/Application'
Expand Down Expand Up @@ -172,7 +172,8 @@ export function getVersionString (path: string) {
'/value',
]

return execa.stdout('wmic', args)
return utils.execa('wmic', args)
.then(prop('stdout'))
.then(trim)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"bluebird": "3.5.3",
"debug": "4.1.1",
"execa": "1.0.0",
"execa": "4.0.0",
"fs-extra": "8.1.0",
"lodash": "4.17.15",
"plist": "2.1.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/launcher/test/unit/darwin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash'
import * as darwinHelper from '../../lib/darwin'
import * as linuxHelper from '../../lib/linux'
import * as darwinUtil from '../../lib/darwin/util'
import execa from 'execa'
import { utils } from '../../lib/utils'
import { expect } from 'chai'
import sinon, { SinonStub } from 'sinon'
import { browsers } from '../../lib/browsers'
Expand All @@ -24,9 +24,9 @@ function generatePlist (key, value) {
}

function stubBrowser (findAppParams: darwinUtil.FindAppParams) {
(execa.stdout as SinonStub)
(utils.execa as unknown as SinonStub)
.withArgs(`mdfind 'kMDItemCFBundleIdentifier=="${findAppParams.appId}"' | head -1`)
.resolves(`/Applications/${findAppParams.appName}`)
.resolves({ stdout: `/Applications/${findAppParams.appName}` })

;(fse.readFile as SinonStub)
.withArgs(`/Applications/${findAppParams.appName}/Contents/Info.plist`)
Expand All @@ -36,7 +36,7 @@ function stubBrowser (findAppParams: darwinUtil.FindAppParams) {
describe('darwin browser detection', () => {
beforeEach(() => {
sinon.stub(fse, 'readFile').rejects({ code: 'ENOENT' })
sinon.stub(execa, 'stdout').resolves('')
sinon.stub(utils, 'execa').resolves({ stdout: '' })
})

it('detects browsers as expected', async () => {
Expand Down
20 changes: 10 additions & 10 deletions packages/launcher/test/unit/detect_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('../spec_helper')
import { detect, detectByPath, setMajorVersion } from '../../lib/detect'
import { goalBrowsers } from '../fixtures'
import { expect } from 'chai'
import execa from 'execa'
import { utils } from '../../lib/utils'
import sinon, { SinonStub } from 'sinon'
const os = require('os')
import { log } from '../log'
Expand Down Expand Up @@ -50,21 +50,21 @@ describe('browser detection', () => {
})

context('#detectByPath', () => {
let stdout: SinonStub
let execa: SinonStub

beforeEach(() => {
stdout = sinon.stub(execa, 'stdout')
execa = sinon.stub(utils, 'execa')

stdout.withArgs('/Applications/My Shiny New Browser.app', ['--version'])
.resolves('foo-browser v100.1.2.3')
execa.withArgs('/Applications/My Shiny New Browser.app', ['--version'])
.resolves({ stdout: 'foo-browser v100.1.2.3' })

stdout.withArgs('/foo/bar/browser', ['--version'])
.resolves('foo-browser v9001.1.2.3')
execa.withArgs('/foo/bar/browser', ['--version'])
.resolves({ stdout: 'foo-browser v9001.1.2.3' })

stdout.withArgs('/not/a/browser', ['--version'])
.resolves('not a browser version string')
execa.withArgs('/not/a/browser', ['--version'])
.resolves({ stdout: 'not a browser version string' })

stdout.withArgs('/not/a/real/path', ['--version'])
execa.withArgs('/not/a/real/path', ['--version'])
.rejects()
})

Expand Down
Loading

4 comments on commit abf4d85

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on abf4d85 Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/linux-x64/circle-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-290178/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/circle-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-290161/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on abf4d85 Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on abf4d85 Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-x64/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.2.1/win32-x64/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-x64/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-x64/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-31698641/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on abf4d85 Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/darwin-x64/circle-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-290186/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/circle-develop-abf4d858694e1be3ae6b93da42c6678ad22ba290-290183/cypress.tgz

Please sign in to comment.