Skip to content

Commit

Permalink
Merge branch 'develop' into issue-25239-expose-current-retry
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed Dec 29, 2022
2 parents 6bc0543 + 285e2b3 commit 1be425b
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 78 deletions.
109 changes: 80 additions & 29 deletions packages/electron/lib/install.js
Expand Up @@ -2,8 +2,11 @@
const _ = require('lodash')
const os = require('os')
const path = require('path')
const systeminformation = require('systeminformation')
const execa = require('execa')

const paths = require('./paths')
const log = require('debug')('cypress:electron')
const debug = require('debug')('cypress:electron')
const fs = require('fs-extra')
const crypto = require('crypto')
const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses')
Expand All @@ -27,9 +30,7 @@ module.exports = {
return require('@packages/icons')
},

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

checkCurrentVersion (pathToVersion) {
// read in the version file
return fs.readFile(pathToVersion, 'utf8')
.then((str) => {
Expand All @@ -55,6 +56,7 @@ module.exports = {
},

checkIconVersion () {
// TODO: this seems wrong, it's hard coding the check only for OSX and not windows or linux (!?)
const mainIconsPath = this.icons().getPathToIcon('cypress.icns')
const cachedIconsPath = path.join(__dirname, '../dist/Cypress/Cypress.app/Contents/Resources/electron.icns')

Expand All @@ -66,8 +68,30 @@ module.exports = {
})
},

checkExecExistence () {
return fs.stat(paths.getPathToExec())
checkExecExistence (pathToExec) {
return fs.stat(pathToExec)
},

async checkBinaryArchCpuArch (pathToExec, platform, arch) {
if (platform === 'darwin' && arch === 'x64') {
return Promise.all([
// get the current arch of the binary
execa('lipo', ['-archs', pathToExec])
.then(({ stdout }) => {
return stdout
}),

// get the real arch of the system
this.getRealArch(platform, arch),
])
.then(([binaryArch, cpuArch]) => {
debug('archs detected %o', { binaryArch, cpuArch })

if (binaryArch !== cpuArch) {
throw new Error(`built binary arch: '${binaryArch}' does not match system CPU arch: '${cpuArch}', binary needs rebuilding`)
}
})
}
},

move (src, dest) {
Expand All @@ -94,44 +118,62 @@ module.exports = {
})
},

async getRealArch (platform, arch) {
if (platform === 'darwin' && arch === 'x64') {
// see this comment for explanation of x64 -> arm64 translation
// https://github.com/cypress-io/cypress/pull/25014/files#diff-85c4db7620ed2731baf5669a9c9993e61e620693a008199ca7c584e621b6a1fdR11
return systeminformation.cpu()
.then(({ manufacturer }) => {
// if the cpu is apple then return arm64 as the arch
return manufacturer === 'Apple' ? 'arm64' : arch
})
}

return arch
},

package (options = {}) {
const pkgr = require('electron-packager')
const icons = require('@packages/icons')

const iconPath = icons.getPathToIcon('cypress')

log('package icon', iconPath)
debug('package icon', iconPath)

const platform = os.platform()
const arch = os.arch()

_.defaults(options, {
dist: paths.getPathToDist(),
dir: 'app',
out: 'tmp',
name: 'Cypress',
platform,
arch,
asar: false,
prune: true,
overwrite: true,
electronVersion,
icon: iconPath,
return this.getRealArch(platform, arch)
.then((arch) => {
_.defaults(options, {
dist: paths.getPathToDist(),
dir: 'app',
out: 'tmp',
name: 'Cypress',
platform,
arch,
asar: false,
prune: true,
overwrite: true,
electronVersion,
icon: iconPath,
})

debug('packager options %j', options)

return pkgr(options)
})

log('packager options %j', options)

return pkgr(options)
.then((appPaths) => {
return appPaths[0]
})
// Promise.resolve("tmp\\Cypress-win32-x64")
.then((appPath) => {
const { dist } = options

// and now move the tmp into dist
console.log('moving created file from', appPath)
console.log('to', options.dist)
debug('moving created file %o', { from: appPath, to: dist })

return this.move(appPath, options.dist)
return this.move(appPath, dist)
})
.then(() => {
return !['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE) ? flipFuses(
Expand All @@ -150,22 +192,31 @@ module.exports = {
},

ensure () {
const arch = os.arch()
const platform = os.platform()
const pathToExec = paths.getPathToExec()
const pathToVersion = paths.getPathToVersion()

return Promise.all([
// check the version of electron and re-build if updated
this.checkCurrentVersion(),
this.checkCurrentVersion(pathToVersion),
// check if the dist folder exist and re-build if not
this.checkExecExistence(),
this.checkExecExistence(pathToExec),
// Compare the icon in dist with the one in the icons
// package. If different, force the re-build.
this.checkIconVersion(),
])
.then(() => {
// check that the arch of the built binary matches our CPU
return this.checkBinaryArchCpuArch(pathToExec, platform, arch)
})

// if all is good, then return without packaging a new electron app
},

check () {
return this.ensure()
.catch(() => {
.catch((err) => {
this.packageAndExit()
})
},
Expand Down
3 changes: 2 additions & 1 deletion packages/electron/package.json
Expand Up @@ -27,7 +27,8 @@
"electron-packager": "15.4.0",
"execa": "4.1.0",
"mocha": "3.5.3",
"rimraf": "3.0.2"
"rimraf": "3.0.2",
"systeminformation": "5.16.9"
},
"files": [
"dist",
Expand Down
34 changes: 29 additions & 5 deletions packages/server/lib/util/ci_provider.js
Expand Up @@ -132,6 +132,15 @@ const _detectProviderName = () => {
})
}

// User provided environment variables are used to allow users to define their own
// values should the CI provider not have an existing or correct mapping from the list below.
const _userProvidedProviderCiParams = () => {
return extract([
'CYPRESS_PULL_REQUEST_ID',
'CYPRESS_PULL_REQUEST_URL',
'CYPRESS_CI_BUILD_URL',
])
}
// TODO: don't forget about buildNumber!
// look at the old commit that was removed to see how we did it
const _providerCiParams = () => {
Expand Down Expand Up @@ -299,11 +308,21 @@ const _providerCiParams = () => {
'SHORT_SHA',
// https://cloud.google.com/cloud-build/docs/api/reference/rest/Shared.Types/Build
]),
/**
* References:
* https://ci.eclipse.org/webtools/env-vars.html/
* https://www.jenkins.io/doc/book/pipeline/multibranch/#additional-environment-variables
*/
jenkins: extract([
'BUILD_ID',
'BUILD_URL',
'BUILD_NUMBER',
'ghprbPullId',
// Jenkins pipeline options change options
'CHANGE_ID',
'CHANGE_URL',
'CHANGE_TARGET',
'CHANGE_TITLE',
]),
// https://semaphoreci.com/docs/available-environment-variables.html
// some come from v1, some from v2 of semaphore
Expand Down Expand Up @@ -539,10 +558,10 @@ const _providerCommitParams = () => {
},
jenkins: {
sha: env.GIT_COMMIT,
branch: env.GIT_BRANCH,
// message: ???
// authorName: ???
// authorEmail: ???
branch: env.GIT_BRANCH || env.BRANCH_NAME || env.CHANGE_BRANCH,
// message: ??,
authorName: env.GIT_AUTHOR_NAME || env.CHANGE_AUTHOR_DISPLAY_NAME,
authorEmail: env.GIT_AUTHOR_EMAIL || env.CHANGE_AUTHOR_EMAIL,
// remoteOrigin: ???
// defaultBranch: ???
},
Expand Down Expand Up @@ -617,7 +636,12 @@ const _get = (fn) => {
}

const ciParams = () => {
return _get(_providerCiParams)
const ciParams = {
..._.chain(_userProvidedProviderCiParams()).thru(omitUndefined).defaultTo(null).value(),
..._get(_providerCiParams),
}

return Object.keys(ciParams).length > 0 ? ciParams : null
}

const commitParams = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Expand Up @@ -111,7 +111,7 @@
"squirrelly": "7.9.2",
"strip-ansi": "6.0.0",
"syntax-error": "1.4.0",
"systeminformation": "5.6.4",
"systeminformation": "5.16.9",
"term-size": "2.1.0",
"through": "2.3.8",
"tough-cookie": "4.0.0",
Expand Down

0 comments on commit 1be425b

Please sign in to comment.