Skip to content

Commit

Permalink
Update update.js to work with Chrome for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
giggio committed Jul 24, 2023
1 parent c9ab40c commit 4ea3506
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions update.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const execSync = require('child_process').execSync;
const CURRENT_VERSION = require('./lib/chromedriver').version;

// fetch the latest chromedriver version
async function getLatest () {
const url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE';
async function getLatest() {
const url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json';
try {
const res = await fetch(url);
const text = await res.text();
return text.trim();
const data = await res.json();
return data?.channels?.Stable?.version;
} catch (err) {
console.log(err);
process.exit(1);
Expand All @@ -23,23 +23,28 @@ async function getLatest () {
- add a git tag using the new node-chromedriver version
- add a git commit, e.g. Bump version to 77.0.0
*/
const writeUpdate = (version) => {
async function writeUpdate(version) {
const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8');
const versionExport = 'exports.version';
const regex = new RegExp(`^.*${versionExport}.*$`, 'gm');
const updated = helper.replace(regex, `${versionExport} = '${version}';`);
fs.writeFileSync('./lib/chromedriver.js', updated, 'utf8');
const packageVersion = `${version.slice(0, version.indexOf('.'))}.0.0`;
execSync(`npm version ${packageVersion} --git-tag-version=false && git add . && git commit -m "Bump version to ${packageVersion}" && git tag -s ${packageVersion} -m ${packageVersion}`);
};
}

getLatest().then(version => {
if (CURRENT_VERSION === version) {
console.log('Chromedriver version is up to date.');
} else {
writeUpdate(version);
console.log(`Chromedriver version updated to ${version}`);
async function run() {
try {
const version = await getLatest();
if (CURRENT_VERSION === version) {
console.log('Chromedriver version is up to date.');
} else {
writeUpdate(version);
console.log(`Chromedriver version updated to ${version}`);
}
} catch (err) {
console.log(err);
}
}, err => {
console.log(err);
});
}

run();

0 comments on commit 4ea3506

Please sign in to comment.