mirror of
https://gh.wpcy.net/https://github.com/elementor/elementor.git
synced 2026-06-18 04:33:19 +08:00
## PR Checklist <!-- Please check if your PR fulfills the following requirements: **Filling out the template is required.** Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion. --> - [ ] The commit message follows our guidelines: https://github.com/elementor/elementor/blob/master/.github/CONTRIBUTING.md ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x" with no spaces eg: [x]. --> - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, local variables) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] CI related changes - [ ] Documentation content changes - [ ] Other... Please describe: ## Summary This PR can be summarized in the following changelog entry: * ## Description An explanation of what is done in this PR * ## Test instructions This PR can be tested by following these steps: * ## Quality assurance - [ ] I have tested this code to the best of my abilities - [ ] I have added unittests to verify the code works as intended - [ ] Docs have been added / updated (for bug fixes / features) Fixes # <!--start_gitstream_placeholder--> ### ✨ PR Description ## 1. Problem & Context Add tooling to update Playwright visual regression snapshots on-demand via GitHub Actions workflow, eliminating manual local snapshot regeneration and enabling targeted test coverage updates (ED-23800). ## 2. What Changed (Where) - `update-snapshots-linux.js`: Docker-based snapshot updater script that spawns Playwright tests with `--update-snapshots` flag - `.github/actions/setup-playwright-env/action.yml`: Reusable composite action provisioning WordPress, dependencies, and Playwright browsers - `.github/workflows/update-snapshots.yml`: Dispatch workflow supporting sharded batch runs (17 shards) plus targeted single-test runs with optional baseline reset ## 3. How It Works Workflow triggers via `workflow_dispatch` with configurable browser selection and grep filtering. For batch mode: 17 shards run in parallel updating snapshots independently, uploading artifacts. For targeted mode: single job runs matching `test_grep` pattern with configurable update mode (changed/all). Shared setup action handles PHP version injection, theme downloads, WordPress provisioning. Final `commit-snapshots` job consolidates artifacts and pushes changes back to branch. ## 4. Risks Docker availability assumption in `update-snapshots-linux.js` (checked at runtime but fails hard). Artifact merging could collide if same test path updated across shards—mitigated by grep-invert exclusions preventing overlap. No validation that snapshots actually changed; blindly commits if files differ, risking noisy PRs. _Generated by LinearB AI and added by gitStream._ <sub>AI-generated content may contain inaccuracies. Please verify before using. 💡 **Tip:** You can customize your AI Description using **Guidelines** [Learn how](https://docs.gitstream.cm/automation-actions/#describe-changes)</sub> <!--end_gitstream_placeholder-->
56 lines
1.5 KiB
JavaScript
Vendored
56 lines
1.5 KiB
JavaScript
Vendored
const { spawn, exec } = require( 'child_process' );
|
|
const packageJson = require( './package.json' );
|
|
|
|
function isDockerExist() {
|
|
return new Promise( ( resolve ) => {
|
|
exec( 'docker -v', ( error ) => {
|
|
resolve( ! error );
|
|
} );
|
|
} );
|
|
}
|
|
|
|
async function run( grep ) {
|
|
const playwrightVersion = packageJson.devDependencies[ '@playwright/test' ];
|
|
const workingDir = process.cwd();
|
|
const browsers = process.env.BROWSERS || 'chromium';
|
|
|
|
const command = 'docker run';
|
|
const options = [
|
|
'--rm',
|
|
'--network host',
|
|
`--volume ${ workingDir }:/work`,
|
|
'--workdir /work/',
|
|
`--env BROWSERS=${ browsers }`,
|
|
'--interactive',
|
|
process.env.CI ? '' : '--tty',
|
|
];
|
|
const image = `mcr.microsoft.com/playwright:v${ playwrightVersion.replace( '^', '' ) }-jammy`;
|
|
const grepFlag = grep.length ? `--grep="${ grep }"` : '';
|
|
const commandToRun = `/bin/bash -c "npm run test:playwright -- --update-snapshots ${ grepFlag }"`;
|
|
|
|
await new Promise( ( resolve, reject ) => {
|
|
const child = spawn( `${ command } ${ options.join( ' ' ) } ${ image } ${ commandToRun }`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
} );
|
|
|
|
child.on( 'close', ( code ) => {
|
|
if ( code !== 0 ) {
|
|
reject( new Error( `Docker process exited with code ${ code }` ) );
|
|
} else {
|
|
resolve();
|
|
}
|
|
} );
|
|
} );
|
|
}
|
|
|
|
( async () => {
|
|
if ( ! await isDockerExist() ) {
|
|
// eslint-disable-next-line no-console
|
|
console.error( 'Docker is not installed, please install it first.' );
|
|
|
|
process.exit( 1 );
|
|
}
|
|
|
|
await run( process.argv.slice( 2 ) );
|
|
} )();
|