Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance tests: Shallow clone and fetch PR merge commit #45057

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Compare performance with trunk
if: github.event_name == 'pull_request'
run: ./bin/plugin/cli.js perf --ci $GITHUB_SHA trunk --tests-branch $GITHUB_SHA
run: ./bin/plugin/cli.js perf --merge-ref $GITHUB_REF --ci $GITHUB_SHA trunk --tests-branch $GITHUB_SHA

- name: Compare performance with current WordPress Core and previous Gutenberg versions
if: github.event_name == 'release'
Expand Down
4 changes: 4 additions & 0 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ program
'--tests-branch <branch>',
"Use this branch's performance test files"
)
.option(
'--merge-ref <branch>',
'Name of ref merging PR into base branch, e.g. refs/pull/44907/merge'
)
.option(
'--wp-version <version>',
'Specify a WordPress version on which to test all branches'
Expand Down
7 changes: 6 additions & 1 deletion bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const config = require( '../config' );
* @typedef WPPerformanceCommandOptions
*
* @property {boolean=} ci Run on CI.
* @property {string=} mergeRef Name of ref merging test branch into base branch, e.g. refs/pull/44907/merge.
* @property {string=} testsBranch The branch whose performance test files will be used for testing.
* @property {string=} wpVersion The WordPress version to be used as the base install for testing.
*/
Expand Down Expand Up @@ -212,7 +213,11 @@ async function runPerformanceTests( branches, options ) {
// 1- Preparing the tests directory.
log( '\n>> Preparing the tests directories' );
log( ' >> Cloning the repository' );
const baseDirectory = await git.clone( config.gitRepositoryURL );
const baseDirectory = await git.cloneAt(
config.gitRepositoryURL,
options.mergeRef,
options.testsBranch
);
const rootDirectory = getRandomTemporaryPath();
const performanceTestDirectory = rootDirectory + '/tests';
await runShellScript( 'mkdir -p ' + rootDirectory );
Expand Down
14 changes: 14 additions & 0 deletions bin/plugin/lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
const SimpleGit = require( 'simple-git' );
const fs = require( 'fs' );

/**
* Internal dependencies
Expand All @@ -26,6 +27,18 @@ async function clone( repositoryUrl ) {
return gitWorkingDirectoryPath;
}

async function cloneAt( repositoryUrl, ref, sha ) {
const gitWorkingDirectoryPath = getRandomTemporaryPath();
fs.mkdirSync( gitWorkingDirectoryPath, { recursive: true } );
console.log( `>>> Fetching ${ ref } (${ sha }) at ${ repositoryUrl }` );
await SimpleGit( gitWorkingDirectoryPath )
.raw( 'init' )
.raw( 'remote', 'add', 'origin', repositoryUrl )
.raw( 'fetch', '--depth=2', 'origin', ref )
.raw( 'checkout', sha );
return gitWorkingDirectoryPath;
}

/**
* Fetches changes from the repository.
*
Expand Down Expand Up @@ -187,6 +200,7 @@ async function replaceContentFromRemoteBranch(

module.exports = {
clone,
cloneAt,
commit,
checkoutRemoteBranch,
createLocalBranch,
Expand Down