-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.pl
484 lines (424 loc) · 12.5 KB
/
release.pl
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#!/usr/bin/perl
# Copyright (c) 2023 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Assumes all repositories master/main locally are upto date including C build
# This script can be safely be repeated until the $release pushed to pypi or tagged
my $release = "7.3.1"; # Without the leading 1!
my $release_name = "To Do";
#my $branch = $release;
my $branch = "version_bump";
use strict;
use warnings;
use Cwd qw(getcwd);
use feature qw(say);
use File::Basename;
use File::Find qw(find);
use File::Path;
use Git;
use LWP::Simple;
use POSIX qw(strftime);
my $changed;
my $in;
my $line;
my $new_path;
my $path;
my $permissions;
my $out;
my $repo;
my $start_path ;
sub git_test_pypi{
# Switch to the main and master branch and make sure is it uptodate
$repo = Git->repository();
$repo->command('checkout', 'test.pypi-last-pre');
}
sub git_main{
# Switch to the main and master branch and make sure is it uptodate
$repo = Git->repository();
$repo->command('fetch', 'origin');
my $info = $repo->command('branch');
if (index($info, 'main') != -1){
$repo->command('checkout', 'main');
$repo->command('merge', 'origin/main', 'main');
} else {
$repo->command('checkout', 'master');
$repo->command('merge', 'origin/master', 'master');
}
}
sub git_setup_branch{
# clears previous versions of the branch and creates a new one.
# the eval is because check if release essist may have a flase possitive
# Especially if doing a full release while an alpha is still in Jenkins
$repo->command('fetch');
# remove previously branches
my $info = $repo->command('branch');
if (index($info, $branch) != -1){
say "removing previous branch $branch";
eval {
$repo->command('branch', '-D', $branch);
} or do {
my $e = $@;
say "Something went wrong: $e#";
};
}
$info = $repo->command('ls-remote', '--heads', 'origin');
if (index($info, $branch) != -1){
say "removing previous remote branch";
eval {
$repo->command('push', "origin", "--delete", $branch);
} or do {
my $e = $@;
say "Something went wrong: $e#";
};
}
# Move to release branch
$repo->command('branch', $branch);
$repo->command('checkout', $branch);
}
sub git_push_branch{
# Pushes the release as a branch
$repo->command('push', 'origin', $branch);
git_main();
$repo->command('branch', '-D', $branch);
}
sub start_copy{
# starts the copy by creating a new bak file
# Opens the original or reading and the bak for writing
open $in, '<', $path or die "Can't read old file: $path";
$permissions = (stat $path)[2] & 00777;
$new_path = "${path}.bak";
open $out, '>', $new_path or die "Can't write new file: $new_path";
$changed = 0 # Perl has no bool type so use 0 as false
}
sub finish_copy{
# closes the file streams
# If needed replaces the original with the new file and does a git commit
# removes the new (.bak) file
close $in;
close $out;
if ($changed){
say "Updated: ",$path;
unlink $path;
rename $new_path, $path;
chmod $permissions, $path;
$repo->command('commit', $path, '-m', "info for release ${release}");
} else {
unlink $new_path;
}
}
sub handle_setup_cfg {
# looks for any line withe the spinnaker version pattern
# and updates to current version
$path = File::Spec->catfile(getcwd(), "setup.cfg");
if (not -e $path) {
say "no ", $path;
return;
}
start_copy();
while( <$in> ) {
$line = $_;
$line =~ s/( == 1!\d.\d.\d.*)/ == 1!${release}/;
print $out $line;
$changed = $changed || $line ne $_;
}
finish_copy();
}
sub handle_version{
# updates version num and dates in _version.pl file
#$path set by caller
start_copy();
$line = <$in>;
if (!defined $line){
print("No __version line found\n");
die $path;
}
while ($line !~ /\_\_version/i){
print $out $line;
$line = <$in>;
if (!defined $line){
print("No __version line found\n");
die $path;
}
}
if (index($line, $release) == -1){
$changed = 1;
while ($line !~ /\_\_version\_name\_\_/i){
$line = <$in>;
if (!defined $line){
print("No __version_name__ line found\n");
die $path;
}
}
print $out "__version__ = \"1!${release}\"\n";
if ($release eq $branch){
my $month = strftime "%B", localtime;
print $out "__version_month__ = \"${month}\"\n";
my $year = strftime "%Y", localtime;
print $out "__version_year__ = \"${year}\"\n";
my $day = strftime "%d", localtime;
print $out "__version_day__ = \"${day}\"\n";
} else {
print $out "__version_month__ = \"TBD\"\n";
print $out "__version_year__ = \"TBD\"\n";
print $out "__version_day__ = \"TBD\"\n";
}
print $out "__version_name__ = \"${release_name}\"\n";
while( <$in> ) {
print $out $_;
}
}
finish_copy();
}
sub handle_readme {
# Updates the README.md file
# change readthedocs.io link to version specific
if ($release ne $branch){
return;
}
$path = File::Spec->catfile(getcwd(), "README.md");
if (not -e $path) {
say "no ", $path;
return;
}
start_copy();
while( <$in> ) {
$line = $_;
if ($release eq $branch) {
if ($line =~ /^\[\!\[/) {
$line = ""
}
}
$line =~ s/readthedocs\.io.*\)$/readthedocs\.io\/en\/${release}\)/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub handle_jenkins {
if ($release ne $branch){
return;
}
# update Jenkins file to use a specific version
$path = File::Spec->catfile(getcwd(), "Jenkinsfile");
start_copy();
my $release2 = $release;
$release2 =~ s/-//;
while( <$in> ) {
$line = $_;
$line =~ s/ --pre/==1!${release2}/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
say $release;
}
sub handle_conf_py {
# update doc/source/conf.py file
# Updates various lines with version
if ($release ne $branch){
return;
}
$path = File::Spec->catfile(getcwd(), "doc", "source", "conf.py");
if (not -e $path) {
return;
}
start_copy();
# assume only a single digit sub release
my $version = substr($release, 0, 3);
while( <$in> ) {
$line = $_;
my $old_line = $line;
$line =~ s/(\d{4})\-(\d{4})/$1\-2023/i;
$line =~ s/version = \'\d.\d.*$/version = \'1!${version}\'/;
$line =~ s/release = \'\d.\d.*$/release = \'1!${release}\'/;
$line =~ s/spinnaker_doc_version = "latest"/spinnaker_doc_version = "${release}"/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub handle_doc_requirements_txt {
# updates doc/doc_requirements.txt
# use the version specific branches for dependecies dependencies
if ($release ne $branch){
return;
}
$path = File::Spec->catfile(getcwd(), "doc", "doc_requirements.txt");
if (not -e $path) {
return;
}
start_copy();
while( <$in> ) {
$line = $_;
my $old_line = $line;
$line =~ s/\@master#/\@${release}#/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub handle_index_rst {
# Updates the index.rst by changing readthedoc links to version specific
if ($release ne $branch){
return;
}
# $path set by caller
start_copy();
while( <$in> ) {
$line = $_;
print $line;
$line =~ s/readthedocs\.io(.*)$/readthedocs\.io\/en\/${release}/;
print $line;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub handle_pom {
# Updates Java pom.xml changes <version> to current release
# $path set by caller
say $path ;
start_copy();
while( <$in> ) {
$line = $_;
$line =~ s/(version>)(.*)(-SNAPSHOT)/$1$release/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub handle_doxyfile {
# Updates Doxyfile changing PROJECT_NUMBER to version
# $path set by caller
say $path ;
if (index($path, "spinnaker_tools") != -1){
return;
}
start_copy();
while( <$in> ) {
$line = $_;
$line =~ s/(PROJECT_NUMBER\s*\=\s*)(\w.*)$/$1$release/;
$changed = $changed || $line ne $_;
print $out $line;
}
finish_copy();
}
sub do_build{
# clears any previous python build and does a new one
if ($release ne $branch){
return;
}
$path = File::Spec->catfile(getcwd(), "setup.py");
if (not -e $path) {
return;
}
rmtree("dist");
system("python3 -m build >nul");
}
sub find_and_handle_special{
$path = $File::Find::name;
if (basename($path) eq "_version.py"){
handle_version();
} elsif (basename($path) eq "index.rst"){
handle_index_rst();
} elsif (basename($path) eq "pom.xml"){
handle_pom();
} elsif (basename($path) eq "Doxyfile"){
handle_doxyfile();
}
# pom.xml
# Doxyfile but not tools
}
sub update_directory{
# Moves into directory, updates version, builds and commits
$start_path = getcwd();
chdir $_[0];
say "updating", getcwd();
# switch to main or master branch
git_main();
git_setup_branch();
handle_setup_cfg();
find(\&find_and_handle_special, getcwd());
handle_conf_py();
handle_doc_requirements_txt();
handle_readme();
do_build();
git_push_branch();
chdir $start_path;
}
sub update_integration_tests{
# creates a test branch based on branch setup for test pypi
$start_path = getcwd();
chdir $_[0];
say "updating", getcwd();
if ($release eq $branch) {
git_test_pypi();
} else {
git_main();
}
git_setup_branch();
handle_jenkins();
# Do not push, or delete the branch
chdir $start_path;
}
sub wait_doc_built{
if ($release ne $branch){
return;
}
# Blocks the script to make sure the readthedocs build finished
my $url = "https://${_[0]}.readthedocs.io/en/${release}/";
say $url;
my $browser = LWP::UserAgent->new;
my $timeout = 30;
my $response = $browser->get( $url );
while (index($response->status_line, "200") == -1) {
my $status = $response->status_line;
say "$url gave $status waiting ${timeout}s";
sleep($timeout);
$response = $browser->get( $url );
}
}
update_directory("../spinnaker_tools");
update_directory("../spinn_common");
update_directory("../SpiNNUtils");
wait_doc_built('spinnutils');
update_directory("../SpiNNMachine");
wait_doc_built('spinnmachine');
update_directory("../SpiNNMan");
wait_doc_built('spinnman');
update_directory("../spalloc");
update_directory("../PACMAN");
wait_doc_built('spalloc');
wait_doc_built('pacman');
update_directory("../SpiNNFrontEndCommon");
update_directory("../TestBase");
wait_doc_built('spinnfrontendcommon');
update_directory("../sPyNNaker");
update_directory("../SpiNNakerGraphFrontEnd");
update_directory("../PyNNExamples");
update_directory("../sPyNNakerNewModelTemplate");
update_directory("../sPyNNakerVisualisers");
update_directory("../Visualiser");
update_directory("../JavaSpiNNaker");
update_directory("../SpiNNGym");
update_directory("../SpiNNaker_PDP2");
update_directory("../microcircuit_model");
update_directory("../MarkovChainMonteCarlo");
update_directory("../sPyNNakerJupyter");
update_directory("../TSPonSpiNNaker");
update_directory("../BitBrainDemo");
wait_doc_built('spynnaker');
wait_doc_built('spinnakergraphfrontend');
update_directory("../sphinx8");
update_integration_tests("../IntegrationTests");
# die "stop";