mirror of
https://github.com/cypress-io/cypress.git
synced 2025-12-30 19:19:53 -06:00
* add husky script to build circleci yml files * add circleci cli as a required tool for working with .circleci * break the original workflows.yml file into separate pieces, using circleci config pack to compose them into the main workflows.yml file * fix pull request workflow def * more robust precommit for circleci packing * even nicer stdout for precommit :) * allow pr pipeline on this branch * split up the config.yml to demonstrate more fully * fix conditional on pr pipeline * exit 1 if circleci cli not found and circleci config files staged for commit * use linux-x64 executor for unit-tests * try using ipv6 in contributor with correct executor * ensure node * update github action to update browser versions to point to the correct file * ensure node more times * fix export * reduce expected result count * run full workflow menu on this branch * bump config class to medium * index on use-pack-for-circle:a9bcbe87b0run full workflow menu on this branch * index on use-pack-for-circle:a9bcbe87b0run full workflow menu on this branch * index on use-pack-for-circle:a9bcbe87b0run full workflow menu on this branch * revert to small for checkout code in config workflow; remove from multi branch trigger * fix incorrect conflict resolution for bettersqlite3 changes w/ electron update * make path to circleci workflows file more explicit, comment why it is that file --------- Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
132 lines
4.6 KiB
JavaScript
132 lines
4.6 KiB
JavaScript
const https = require('https')
|
|
const fs = require('fs')
|
|
const yaml = require('yaml')
|
|
const path = require('path')
|
|
|
|
const CHROME_STABLE_KEY = 'chrome-stable-version'
|
|
const CHROME_BETA_KEY = 'chrome-beta-version'
|
|
|
|
// This is the path to the CircleCI file that contains the browser version anchors
|
|
const CIRCLECI_WORKFLOWS_FILEPATH = path.join(__dirname, '../../.circleci/src/workflows/@workflows.yml')
|
|
|
|
// https://developer.chrome.com/docs/versionhistory/reference/#platform-identifiers
|
|
const getLatestVersionData = ({ channel, currentVersion }) => {
|
|
const options = {
|
|
hostname: 'versionhistory.googleapis.com',
|
|
port: 443,
|
|
path: `/v1/chrome/platforms/linux/channels/${channel}/versions?filter=version>${currentVersion}&order_by=version%20desc`,
|
|
method: 'GET',
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const req = https.request(options, (res) => {
|
|
let response = ''
|
|
|
|
res.on('data', (d) => {
|
|
response += d.toString()
|
|
})
|
|
|
|
res.on('end', () => {
|
|
resolve(response)
|
|
})
|
|
})
|
|
|
|
req.on('error', (err) => {
|
|
reject(err)
|
|
})
|
|
|
|
req.end()
|
|
})
|
|
}
|
|
|
|
const getVersions = async ({ core }) => {
|
|
try {
|
|
const doc = yaml.parseDocument(fs.readFileSync(CIRCLECI_WORKFLOWS_FILEPATH, 'utf8'))
|
|
|
|
const currentChromeStable = doc.contents.items.find((item) => item.key.value === CHROME_STABLE_KEY).value.value
|
|
const currentChromeBeta = doc.contents.items.find((item) => item.key.value === CHROME_BETA_KEY).value.value
|
|
|
|
const stableData = JSON.parse(await getLatestVersionData({ channel: 'stable', currentVersion: currentChromeStable }))
|
|
const betaData = JSON.parse(await getLatestVersionData({ channel: 'beta', currentVersion: currentChromeBeta }))
|
|
const hasStableUpdate = stableData.versions.length > 0
|
|
const hasBetaUpdate = betaData.versions.length > 0
|
|
let description = 'Update '
|
|
|
|
if (hasStableUpdate) {
|
|
description += `Chrome (stable) to ${stableData.versions[0].version}`
|
|
|
|
if (hasBetaUpdate) {
|
|
description += ' and '
|
|
}
|
|
}
|
|
|
|
if (hasBetaUpdate) {
|
|
description += `Chrome (beta) to ${betaData.versions[0].version}`
|
|
}
|
|
|
|
core.setOutput('has_update', (hasStableUpdate || hasBetaUpdate) ? 'true' : 'false')
|
|
core.setOutput('current_stable_version', currentChromeStable)
|
|
core.setOutput('latest_stable_version', hasStableUpdate ? stableData.versions[0].version : currentChromeStable)
|
|
core.setOutput('current_beta_version', currentChromeBeta)
|
|
core.setOutput('latest_beta_version', hasBetaUpdate ? betaData.versions[0].version : currentChromeBeta)
|
|
core.setOutput('description', description)
|
|
} catch (err) {
|
|
console.log('Errored checking for new Chrome versions:', err.stack)
|
|
core.setOutput('has_update', 'false')
|
|
}
|
|
}
|
|
|
|
const checkNeedForBranchUpdate = ({ core, latestStableVersion, latestBetaVersion }) => {
|
|
const doc = yaml.parseDocument(fs.readFileSync(CIRCLECI_WORKFLOWS_FILEPATH, 'utf8'))
|
|
|
|
const currentChromeStable = doc.contents.items.find((item) => item.key.value === CHROME_STABLE_KEY).value.value
|
|
const currentChromeBeta = doc.contents.items.find((item) => item.key.value === CHROME_BETA_KEY).value.value
|
|
|
|
const hasNewerStableVersion = currentChromeStable !== latestStableVersion
|
|
const hasNewerBetaVersion = currentChromeBeta !== latestBetaVersion
|
|
|
|
core.setOutput('has_newer_update', (hasNewerStableVersion || hasNewerBetaVersion) ? 'true' : 'false')
|
|
}
|
|
|
|
const updateBrowserVersionsFile = ({ latestBetaVersion, latestStableVersion }) => {
|
|
const doc = yaml.parseDocument(fs.readFileSync(CIRCLECI_WORKFLOWS_FILEPATH, 'utf8'))
|
|
|
|
const currentChromeStableYamlRef = doc.contents.items.find((item) => item.key.value === CHROME_STABLE_KEY)
|
|
const currentChromeBetaYamlRef = doc.contents.items.find((item) => item.key.value === CHROME_BETA_KEY)
|
|
|
|
currentChromeStableYamlRef.value.value = latestStableVersion
|
|
currentChromeBetaYamlRef.value.value = latestBetaVersion
|
|
|
|
fs.writeFileSync(CIRCLECI_WORKFLOWS_FILEPATH, yaml.stringify(doc), 'utf8')
|
|
}
|
|
|
|
const updatePRTitle = async ({ context, github, baseBranch, branchName, description }) => {
|
|
const { data } = await github.rest.pulls.list({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
base: baseBranch,
|
|
head: `${context.repo.owner}:${branchName}`,
|
|
})
|
|
|
|
if (!data.length) {
|
|
console.log('Could not find PR for branch:', branchName)
|
|
|
|
return
|
|
}
|
|
|
|
await github.rest.pulls.update({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: data[0].number,
|
|
title: `chore: ${description}`,
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
getVersions,
|
|
checkNeedForBranchUpdate,
|
|
updateBrowserVersionsFile,
|
|
updatePRTitle,
|
|
CIRCLECI_WORKFLOWS_FILEPATH,
|
|
}
|