Skip to content

Commit

Permalink
chore: move browser-versions.json values straight into the workflow y…
Browse files Browse the repository at this point in the history
…aml (#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 <[email protected]>

* move expected yaml keys to const variables

---------

Co-authored-by: Matt Schile <[email protected]>
  • Loading branch information
AtofStryker and mschile authored Feb 5, 2025
1 parent bd62045 commit fec6912
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 164 deletions.
335 changes: 217 additions & 118 deletions .circleci/workflows.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .github/workflows/update-browser-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: install dependencies
run: CI=true yarn
- name: Check for new Chrome versions
id: get-versions
uses: actions/github-script@v7
Expand Down
5 changes: 0 additions & 5 deletions browser-versions.json

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"tree-kill": "1.2.2",
"ts-node": "^10.9.2",
"typescript": "5.3.3",
"yaml": "2.7.0",
"yarn-deduplicate": "3.1.0"
},
"engines": {
Expand Down Expand Up @@ -263,7 +264,8 @@
},
"lint-staged": {
"*.coffee": "yarn stop-only --folder",
"*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix"
"*.{js,jsx,ts,tsx,json,eslintrc,vue}": "eslint --fix",
"*workflows.yml": "node scripts/format-workflow-file.js"
},
"resolutions": {
"**/@types/cheerio": "0.22.21",
Expand Down
17 changes: 17 additions & 0 deletions scripts/format-workflow-file.js
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 0 additions & 4 deletions scripts/get-browser-version.js

This file was deleted.

46 changes: 30 additions & 16 deletions scripts/github-actions/update-browser-versions.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down Expand Up @@ -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 '
Expand All @@ -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)
Expand All @@ -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 }) => {
Expand Down
21 changes: 6 additions & 15 deletions scripts/unit/github-actions/update-browser-version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
})
}

Expand Down Expand Up @@ -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')

Expand All @@ -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')
})
})

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33104,16 +33104,16 @@ yaml-eslint-parser@^1.2.2:
lodash "^4.17.21"
yaml "^2.0.0"

[email protected], yaml@^2.0.0, yaml@^2.3.4, yaml@^2.4.1, yaml@^2.6.0:
version "2.7.0"
resolved "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz#aef9bb617a64c937a9a748803786ad8d3ffe1e98"
integrity sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==

yaml@^1.10.0:
version "1.10.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==

yaml@^2.0.0, yaml@^2.3.4, yaml@^2.4.1, yaml@^2.6.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.7.0.tgz#aef9bb617a64c937a9a748803786ad8d3ffe1e98"
integrity sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==

[email protected]:
version "13.1.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0"
Expand Down

5 comments on commit fec6912

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fec6912 Feb 5, 2025

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.3/linux-arm64/develop-fec6912cf93fe602e67f08b4b5c73c3f1bd6b94e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fec6912 Feb 5, 2025

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.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.3/linux-x64/develop-fec6912cf93fe602e67f08b4b5c73c3f1bd6b94e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fec6912 Feb 5, 2025

Choose a reason for hiding this comment

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

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

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.3/win32-x64/develop-fec6912cf93fe602e67f08b4b5c73c3f1bd6b94e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fec6912 Feb 5, 2025

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.3/darwin-arm64/develop-fec6912cf93fe602e67f08b4b5c73c3f1bd6b94e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fec6912 Feb 5, 2025

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.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.3/darwin-x64/develop-fec6912cf93fe602e67f08b4b5c73c3f1bd6b94e/cypress.tgz

Please sign in to comment.