mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
ci: make formatter run on changed files (#10328)
This commit is contained in:
parent
0371beebba
commit
7b8f1e2a0d
@ -46,6 +46,7 @@ CHANGELOG.md
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
test/assets/
|
test/assets/
|
||||||
docs/api
|
docs/api
|
||||||
|
docs/browsers-api
|
||||||
versioned_*/
|
versioned_*/
|
||||||
|
|
||||||
# Ng-schematics
|
# Ng-schematics
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {execSync} from 'child_process';
|
import {execSync, exec} from 'child_process';
|
||||||
import {writeFile, readFile} from 'fs/promises';
|
import {writeFile, readFile} from 'fs/promises';
|
||||||
|
import {promisify} from 'util';
|
||||||
|
|
||||||
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';
|
||||||
@ -24,10 +25,14 @@ 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';
|
||||||
|
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
const CHROME_CURRENT_VERSION = PUPPETEER_REVISIONS.chrome;
|
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.';
|
||||||
|
|
||||||
|
const touchedFiles = [];
|
||||||
|
|
||||||
function checkIfNeedsUpdate(oldVersion, newVersion, newRevision) {
|
function checkIfNeedsUpdate(oldVersion, newVersion, newRevision) {
|
||||||
const oldSemVer = new SemVer(oldVersion, true);
|
const oldSemVer = new SemVer(oldVersion, true);
|
||||||
const newSemVer = new SemVer(newVersion, true);
|
const newSemVer = new SemVer(newVersion, true);
|
||||||
@ -47,11 +52,30 @@ function checkIfNeedsUpdate(oldVersion, newVersion, newRevision) {
|
|||||||
actions.setOutput('commit', message);
|
actions.setOutput('commit', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We cant use `npm run format` as it's too slow
|
||||||
|
* so we only scope the files we updated
|
||||||
|
*/
|
||||||
|
async function formatUpdateFiles() {
|
||||||
|
await Promise.all(
|
||||||
|
touchedFiles.map(file => {
|
||||||
|
return execAsync(`npx eslint --ext js --ext ts --fix ${file}`);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
touchedFiles.map(file => {
|
||||||
|
return execAsync(`npx prettier --write ${file}`);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
await writeFile(filePath, update);
|
await writeFile(filePath, update);
|
||||||
|
|
||||||
|
touchedFiles.push(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVersionAndRevisionForStable() {
|
async function getVersionAndRevisionForStable() {
|
||||||
@ -86,17 +110,23 @@ async function updateDevToolsProtocolVersion(revision) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateVersionFileLastMaintained(updateVersion) {
|
async function updateVersionFileLastMaintained(currentVersion, updateVersion) {
|
||||||
const versions = [...versionsPerRelease.keys()];
|
const versions = [...versionsPerRelease.keys()];
|
||||||
if (version.indexOf(updateVersion) !== -1) {
|
if (versions.indexOf(updateVersion) !== -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await replaceInFile(
|
// If we have manually rolled Chrome but not yet released
|
||||||
'./versions.js',
|
// We will have NEXT as value in the Map
|
||||||
VERSIONS_PER_RELEASE_COMMENT,
|
if (versionsPerRelease.get(currentVersion) === 'NEXT') {
|
||||||
`${VERSIONS_PER_RELEASE_COMMENT}\n ['${version}', 'NEXT'],`
|
await replaceInFile('./versions.js', currentVersion, updateVersion);
|
||||||
);
|
} else {
|
||||||
|
await replaceInFile(
|
||||||
|
'./versions.js',
|
||||||
|
VERSIONS_PER_RELEASE_COMMENT,
|
||||||
|
`${VERSIONS_PER_RELEASE_COMMENT}\n ['${version}', 'NEXT'],`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const lastMaintainedIndex = versions.indexOf(lastMaintainedChromeVersion);
|
const lastMaintainedIndex = versions.indexOf(lastMaintainedChromeVersion);
|
||||||
const nextMaintainedVersion = versions[lastMaintainedIndex - 1];
|
const nextMaintainedVersion = versions[lastMaintainedIndex - 1];
|
||||||
@ -118,13 +148,13 @@ await replaceInFile(
|
|||||||
version
|
version
|
||||||
);
|
);
|
||||||
|
|
||||||
await updateVersionFileLastMaintained(version);
|
await updateVersionFileLastMaintained(CHROME_CURRENT_VERSION, version);
|
||||||
await updateDevToolsProtocolVersion(revision);
|
await updateDevToolsProtocolVersion(revision);
|
||||||
|
|
||||||
// Create new `package-lock.json` as we update devtools-protocol
|
// Create new `package-lock.json` as we update devtools-protocol
|
||||||
execSync('npm install --ignore-scripts');
|
execSync('npm install --ignore-scripts');
|
||||||
// Make sure we pass CI formatter check by running all the new files though it
|
// Make sure we pass CI formatter check by running all the new files though it
|
||||||
execSync('npm run format');
|
await formatUpdateFiles();
|
||||||
|
|
||||||
// Keep this as they can be used to debug GitHub Actions if needed
|
// Keep this as they can be used to debug GitHub Actions if needed
|
||||||
actions.setOutput('version', version);
|
actions.setOutput('version', version);
|
||||||
|
Loading…
Reference in New Issue
Block a user