diff --git a/scripts/github-actions/update-browser-versions.js b/scripts/github-actions/update-browser-versions.js index a6fae9560319..b6813a32b1cc 100644 --- a/scripts/github-actions/update-browser-versions.js +++ b/scripts/github-actions/update-browser-versions.js @@ -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', } @@ -34,16 +35,14 @@ 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 ' @@ -51,14 +50,14 @@ const getVersions = async ({ core }) => { } 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) diff --git a/scripts/unit/github-actions/update-browser-version-spec.js b/scripts/unit/github-actions/update-browser-version-spec.js index 5d78c1317bd4..40892cb2838c 100644 --- a/scripts/unit/github-actions/update-browser-version-spec.js +++ b/scripts/unit/github-actions/update-browser-version-spec.js @@ -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) } @@ -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', () => { @@ -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', }) @@ -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() @@ -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', }) @@ -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() @@ -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() @@ -132,7 +133,7 @@ describe('update browser version github action', () => { }) it('sets versions', async () => { - stubOmahaVersions({ + stubChromeVersions({ betaVersion: '2.1', stableVersion: '2.0', }) @@ -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', }) @@ -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() @@ -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', })