mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-06 06:29:45 -06:00
chore: move browser-versions.json values straight into the workflow yaml (#30989)
* use env variables in yaml [run ci] * add husky hook to lint-staged to format the circle workflow file on commit when the file changes to keep the diff from the github actions job short * chore: cut over browser-version scripts from json to yaml to update the workflow file inline * Update scripts/format-workflow-file.js Co-authored-by: Matt Schile <mschile@cypress.io> * move expected yaml keys to const variables --------- Co-authored-by: Matt Schile <mschile@cypress.io>
This commit is contained in:
17
scripts/format-workflow-file.js
Normal file
17
scripts/format-workflow-file.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const fs = require('fs')
|
||||
const yaml = require('yaml')
|
||||
|
||||
/**
|
||||
* from root of directory run:
|
||||
* node ./scripts/format-workflow-file.js
|
||||
*
|
||||
* This script is also executed as a pre-commit hook in husky to ensure the workflow file is always formatted correctly
|
||||
*/
|
||||
const formatWorkflowFile = () => {
|
||||
// file path is relative to repo root
|
||||
const doc = yaml.parseDocument(fs.readFileSync('./.circleci/workflows.yml', 'utf8'))
|
||||
|
||||
fs.writeFileSync('./.circleci/workflows.yml', yaml.stringify(doc), 'utf8')
|
||||
}
|
||||
|
||||
formatWorkflowFile()
|
||||
@@ -1,4 +0,0 @@
|
||||
const versions = require('../browser-versions')
|
||||
const channel = process.argv[2]
|
||||
|
||||
process.stdout.write(versions[channel])
|
||||
@@ -1,5 +1,9 @@
|
||||
const https = require('https')
|
||||
const fs = require('fs')
|
||||
const yaml = require('yaml')
|
||||
|
||||
const CHROME_STABLE_KEY = 'chrome-stable-version'
|
||||
const CHROME_BETA_KEY = 'chrome-beta-version'
|
||||
|
||||
// https://developer.chrome.com/docs/versionhistory/reference/#platform-identifiers
|
||||
const getLatestVersionData = ({ channel, currentVersion }) => {
|
||||
@@ -34,9 +38,13 @@ const getLatestVersionData = ({ channel, currentVersion }) => {
|
||||
const getVersions = async ({ core }) => {
|
||||
try {
|
||||
// file path is relative to repo root
|
||||
const currentBrowserVersions = JSON.parse(fs.readFileSync('./browser-versions.json'))
|
||||
const stableData = JSON.parse(await getLatestVersionData({ channel: 'stable', currentVersion: currentBrowserVersions['chrome:stable'] }))
|
||||
const betaData = JSON.parse(await getLatestVersionData({ channel: 'beta', currentVersion: currentBrowserVersions['chrome:beta'] }))
|
||||
const doc = yaml.parseDocument(fs.readFileSync('./.circleci/workflows.yml', '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 '
|
||||
@@ -54,10 +62,10 @@ const getVersions = async ({ core }) => {
|
||||
}
|
||||
|
||||
core.setOutput('has_update', (hasStableUpdate || hasBetaUpdate) ? 'true' : 'false')
|
||||
core.setOutput('current_stable_version', currentBrowserVersions['chrome:stable'])
|
||||
core.setOutput('latest_stable_version', hasStableUpdate ? stableData.versions[0].version : currentBrowserVersions['chrome:stable'])
|
||||
core.setOutput('current_beta_version', currentBrowserVersions['chrome:beta'])
|
||||
core.setOutput('latest_beta_version', hasBetaUpdate ? betaData.versions[0].version : currentBrowserVersions['chrome:beta'])
|
||||
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)
|
||||
@@ -67,22 +75,28 @@ const getVersions = async ({ core }) => {
|
||||
|
||||
const checkNeedForBranchUpdate = ({ core, latestStableVersion, latestBetaVersion }) => {
|
||||
// file path is relative to repo root
|
||||
const branchBrowserVersions = JSON.parse(fs.readFileSync('./browser-versions.json'))
|
||||
const hasNewerStableVersion = branchBrowserVersions['chrome:stable'] !== latestStableVersion
|
||||
const hasNewerBetaVersion = branchBrowserVersions['chrome:beta'] !== latestBetaVersion
|
||||
const doc = yaml.parseDocument(fs.readFileSync('./.circleci/workflows.yml', '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 currentBrowserVersions = JSON.parse(fs.readFileSync('./browser-versions.json'))
|
||||
const newVersions = Object.assign(currentBrowserVersions, {
|
||||
'chrome:beta': latestBetaVersion,
|
||||
'chrome:stable': latestStableVersion,
|
||||
})
|
||||
const doc = yaml.parseDocument(fs.readFileSync('./.circleci/workflows.yml', '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
|
||||
|
||||
// file path is relative to repo root
|
||||
fs.writeFileSync('./browser-versions.json', `${JSON.stringify(newVersions, null, 2) }\n`)
|
||||
fs.writeFileSync('./.circleci/workflows.yml', yaml.stringify(doc), 'utf8')
|
||||
}
|
||||
|
||||
const updatePRTitle = async ({ context, github, baseBranch, branchName, description }) => {
|
||||
|
||||
@@ -29,10 +29,7 @@ const stubChromeVersionResult = (channel, result) => {
|
||||
|
||||
const stubRepoVersions = ({ betaVersion, stableVersion }) => {
|
||||
mockfs({
|
||||
'./browser-versions.json': JSON.stringify({
|
||||
'chrome:beta': betaVersion,
|
||||
'chrome:stable': stableVersion,
|
||||
}),
|
||||
'./.circleci/workflows.yml': `chrome-stable-version: &chrome-stable-version "${stableVersion}"\nchrome-beta-version: &chrome-beta-version "${betaVersion}"\n`,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -245,11 +242,10 @@ describe('update browser version github action', () => {
|
||||
|
||||
context('.updateBrowserVersionsFile', () => {
|
||||
it('updates browser-versions.json with specified versions, leaving other entries in place', () => {
|
||||
sinon.stub(fs, 'readFileSync').returns(`{
|
||||
"chrome:beta": "1.1",
|
||||
"chrome:stable": "1.0",
|
||||
"chrome:other": "0.4"
|
||||
}`)
|
||||
stubRepoVersions({
|
||||
betaVersion: '1.1',
|
||||
stableVersion: '1.0',
|
||||
})
|
||||
|
||||
sinon.stub(fs, 'writeFileSync')
|
||||
|
||||
@@ -258,12 +254,7 @@ describe('update browser version github action', () => {
|
||||
latestStableVersion: '2.0',
|
||||
})
|
||||
|
||||
expect(fs.writeFileSync).to.be.calledWith('./browser-versions.json', `{
|
||||
"chrome:beta": "2.1",
|
||||
"chrome:stable": "2.0",
|
||||
"chrome:other": "0.4"
|
||||
}
|
||||
`)
|
||||
expect(fs.writeFileSync).to.be.calledWith('./.circleci/workflows.yml', `chrome-stable-version: &chrome-stable-version "2.0"\nchrome-beta-version: &chrome-beta-version "2.1"\n`, 'utf8')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user