ci: update auto-roller to be more robust (#10308)
This commit is contained in:
parent
78a5c0ad5c
commit
5b3ff64cf5
9
.github/workflows/update-browser-pins.yml
vendored
9
.github/workflows/update-browser-pins.yml
vendored
@ -30,11 +30,8 @@ jobs:
|
||||
id: update
|
||||
run: |
|
||||
node --experimental-fetch tools/update_chrome_revision.mjs
|
||||
- name: Format files if needed
|
||||
run: npm run format
|
||||
- name: Update package-lock.json
|
||||
run: npm install --ignore-scripts
|
||||
- name: Create Pull Request
|
||||
if: ${{ steps.update.outputs.commit }}
|
||||
uses: peter-evans/create-pull-request@284f54f989303d2699d373481a0cfa13ad5a6666 # v5.0.1
|
||||
with:
|
||||
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
|
||||
@ -42,7 +39,7 @@ jobs:
|
||||
delete-branch: true
|
||||
committer: Browser Automation Bot <browser-automation-bot@google.com>
|
||||
author: Browser Automation Bot <browser-automation-bot@google.com>
|
||||
commit-message: 'feat(chrome): roll to Chrome ${{ steps.update.outputs.version }} (r${{ steps.update.outputs.revision }})'
|
||||
title: 'feat(chrome): roll to Chrome ${{ steps.update.outputs.version }} (r${{ steps.update.outputs.revision }})'
|
||||
commit-message: ${{ steps.update.outputs.commit }}
|
||||
title: ${{ steps.update.outputs.commit }}
|
||||
body: 'Automatically generated by https://github.com/puppeteer/puppeteer/blob/main/.github/workflows/update-browser-pins.yml'
|
||||
labels: dependencies
|
||||
|
@ -19,6 +19,7 @@ import {writeFile, readFile} from 'fs/promises';
|
||||
|
||||
import actions from '@actions/core';
|
||||
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
|
||||
import {SemVer} from 'semver';
|
||||
|
||||
import packageJson from '../packages/puppeteer-core/package.json' assert {type: 'json'};
|
||||
import {versionsPerRelease, lastMaintainedChromeVersion} from '../versions.js';
|
||||
@ -27,6 +28,25 @@ const CHROME_CURRENT_VERSION = PUPPETEER_REVISIONS.chrome;
|
||||
const VERSIONS_PER_RELEASE_COMMENT =
|
||||
'// In Chrome roll patches, use `NEXT` for the Puppeteer version.';
|
||||
|
||||
function checkIfNeedsUpdate(oldVersion, newVersion, newRevision) {
|
||||
const oldSemVer = new SemVer(oldVersion, true);
|
||||
const newSemVer = new SemVer(newVersion, true);
|
||||
let message = `roll to Chrome ${newVersion} (r${newRevision})`;
|
||||
|
||||
if (newSemVer.compare(oldSemVer) <= 0) {
|
||||
// Exit the process without setting up version
|
||||
console.warn(
|
||||
`Version ${newVersion} is older then the current ${oldVersion}`
|
||||
);
|
||||
process.exit(0);
|
||||
} else if (newSemVer.compareMain(oldSemVer) === 0) {
|
||||
message = `fix: ${message}`;
|
||||
} else {
|
||||
message = `feat: ${message}`;
|
||||
}
|
||||
actions.setOutput('commit', message);
|
||||
}
|
||||
|
||||
async function replaceInFile(filePath, search, replace) {
|
||||
const buffer = await readFile(filePath);
|
||||
const update = buffer.toString().replace(search, replace);
|
||||
@ -90,6 +110,8 @@ async function updateVersionFileLastMaintained(updateVersion) {
|
||||
|
||||
const {version, revision} = await getVersionAndRevisionForStable();
|
||||
|
||||
checkIfNeedsUpdate(CHROME_CURRENT_VERSION, version, revision);
|
||||
|
||||
await replaceInFile(
|
||||
'./packages/puppeteer-core/src/revisions.ts',
|
||||
CHROME_CURRENT_VERSION,
|
||||
@ -99,5 +121,11 @@ await replaceInFile(
|
||||
await updateVersionFileLastMaintained(version);
|
||||
await updateDevToolsProtocolVersion(revision);
|
||||
|
||||
// Create new `package-lock.json` as we update devtools-protocol
|
||||
execSync('npm install --ignore-scripts');
|
||||
// Make sure we pass CI formatter check by running all the new files though it
|
||||
execSync('npm run format');
|
||||
|
||||
// Keep this as they can be used to debug GitHub Actions if needed
|
||||
actions.setOutput('version', version);
|
||||
actions.setOutput('revision', revision);
|
||||
|
Loading…
Reference in New Issue
Block a user