-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathprep-release.php
More file actions
220 lines (193 loc) · 7.07 KB
/
prep-release.php
File metadata and controls
220 lines (193 loc) · 7.07 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
if (!defined('GLOB_BRACE')) {
echo "Error: GLOB_BRACE is not available on this system\n";
exit(1);
}
function verify_stability($stability) {
$stabilities = array(
"snapshot",
"devel",
"alpha",
"beta",
"stable",
);
if (!in_array($stability, $stabilities)) {
echo "Invalid stability: $stability\n";
echo "Must be one of: ", join(", ", $stabilities), "\n";
usage();
}
}
function verify_version($version, $stability) {
if (3 != sscanf($version, "%d.%d.%d", $major, $minor, $patch)) {
var_dump($major, $minor, $patch);
echo "Invalid version schema, expected 'major.minor.patch' (1.2.3), got $version\n";
usage();
}
if ($major < 0 && $stability == "stable") {
echo "Invalid stability for major version $major ($stability)\n";
echo "Major versions before 1.0.0 cannot be marked as stable\n";
usage();
}
}
function get_files() {
$dirs = array(
'src' => array(
"phongo.{c,h}",
"phongo_version.h",
"config.{m4,w32}",
"Makefile.frag",
"scripts/autotools/*.{m4}",
"scripts/autotools/*/*.{m4}",
"src/*.{c,h}",
"src/LIBMONGOCRYPT_VERSION_CURRENT",
"src/MongoDB/*.{c,h}",
"src/MongoDB/Exception/*.{c,h}",
"src/MongoDB/Monitoring/*.{c,h}",
"src/BSON/*.{c,h}",
"src/contrib/*.{c,h}",
"src/libmongoc/src/common/src/*.{c,h,h.in}",
// Note: src/libmongoc/src/common/src/mlib/ does not contain source files (as of libmongoc 2.0.1)
"src/libmongoc/src/common/src/mlib/*.h",
"src/libmongoc/src/kms-message/src/*.{c,h}",
"src/libmongoc/src/kms-message/src/kms_message/*.{c,h}",
"src/libmongoc/src/libbson/src/bson/*.{c,h,h.in}",
"src/libmongoc/src/libbson/src/jsonsl/*.{c,h}",
"src/libmongoc/src/libbson/VERSION*",
"src/libmongoc/src/libmongoc/src/mongoc/*.{c,def,defs,h,h.in}",
"src/libmongoc/src/zlib-1.*/*.{c,h,h.in}",
"src/libmongoc/src/utf8proc-2.*/*.{c,h}",
"src/libmongoc/src/uthash/uthash-2.*/*.h",
"src/libmongoc/VERSION*",
"src/libmongocrypt-compat/*.{c,h}",
"src/libmongocrypt-compat/mongocrypt/*.{c,h}",
"src/libmongocrypt/src/*.{c,h,h.in}",
"src/libmongocrypt/src/crypto/*.{c,h}",
// Note: src/libmongocrypt/src/mc-mlib/ does not contain source files (as of libmongocrypt 1.14.0)
"src/libmongocrypt/src/mc-mlib/*.h",
"src/libmongocrypt/src/os_posix/*.{c,h}",
"src/libmongocrypt/src/os_win/*.{c,h}",
"src/libmongocrypt/src/unicode/*.{c,h}",
"src/libmongocrypt/kms-message/src/*.{c,h}",
"src/libmongocrypt/kms-message/src/kms_message/*.{c,h}",
),
'test' => array(
"scripts/*/*.{sh}",
"scripts/*.{json,php,py,sh}",
"tests/utils/*.{inc,json.gz,php}",
"tests/**/*.{phpt}",
),
'doc' => array(
"README*",
"LICENSE",
"CREDITS",
"CONTRIBUTING*",
"THIRD_PARTY_NOTICES",
)
);
$files = array();
foreach($dirs as $role => $patterns) {
foreach ($patterns as $pattern) {
foreach (glob($pattern, GLOB_BRACE) ?: [] as $file) {
$files[$file] = $role;
}
}
}
// Exclude headers generated by configure (AC_CONFIG_FILES in config.m4).
// These are produced on the build machine and must not be shipped in the
// PECL package. Their .h.in templates are included above and configure
// regenerates the correct output in the build directory on the target machine.
unset($files['src/libmongoc/src/common/src/common-config.h']);
unset($files['src/libmongoc/src/libbson/src/bson/config.h']);
unset($files['src/libmongoc/src/libbson/src/bson/version.h']);
unset($files['src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h']);
unset($files['src/libmongoc/src/libmongoc/src/mongoc/mongoc-config-private.h']);
unset($files['src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h']);
unset($files['src/libmongoc/src/zlib-1.3.1/zconf.h']);
unset($files['src/libmongocrypt/src/mongocrypt-config.h']);
ksort($files);
return $files;
}
function format_open_dir($dir, $tab) {
return sprintf('%s<dir name="%s">', str_repeat(" ", $tab), $dir);
}
function format_close_dir($tab) {
return sprintf("%s</dir>", str_repeat(" ", $tab));
}
function format_file($filename, $tab, $role) {
return sprintf('%s<file role="%s" name="%s"/>', str_repeat(" ", $tab+1), $role, $filename);
}
function make_tree($files) {
$retval = array();
$lastdir = ".";
$tab = 2;
$retval[] = format_open_dir("/", $tab);
foreach($files as $file => $role) {
$dir = dirname($file);
$filename = basename($file);
if ($dir != $lastdir) {
$currdir = explode("/", $dir);
$prevdir = explode("/", $lastdir);
foreach($currdir as $n => $d) {
if (isset($prevdir[$n]) && $prevdir[$n] == $d) {
/* In case we are shorter then previous */
$n++;
continue;
}
break;
}
if ($lastdir != ".") {
foreach(array_reverse(array_slice($prevdir, $n)) as $close) {
$retval[] = format_close_dir($tab--);
}
}
foreach(array_slice($currdir, $n) as $open) {
$retval[] = format_open_dir($open, ++$tab);
}
}
$retval[] = format_file($filename, $tab, $role);
$lastdir = $dir;
}
foreach(array_reverse(explode("/", $lastdir)) as $close) {
$retval[] = format_close_dir($tab--);
}
$retval[] = format_close_dir($tab);
return $retval;
}
function usage() {
global $argv;
echo "Usage:\n\t";
echo $argv[0], " <version> <stability> [<release-notes-file>]\n";
exit(1);
}
if ($argc != 3 && $argc != 4) {
usage();
}
$VERSION = $argv[1];
$STABILITY = $argv[2];
$RELEASE_NOTES_FILE = $argv[3] ?? null;
/* 0.x.y. are developmental releases and cannot be stable */
if ((int)$VERSION < 1) {
$STABILITY = "devel";
}
/* A release candidate is a "beta" stability in terms of PECL */
if (stristr($VERSION, '-rc') !== false) {
$STABILITY = "beta";
}
verify_stability($STABILITY);
verify_version($VERSION, $STABILITY);
$currtime = new DateTime('now', new DateTimeZone('UTC'));
$DATE = $currtime->format('Y-m-d');
$TIME = $currtime->format('H:i:s');
$TREE = make_tree(get_files());
$contents = file_get_contents(__DIR__ . "/package.xml.in");
$REPLACE = array(
"%RELEASE_DATE%" => $DATE,
"%RELEASE_TIME%" => $TIME,
"%RELEASE_VERSION%" => $VERSION,
"%RELEASE_STABILITY%" => $STABILITY,
"%RELEASE_FILES%" => join("\n", $TREE),
"%RELEASE_NOTES%" => is_string($RELEASE_NOTES_FILE) && file_exists($RELEASE_NOTES_FILE) ? file_get_contents($RELEASE_NOTES_FILE) : '',
);
$contents = str_replace(array_keys($REPLACE), array_values($REPLACE), $contents);
file_put_contents(__DIR__ . "/../package.xml", $contents);
echo "Wrote package.xml\n";