Skip to content

Commit

Permalink
Add action to create PR on update
Browse files Browse the repository at this point in the history
  • Loading branch information
giggio committed Sep 21, 2023
1 parent 48cb215 commit 87e8749
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/check-for-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: "Check for update"

on:
schedule:
- cron: "0 1 * * *"
workflow_dispatch:

permissions:
pull-requests: write

jobs:
action:
runs-on: ubuntu-latest
steps:
- run: |
./update.js --no-commit
VERSION=`node --eval 'console.log(require("./package.json").version)'`
echo "{NEW_VERSION}={$VERSION}" >> "$GITHUB_OUTPUT"
id: update
name: Run update
- uses: peter-evans/create-pull-request@v5
name: Create Pull Request
with:
commit-message: Bump version to ${{ steps.update.outputs.NEW_VERSION }}
branch: update-${{ steps.update.outputs.NEW_VERSION }}
delete-branch: true
title: Bump version to ${{ steps.update.outputs.NEW_VERSION }}
body: |
Update Chromedriver to version `${{ steps.update.outputs.NEW_VERSION }}`.
See: https://googlechromelabs.github.io/chrome-for-testing/
labels: |
update chromedriver
assignees: giggio
reviewers: giggio
15 changes: 9 additions & 6 deletions update.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function getLatest() {
const data = await res.json();
return data?.channels?.Stable?.version;
} catch (err) {
console.log(err);
console.error(err);
process.exit(1);
}
}
Expand All @@ -26,7 +26,7 @@ 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
*/
async function writeUpdate(newVersion) {
async function writeUpdate(newVersion, shouldCommit) {
const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8');
const versionExport = 'exports.version';
const regex = new RegExp(`^.*${versionExport}.*$`, 'gm');
Expand All @@ -36,23 +36,26 @@ async function writeUpdate(newVersion) {
const version = currentMajor !== newMajor ? `${newMajor}.0.0` : semver.inc(currentVersionInPackageJson, 'patch');
execSync(`npm version ${version} --git-tag-version=false`);
fs.writeFileSync('./lib/chromedriver.js', updated, 'utf8');
if (!shouldCommit) return;
execSync('git add :/');
execSync(`git commit -m "Bump version to ${version}"`);
execSync(`git tag -s ${version} -m ${version}`);
}

async function run() {
async function run(shouldCommit) {
try {
const latestVersion = await getLatest();
if (currentChromedriverVersion === latestVersion) {
console.log('Chromedriver version is up to date.');
} else {
writeUpdate(latestVersion);
writeUpdate(latestVersion, shouldCommit);
console.log(`Chromedriver version updated to ${latestVersion}`);
}
} catch (err) {
console.log(err);
console.error(err);
process.exit(1);
}
}

run();
const shouldCommit = process.argv.indexOf('--no-commit') == -1;
run(shouldCommit);

0 comments on commit 87e8749

Please sign in to comment.