Files
cypress/scripts/binary/binary-sources.js
Cacie Prins 3288aa5069 chore(dependency): Upgrade Electron 27 (#28792)
* dependency: upgrades electron from 25 to 26

* bump cache run ci

* fix docker img names

* ref electron upgrade branch

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* debug

* debug

* debug

* update search string for resize observer error swallow

* debug

* update integrity check

* update electron readme with upgrade troubleshooting section

* point to new publish binary workflow branch for electron 27

* update electron readme with locations of chromium & node versions for a given electron version

* update node versions and docker image refs

* update electron version to 27.1.3

* fix db nativeBinding arg

* chore: updating v8 snapshot cache

* install setuptools on mac when updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* run workflows on this branch run ci

* require addon directly and pass to better-sqlite3 init; debug

* rm debug

* try loading better-sqlite with a more dynamic filename

* bump electron version

* bump electron version

* bump electron version -- run ci

* bump electron version -- run ci

* bump electron version -- run ci

* bump electron version -- run ci

* bump electron version -- run ci

* add a step to update workflows.yml to electron upgrade process

* reduce retry limit on issue 1244 test to prevent circle from thinking tests have hanged

* target main branch of binary publish workflow? run ci

* Update .node-version -- run ci

* Update CHANGELOG.md

* Update module_api_spec.ts

* point publish binary back to electron upgrade branch

* Adds some logging re: cachedDataVersion

* use precise electron version for better-sqlite3 for centos7

* Update CHANGELOG.md

* chore: fix issue with bytenode (#28568)

* fix jsc for 27 -- run ci

* Update smoke.js

* fix build

* update electron upgrade steps

* Update packages/electron/README.md

Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>

* Update cli/CHANGELOG.md

Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>

* fix DebugEmptyStates component test

* try to fix downstream build -- run ci (#28649)

Co-authored-by: Cacie Prins <cacieprins@users.noreply.github.com>

* point to consolidated binary publish branch

* revert webpack-preprocessor-awesome-typescript-loader update

* revert certain system tests

* increase padding for module api system test duration window

* account for differing screenshot sizes

* screenshot size differs locally vs ci

* update protocol snapshots

* Update after-pack-hook.js

* fix flaky slideshow

* correct the chromium version in changelog

* use 18.17.1 internal images

* workflow filters

* fix trailing checkbox in electron readme

* add solution to crashing better-sqlite3 in electron readme

* Update packages/electron/README.md

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* Update scripts/after-pack-hook.js

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* Update scripts/after-pack-hook.js

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* Update scripts/after-pack-hook.js

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* add branch to setup_should_persist_artifacts

* debug app e2e test

* bump cache

* upgrade browsers-internal to chrome 121

* revert to chrome 118 images

* bump cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* bump cache

---------

Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>
Co-authored-by: Bill Glesias <bglesias@gmail.com>
2024-02-15 10:33:51 -05:00

133 lines
4.5 KiB
JavaScript

const fs = require('fs-extra')
const crypto = require('crypto')
const path = require('path')
const esbuild = require('esbuild')
const escapeString = (string) => string.replaceAll(`\``, `\\\``).replaceAll(`$`, `\\$`)
const secret = require('crypto').randomBytes(48).toString('hex')
const DUMMY_INDEX_JSC_HASH = 'abcddcbaabcddcbaabcddcbaabcddcba'
function read (file) {
const pathToFile = require.resolve(`./${file}`)
return fs.readFileSync(pathToFile, 'utf8')
}
const getBinaryEntryPointSource = async () => {
const esbuildResult = await esbuild.build({
entryPoints: [require.resolve('./binary-entry-point-source.js')],
bundle: true,
platform: 'node',
write: false,
minify: true,
treeShaking: true,
})
return esbuildResult.outputFiles[0].text
}
const getBinaryByteNodeEntryPointSource = async () => {
const esbuildResult = await esbuild.build({
entryPoints: [require.resolve('./binary-byte-node-entry-point-source.js')],
bundle: true,
platform: 'node',
write: false,
minify: true,
treeShaking: true,
})
return esbuildResult.outputFiles[0].text
}
const getIntegrityCheckSource = (baseDirectory) => {
const fileSource = read('binary-integrity-check-source.js')
const mainIndexHash = crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './index.js'), 'utf8')).digest('hex')
return fileSource.split('\n').join(`\n `)
.replaceAll('MAIN_INDEX_HASH', mainIndexHash)
.replaceAll('INDEX_JSC_HASH', DUMMY_INDEX_JSC_HASH)
.replaceAll('HMAC_SECRET', secret)
.replaceAll('CRYPTO_CREATE_HMAC_TO_STRING', escapeString(crypto.createHmac.toString()))
.replaceAll('CRYPTO_HMAC_UPDATE_TO_STRING', escapeString(crypto.Hmac.prototype.update.toString()))
.replaceAll('CRYPTO_HMAC_DIGEST_TO_STRING', escapeString(crypto.Hmac.prototype.digest.toString()))
}
const getIndexJscHash = (baseDirectory) => {
return crypto.createHmac('md5', secret).update(fs.readFileSync(path.join(baseDirectory, './packages/server/index.jsc'), 'utf8')).digest('hex')
}
const getEncryptionFileSource = async (encryptionFilePath) => {
const fileContents = await fs.readFile(encryptionFilePath, 'utf8')
if (!fileContents.includes(`test: CY_TEST,`)) {
throw new Error(`Expected to find test key in cloud encryption file`)
}
return fileContents.replace(`test: CY_TEST,`, '').replace(/const CY_TEST = `(.*?)`/, '')
}
const validateEncryptionFile = async (encryptionFilePath) => {
const afterReplaceEncryption = await fs.readFile(encryptionFilePath, 'utf8')
if (afterReplaceEncryption.includes('CY_TEST')) {
throw new Error(`Expected test key to be stripped from cloud encryption file`)
}
}
const getCloudEnvironmentFileSource = async (cloudApiFilePath) => {
const fileContents = await fs.readFile(cloudApiFilePath, 'utf8')
if (!fileContents.includes('process.env.CYPRESS_ENV_DEPENDENCIES')) {
throw new Error(`Expected to find CYPRESS_ENV_DEPENDENCIES in cloud api file`)
}
if (process.env.CYPRESS_ENV_DEPENDENCIES) {
return fileContents.replace('process.env.CYPRESS_ENV_DEPENDENCIES', `'${process.env.CYPRESS_ENV_DEPENDENCIES}'`)
}
return fileContents
}
const validateCloudEnvironmentFile = async (cloudApiFilePath) => {
if (process.env.CYPRESS_ENV_DEPENDENCIES) {
const afterReplaceCloudApi = await fs.readFile(cloudApiFilePath, 'utf8')
if (afterReplaceCloudApi.includes('process.env.CYPRESS_ENV_DEPENDENCIES')) {
throw new Error(`Expected process.env.CYPRESS_ENV_DEPENDENCIES to be stripped from cloud api file`)
}
}
}
const getProtocolFileSource = async (protocolFilePath) => {
const fileContents = await fs.readFile(protocolFilePath, 'utf8')
if (!fileContents.includes('process.env.CYPRESS_LOCAL_PROTOCOL_PATH')) {
throw new Error(`Expected to find CYPRESS_LOCAL_PROTOCOL_PATH in protocol file`)
}
return fileContents.replaceAll('process.env.CYPRESS_LOCAL_PROTOCOL_PATH', 'undefined')
}
const validateProtocolFile = async (protocolFilePath) => {
const afterReplaceProtocol = await fs.readFile(protocolFilePath, 'utf8')
if (afterReplaceProtocol.includes('process.env.CYPRESS_LOCAL_PROTOCOL_PATH')) {
throw new Error(`Expected process.env.CYPRESS_LOCAL_PROTOCOL_PATH to be stripped from protocol file`)
}
}
module.exports = {
getBinaryEntryPointSource,
getBinaryByteNodeEntryPointSource,
getIntegrityCheckSource,
getEncryptionFileSource,
validateEncryptionFile,
getCloudEnvironmentFileSource,
validateCloudEnvironmentFile,
getProtocolFileSource,
validateProtocolFile,
getIndexJscHash,
DUMMY_INDEX_JSC_HASH,
}