Skip to content

Commit 55e87f8

Browse files
Copilotswissspidy
andauthored
Parallelize repository cloning during development environment setup
Agent-Logs-Url: https://github.com/wp-cli/wp-cli-dev/sessions/6509f703-3861-4c87-83a6-f0247ed1904b Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 7567837 commit 55e87f8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.maintenance/clone-all-repositories.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
$pwd = getcwd();
3737
$update_folders = [];
38+
$clone_list = [];
3839

3940
foreach ( $repositories as $repository ) {
4041
if ( in_array( $repository->name, $skip_list, true ) ) {
@@ -44,13 +45,17 @@
4445
$destination = isset( $clone_destination_map[ $repository->name ] ) ? $clone_destination_map[ $repository->name ] : $repository->name;
4546

4647
if ( ! is_dir( $destination ) ) {
47-
printf( "Fetching \033[32mwp-cli/{$repository->name}\033[0m...\n" );
48-
$clone_url = getenv( 'GITHUB_ACTION' ) ? $repository->clone_url : $repository->ssh_url;
49-
system( "git clone {$clone_url} {$destination}" );
48+
$clone_url = getenv( 'GITHUB_ACTION' ) ? $repository->clone_url : $repository->ssh_url;
49+
$clone_list[] = "{$destination} {$clone_url}";
5050
}
5151

5252
$update_folders[] = $destination;
5353
}
5454

55-
$updates = implode( '\n', $update_folders );
55+
if ( ! empty( $clone_list ) ) {
56+
$clones = implode( "\n", $clone_list );
57+
system( "echo '$clones' | xargs -n2 -P8 php .maintenance/clone-repository.php" );
58+
}
59+
60+
$updates = implode( "\n", $update_folders );
5661
system( "echo '$updates' | xargs -n1 -P8 -I% php .maintenance/refresh-repository.php %" );

.maintenance/clone-repository.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
if ( ! isset( $argv[1], $argv[2] ) ) {
4+
exit( "Usage: php clone-repository.php <destination> <clone_url>\n" );
5+
}
6+
7+
$destination = $argv[1];
8+
$clone_url = $argv[2];
9+
10+
printf( "Fetching \033[32m%s\033[0m...\n", $destination );
11+
system( 'git clone ' . escapeshellarg( $clone_url ) . ' ' . escapeshellarg( $destination ) );

0 commit comments

Comments
 (0)