Skip to content

Commit

Permalink
chore: updating browser version script to use versionhistory api (#27824
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mschile authored Sep 15, 2023
1 parent 8e68282 commit 5eaa4d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
25 changes: 12 additions & 13 deletions scripts/github-actions/update-browser-versions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const https = require('https')
const fs = require('fs')

const getLatestVersionData = () => {
// https://developer.chrome.com/docs/versionhistory/reference/#platform-identifiers
const getLatestVersionData = ({ channel, currentVersion }) => {
const options = {
hostname: 'omahaproxy.appspot.com',
hostname: 'versionhistory.googleapis.com',
port: 443,
path: '/all.json',
path: `/v1/chrome/platforms/linux/channels/${channel}/versions?filter=version>${currentVersion}&order_by=version%20desc`,
method: 'GET',
}

Expand Down Expand Up @@ -34,31 +35,29 @@ const getVersions = async ({ core }) => {
try {
// file path is relative to repo root
const currentBrowserVersions = JSON.parse(fs.readFileSync('./browser-versions.json'))
const data = JSON.parse(await getLatestVersionData())
const linuxData = data.find((item) => item.os === 'linux')
const stableData = linuxData.versions.find((version) => version.channel === 'stable')
const betaData = linuxData.versions.find((version) => version.channel === 'beta')
const hasStableUpdate = currentBrowserVersions['chrome:stable'] !== stableData.version
const hasBetaUpdate = currentBrowserVersions['chrome:beta'] !== betaData.version
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 hasStableUpdate = stableData.versions.length > 0
const hasBetaUpdate = betaData.versions.length > 0
let description = 'Update '

if (hasStableUpdate) {
description += `Chrome (stable) to ${stableData.version}`
description += `Chrome (stable) to ${stableData.versions[0].version}`

if (hasBetaUpdate) {
description += ' and '
}
}

if (hasBetaUpdate) {
description += `Chrome (beta) to ${betaData.version}`
description += `Chrome (beta) to ${betaData.versions[0].version}`
}

core.setOutput('has_update', (hasStableUpdate || hasBetaUpdate) ? 'true' : 'false')
core.setOutput('current_stable_version', currentBrowserVersions['chrome:stable'])
core.setOutput('latest_stable_version', stableData.version)
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', betaData.version)
core.setOutput('latest_beta_version', hasBetaUpdate ? betaData.versions[0].version : currentBrowserVersions['chrome:beta'])
core.setOutput('description', description)
} catch (err) {
console.log('Errored checking for new Chrome versions:', err.stack)
Expand Down
55 changes: 27 additions & 28 deletions scripts/unit/github-actions/update-browser-version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const coreStub = () => {
}
}

const stubOmahaResult = (result) => {
nock('https://omahaproxy.appspot.com')
.get('/all.json')
const stubChromeVersionResult = (channel, result) => {
nock('https://versionhistory.googleapis.com')
.get((uri) => uri.includes(channel))
.reply(200, result)
}

Expand All @@ -36,22 +36,28 @@ const stubRepoVersions = ({ betaVersion, stableVersion }) => {
})
}

const stubOmahaVersions = ({ betaVersion, stableVersion }) => {
stubOmahaResult([
const stubChromeVersions = ({ betaVersion, stableVersion }) => {
stubChromeVersionResult('stable',
{
os: 'linux',
versions: [
versions: stableVersion ? [
{
channel: 'stable',
name: `chrome/platforms/linux/channels/stable/versions/${stableVersion}`,
version: stableVersion,
},
] : [],
nextPageToken: '',
})

stubChromeVersionResult('beta',
{
versions: betaVersion ? [
{
channel: 'beta',
name: `chrome/platforms/linux/channels/beta/versions/${betaVersion}`,
version: betaVersion,
},
],
},
])
] : [],
nextPageToken: '',
})
}

describe('update browser version github action', () => {
Expand All @@ -70,8 +76,7 @@ describe('update browser version github action', () => {
})

it('sets has_update: true when there is a stable update', async () => {
stubOmahaVersions({
betaVersion: '1.1',
stubChromeVersions({
stableVersion: '2.0',
})

Expand All @@ -83,9 +88,8 @@ describe('update browser version github action', () => {
})

it('sets has_update: true when there is a beta update', async () => {
stubOmahaVersions({
stubChromeVersions({
betaVersion: '1.2',
stableVersion: '1.0',
})

const core = coreStub()
Expand All @@ -96,7 +100,7 @@ describe('update browser version github action', () => {
})

it('sets has_update: true when there is a stable update and a beta update', async () => {
stubOmahaVersions({
stubChromeVersions({
betaVersion: '2.1',
stableVersion: '2.0',
})
Expand All @@ -109,10 +113,7 @@ describe('update browser version github action', () => {
})

it('sets has_update: false when there is not a stable update or a beta update', async () => {
stubOmahaVersions({
betaVersion: '1.1',
stableVersion: '1.0',
})
stubChromeVersions({})

const core = coreStub()

Expand All @@ -122,7 +123,7 @@ describe('update browser version github action', () => {
})

it('sets has_update: false if there is a failure', async () => {
stubOmahaResult({})
stubChromeVersions({})

const core = coreStub()

Expand All @@ -132,7 +133,7 @@ describe('update browser version github action', () => {
})

it('sets versions', async () => {
stubOmahaVersions({
stubChromeVersions({
betaVersion: '2.1',
stableVersion: '2.0',
})
Expand All @@ -148,8 +149,7 @@ describe('update browser version github action', () => {
})

it('sets description correctly when there is a stable update', async () => {
stubOmahaVersions({
betaVersion: '1.1',
stubChromeVersions({
stableVersion: '2.0',
})

Expand All @@ -161,9 +161,8 @@ describe('update browser version github action', () => {
})

it('sets description correctly when there is a beta update', async () => {
stubOmahaVersions({
stubChromeVersions({
betaVersion: '1.2',
stableVersion: '1.0',
})

const core = coreStub()
Expand All @@ -174,7 +173,7 @@ describe('update browser version github action', () => {
})

it('sets description correctly when there is a stable update and a beta update', async () => {
stubOmahaVersions({
stubChromeVersions({
betaVersion: '2.1',
stableVersion: '2.0',
})
Expand Down

4 comments on commit 5eaa4d0

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5eaa4d0 Sep 15, 2023

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/13.3.0/linux-x64/develop-5eaa4d046caca1c1727d437270c48669e858940f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5eaa4d0 Sep 15, 2023

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/13.3.0/darwin-arm64/develop-5eaa4d046caca1c1727d437270c48669e858940f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5eaa4d0 Sep 15, 2023

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/13.3.0/darwin-x64/develop-5eaa4d046caca1c1727d437270c48669e858940f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5eaa4d0 Sep 15, 2023

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/13.3.0/win32-x64/develop-5eaa4d046caca1c1727d437270c48669e858940f/cypress.tgz

Please sign in to comment.