forked from Automattic/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-on-wpcom
More file actions
executable file
·122 lines (87 loc) · 4.3 KB
/
test-on-wpcom
File metadata and controls
executable file
·122 lines (87 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/php
<?php
if ( isset( $argv[1] ) && $argv[1] == 'usage' ) {
echo 'Hi there! I\'m here to help you test out a Jetpack branch on WordPress.com. Using me is pretty easy, my syntax looks like: ' . PHP_EOL . PHP_EOL;
echo './tools/test-on-wpcom PATH_TO_WPCOM revert(optional)' . PHP_EOL . PHP_EOL;
echo 'PATH_TO_WPCOM should be the relative path to your local WordPress.com public_html from your Jetpack folder. For example, if you have a folder called "WordPress.com" in the same folder as your local Jetpack repo, you would use the command "./tools/test-on-wpcom ../WordPress.com/wpcom/public_html/"' . PHP_EOL . PHP_EOL;
echo 'When you\'re finished testing, run the same command, but add " revert" to the end and your WordPress.com files will be rolled back to how they used to be.';
die( PHP_EOL );
}
$path_to_wpcom = '../wpcom/wpcom/public_html/';
if ( isset( $argv[1] ) && $argv[1] != '.' ) {
$path_to_wpcom = $argv[1] . '/';
$path_to_wpcom = str_replace( '//', '/', $path_to_wpcom );
}
$back_out_to_wpcom = '';
$back_out_to_jetpack_root = '';
$jp_file_list_exists = file_exists( $back_out_to_wpcom . $path_to_wpcom . 'bin/jetpack/build-plugin-files.php' );
if ( !$jp_file_list_exists ) {
$back_out_to_wpcom = '../';
$back_out_to_jetpack_root = '../';
$jp_file_list_exists = file_exists( $back_out_to_wpcom . $path_to_wpcom . 'bin/jetpack/build-plugin-files.php' );
}
$path_to_wpcom = $back_out_to_wpcom . $path_to_wpcom;
if ( !$jp_file_list_exists ) {
die( 'Local WPCOM not found or incomplete.' . PHP_EOL . 'Need help? use "./tools/test-on-wpcom usage"' . PHP_EOL );
}
if ( file_exists( $back_out_to_jetpack_root . 'wpcom-test-backup/' ) && ( !isset( $argv[2] ) || !$argv[2] == 'revert' ) ) {
die( 'It looks like there\'s already a branch being tested. Revert first, then you can test this branch.' . PHP_EOL . 'Need help? use "./tools/test-on-wpcom usage"' . PHP_EOL );
}
if ( !file_exists( $back_out_to_jetpack_root . 'wpcom-test-backup/' ) && ( isset( $argv[2] ) && $argv[2] == 'revert' ) ) {
die( 'Nothing to revert.' . PHP_EOL . 'Need help? use "./tools/test-on-wpcom usage"' . PHP_EOL );
}
// Get all changed files
$diff = shell_exec( 'git diff master' );
$diff_array = explode( PHP_EOL, $diff );
if ( $diff_array ) {
foreach ( $diff_array as $da ) {
if ( strpos( $da, 'diff --git a' ) !== 0 ) {
continue;
}
$da = str_replace( 'diff --git a', '', $da );
$da = explode( ' ', $da );
$changed_files[ $da[0] ] = $da[0];
}
}
// Get list of files which sync with wpcom
include_once( $path_to_wpcom . 'bin/jetpack/build-plugin-files.php' );
if ( !$changed_files ) {
die( 'No changed WPCOM files in this branch.' . PHP_EOL );
}
$changes = array_intersect_key( $jetpack_files, $changed_files );
if ( isset( $argv[2] ) && $argv[2] == 'revert' ) {
echo 'Reverting WPCOM files...' . PHP_EOL . PHP_EOL;
foreach ( $changes as $jpf => $wpcf ) {
$jpf = preg_replace( '/\//', $back_out_to_jetpack_root, $jpf, 1 );
$wpcf = preg_replace( '/\//', '', $wpcf, 1 );
//revert the old file to wpcom
shell_exec( 'cp ' . $back_out_to_jetpack_root . 'wpcom-test-backup/' . $wpcf . ' ' . $path_to_wpcom . $wpcf );
echo $wpcf . ' Restored.' . PHP_EOL;
}
shell_exec( 'rm -Rf ' . $back_out_to_jetpack_root . 'wpcom-test-backup/' );
die( PHP_EOL . 'Revert completed' . PHP_EOL );
}
echo 'Preparing backup of WPCOM files...';
shell_exec( 'mkdir ' . $back_out_to_jetpack_root . 'wpcom-test-backup/' );
echo '...WPCOM files backed up!' . PHP_EOL . PHP_EOL;
// Move all files over
if ( $changes ) {
foreach ( $changes as $jpf => $wpcf ) {
$jpf = preg_replace( '/\//', $back_out_to_jetpack_root, $jpf, 1 );
$wpcf = preg_replace( '/\//', '', $wpcf, 1 );
$backup_folders = explode( '/', $wpcf );
array_pop( $backup_folders );
if ( $backup_folders ) {
foreach ( $backup_folders as $ct => $bf ) {
$ct++;
$dir_to_add = $back_out_to_jetpack_root . 'wpcom-test-backup/' . implode( '/', array_slice( $backup_folders, 0, $ct ) );
shell_exec( 'mkdir ' . $dir_to_add );
}
}
//back up the existing file from wpcom
shell_exec( 'cp ' . $path_to_wpcom . $wpcf . ' ' . $back_out_to_jetpack_root . 'wpcom-test-backup/' . $wpcf );
shell_exec( 'cp ' . $jpf . ' ' . $path_to_wpcom . $wpcf );
echo $jpf . ' ==> ' . $wpcf . PHP_EOL;
}
}
die ( PHP_EOL . 'Thank you for testing with Jetpack Airlines!' . PHP_EOL );