Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updating browser version script to use versionhistory api #27824

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading