ci: update auto-roller to be more robust (#10308)

This commit is contained in:
Nikolay Vitkov 2023-06-02 15:37:48 +02:00 committed by GitHub
parent 78a5c0ad5c
commit 5b3ff64cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -30,11 +30,8 @@ jobs:
id: update id: update
run: | run: |
node --experimental-fetch tools/update_chrome_revision.mjs 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 - name: Create Pull Request
if: ${{ steps.update.outputs.commit }}
uses: peter-evans/create-pull-request@284f54f989303d2699d373481a0cfa13ad5a6666 # v5.0.1 uses: peter-evans/create-pull-request@284f54f989303d2699d373481a0cfa13ad5a6666 # v5.0.1
with: with:
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }} token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
@ -42,7 +39,7 @@ jobs:
delete-branch: true delete-branch: true
committer: Browser Automation Bot <browser-automation-bot@google.com> committer: Browser Automation Bot <browser-automation-bot@google.com>
author: 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 }})' commit-message: ${{ steps.update.outputs.commit }}
title: 'feat(chrome): roll to Chrome ${{ steps.update.outputs.version }} (r${{ steps.update.outputs.revision }})' title: ${{ steps.update.outputs.commit }}
body: 'Automatically generated by https://github.com/puppeteer/puppeteer/blob/main/.github/workflows/update-browser-pins.yml' body: 'Automatically generated by https://github.com/puppeteer/puppeteer/blob/main/.github/workflows/update-browser-pins.yml'
labels: dependencies labels: dependencies

View File

@ -19,6 +19,7 @@ import {writeFile, readFile} from 'fs/promises';
import actions from '@actions/core'; import actions from '@actions/core';
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js'; 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 packageJson from '../packages/puppeteer-core/package.json' assert {type: 'json'};
import {versionsPerRelease, lastMaintainedChromeVersion} from '../versions.js'; import {versionsPerRelease, lastMaintainedChromeVersion} from '../versions.js';
@ -27,6 +28,25 @@ const CHROME_CURRENT_VERSION = PUPPETEER_REVISIONS.chrome;
const VERSIONS_PER_RELEASE_COMMENT = const VERSIONS_PER_RELEASE_COMMENT =
'// In Chrome roll patches, use `NEXT` for the Puppeteer version.'; '// 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) { async function replaceInFile(filePath, search, replace) {
const buffer = await readFile(filePath); const buffer = await readFile(filePath);
const update = buffer.toString().replace(search, replace); const update = buffer.toString().replace(search, replace);
@ -90,6 +110,8 @@ async function updateVersionFileLastMaintained(updateVersion) {
const {version, revision} = await getVersionAndRevisionForStable(); const {version, revision} = await getVersionAndRevisionForStable();
checkIfNeedsUpdate(CHROME_CURRENT_VERSION, version, revision);
await replaceInFile( await replaceInFile(
'./packages/puppeteer-core/src/revisions.ts', './packages/puppeteer-core/src/revisions.ts',
CHROME_CURRENT_VERSION, CHROME_CURRENT_VERSION,
@ -99,5 +121,11 @@ await replaceInFile(
await updateVersionFileLastMaintained(version); await updateVersionFileLastMaintained(version);
await updateDevToolsProtocolVersion(revision); 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('version', version);
actions.setOutput('revision', revision); actions.setOutput('revision', revision);