Skip to content

Commit

Permalink
ci: update devtools-protocol automatically (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade authored Sep 18, 2023
1 parent 51f3860 commit ef098ec
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .browser
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected]
[email protected]
9 changes: 2 additions & 7 deletions .github/workflows/update-browser-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ jobs:
with:
node-version: lts/*
cache: npm
- uses: google/wireit@f3a3c79c553122e2fe5829eeac7d815326502903 # setup-github-actions-caching/v1
- name: Install and build npm dependencies
run: npm ci
- name: Download the latest version
run: |
browser_spec="$(npx @puppeteer/browsers install chrome@canary --path /tmp/browsers | cut -f 1 -d' ')"
echo "$browser_spec" > .browser
- name: Update browser pin and devtools-protocol
run: node tools/update_chrome_revision.mjs
- name: Create Pull Request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
with:
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repos:
- id: check-executables-have-shebangs
- id: check-yaml
- id: end-of-file-fixer
exclude: '.browser'
- id: name-tests-test
args: [--pytest-test-first]
- id: requirements-txt-fixer
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"chai-as-promised": "7.1.1",
"chai-exclude": "2.1.0",
"debug": "4.3.4",
"devtools-protocol": "0.0.1168520",
"devtools-protocol": "0.0.1195796",
"eslint": "8.46.0",
"eslint-config-prettier": "8.10.0",
"eslint-plugin-import": "2.28.1",
Expand Down
69 changes: 69 additions & 0 deletions tools/update_chrome_revision.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env node

/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {writeFile, readFile} from 'fs/promises';
import {execSync} from 'child_process';

import packageJson from '../package.json' assert {type: 'json'};

async function getVersionAndRevisionForCanary() {
const result = await fetch(
'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json'
).then((response) => {
return response.json();
});

const {version, revision} = result.channels['Canary'];

return {
version,
revision,
};
}

async function updateDevToolsProtocolVersion(revision) {
const currentProtocol = packageJson.devDependencies['devtools-protocol'];
const command = `npm view "devtools-protocol@<=0.0.${revision}" version | tail -1`;

const bestNewProtocol = execSync(command, {
encoding: 'utf8',
})
.split(' ')[1]
.replace(/'|\n/g, '');

const buffer = await readFile('./package.json');
const update = buffer
.toString()
.replace(
`"devtools-protocol": "${currentProtocol}"`,
`"devtools-protocol": "${bestNewProtocol}"`
);
await writeFile('./package.json', update);
}

const {version, revision} = await getVersionAndRevisionForCanary();
await updateDevToolsProtocolVersion(revision);

const browserVersion = `chrome@${version}`;
await writeFile('./.browser', browserVersion, 'utf-8');

// Create new `package-lock.json` as we update devtools-protocol
execSync('npm install --ignore-scripts');
// Make sure that the `package-lock.json` is formatted correctly
execSync(`npx prettier --write ./package.json`);

0 comments on commit ef098ec

Please sign in to comment.