-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmcdeployall
executable file
·111 lines (87 loc) · 3.23 KB
/
mcdeployall
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
#!/usr/bin/env php
<?php
if (!defined('STDIN')) {
echo "You're unauthorized to view this page.\n";
exit(1);
}
if (!isset($argv[1])) {
echo "Usage: ./script/mcdeployall [version-number]\n";
exit(1);
}
$version = $argv[1];
if(!preg_match('/\d+\.\d+\.\d+(([a-z_-]+)\d+)?/i', $version)) {
echo "Improper version format.\n";
exit(1);
}
$membercore_plugin_dir = dirname(__DIR__);
$membercore_plugin_slug = basename($membercore_plugin_dir);
$plugins_dir = dirname($membercore_plugin_dir);
if (getcwd() !== $membercore_plugin_dir) {
echo "This script must be run from within the plugin root directory.\n";
exit(1);
}
if (strpos($membercore_plugin_slug, 'membercore') !== 0) {
echo "This script must be run from within a MemberCore plugin directory.\n";
exit(1);
}
$plugins = [
$membercore_plugin_slug,
str_replace('membercore', 'memberpress', $membercore_plugin_slug),
str_replace('membercore', 'wishlistmember', $membercore_plugin_slug),
];
$project_ids = [];
foreach($plugins as $plugin) {
$plugin_path = $plugins_dir . '/' . $plugin;
if (!file_exists($plugin_path)) {
echo "The $plugin plugin was not found.\n";
exit(1);
}
exec('git -C ' . escapeshellarg($plugin_path) . ' status --porcelain', $changes, $result);
if ($result !== 0) {
echo "Failed to execute git status for the $plugin plugin.\n";
exit(1);
} elseif (count($changes)) {
echo "The $plugin plugin has uncommitted changes.\n";
exit(1);
}
if (!is_dir($plugin_path . '/script')) {
echo "The $plugin plugin does not have a script directory.\n";
exit(1);
}
if (!file_exists($plugin_path . '/script/wp-script-config.php')) {
echo "The $plugin plugin does not have a script/wp-script-config.php file.\n";
exit(1);
}
$config = file_get_contents($plugin_path . '/script/wp-script-config.php');
if (!preg_match('/define\(\'WP_SCRIPT_TEXTDOMAIN\',\s*\'([^\']+)\'\)/', $config, $matches)) {
echo "The $plugin plugin does not have a WP_SCRIPT_TEXTDOMAIN defined.\n";
exit(1);
}
if (!preg_match('/define\(\'MOTHERSHIP_URL\',\s*\'([^\']+)\'\)/', $config, $matches)) {
echo "The $plugin plugin does not have a MOTHERSHIP_URL defined.\n";
exit(1);
}
if (!preg_match('/define\(\'MOTHERSHIP_API_KEY\',\s*\'([^\']+)\'\)/', $config, $matches)) {
echo "The $plugin plugin does not have a MOTHERSHIP_API_KEY defined.\n";
exit(1);
}
if (!preg_match('/define\(\'MOTHERSHIP_PROJECT_ID\',\s*\'([^\']+)\'\)/', $config, $matches)) {
echo "The $plugin plugin does not have a MOTHERSHIP_PROJECT_ID defined.\n";
exit(1);
} elseif (empty($matches[1]) || !is_numeric($matches[1])) {
echo "The $plugin plugin does not have a valid MOTHERSHIP_PROJECT_ID defined.\n";
exit(1);
}
if (in_array($matches[1], $project_ids, true)) {
echo "The $plugin plugin has a duplicate MOTHERSHIP_PROJECT_ID defined.\n";
exit(1);
}
$project_ids[] = $matches[1];
}
foreach ($plugins as $plugin) {
chdir($plugins_dir . '/' . $plugin);
$command = "./script/mcdevdeploy $version";
echo "\n$command\n";
system($command);
}
exit(0);