-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.py
executable file
·1047 lines (950 loc) · 41.3 KB
/
release.py
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# This file is part of release-tool.
# Copyright (C) 2016-2021 Sequent Tech Inc <[email protected]>
# release-tool is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License.
# release-tool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with release-tool. If not, see <http://www.gnu.org/licenses/>.
import argparse
import yaml
import requests
import tempfile
from datetime import datetime
import subprocess
import os
import re
from jinja2 import Environment, FileSystemLoader, select_autoescape
from github import Github
from collections import defaultdict
from release_notes import (
get_sem_release,
get_release_head,
get_release_notes,
create_release_notes_md,
)
def read_text_file(file_path):
textfile = open(file_path, "r")
text = textfile.read()
textfile.close()
return text
def write_text_file(file_path, text):
textfile = open(file_path, "w")
textfile.write(text)
textfile.close()
def get_project_type(dir_path):
config_file = read_text_file(os.path.join(dir_path, ".git/config"))
my_match = re.search('url\s*=\s*git@(github|gitlab).com:(sequentech)/(?P<proj_name>.+?)(\.git)?\\n', config_file)
try:
my_match.group('proj_name')
except:
my_match = re.search('url\s*=\s*https://(github|gitlab).com/(sequentech)/(?P<proj_name>.+?)(\.git)?\\n', config_file)
return my_match.group('proj_name')
def do_gui_common(dir_path, version):
invalid_version = re.match(r"^[a-zA-Z]+", version) is not None
print("SequentConfig.js...")
SequentConfig = read_text_file(os.path.join(dir_path, "SequentConfig.js"))
SequentConfig = re.sub(
"var\s+SEQUENT_CONFIG_VERSION\s*=\s*'[^']+';",
"var SEQUENT_CONFIG_VERSION = '" + version + "';",
SequentConfig
)
SequentConfig = re.sub(
"mainVersion\s*[^,]+,\n",
"mainVersion: '" + version + "',\n",
SequentConfig
)
write_text_file(os.path.join(dir_path, "SequentConfig.js"), SequentConfig)
print("package.json...")
if not invalid_version:
package = read_text_file(os.path.join(dir_path, "package.json"))
package = re.sub('"version"\s*:\s*"[^"]+"', '"version" : "'+ version + '"', package)
write_text_file(os.path.join(dir_path, "package.json"), package)
else:
print("leaving package.json as is because of invalid version name")
print("Gruntfile.js...")
Gruntfile = read_text_file(os.path.join(dir_path, "Gruntfile.js"))
Gruntfile = re.sub("var\s+SEQUENT_CONFIG_VERSION\s*=\s*'[^']+';", "var SEQUENT_CONFIG_VERSION = '" + version + "';", Gruntfile)
Gruntfile = re.sub("appCommon-v[0-9a-zA-Z.\-+]+\.js", "appCommon-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("libCommon-v[0-9a-zA-Z.\-+]+\.js", "libCommon-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("libnocompat-v[0-9a-zA-Z.\-+]+\.js", "libnocompat-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("libcompat-v[0-9a-zA-Z.\-+]+\.js", "libcompat-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("SequentConfig-v[0-9a-zA-Z.\-+]+\.js", "SequentConfig-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("SequentThemes-v[0-9a-zA-Z.\-+]+\.js", "SequentThemes-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("SequentPlugins-v[0-9a-zA-Z.\-+]+\.js", "SequentPlugins-v" + version + ".js", Gruntfile)
write_text_file(os.path.join(dir_path, "Gruntfile.js"), Gruntfile)
print("running grunt build..")
call_process("grunt build", shell=True, cwd=dir_path)
def do_gui_other(dir_path, version):
print("index.html...")
index = read_text_file(os.path.join(dir_path, "index.html"))
index = re.sub("libnocompat-v.*\.js", "libnocompat-v" + version + ".js", index)
index = re.sub("libcompat-v.*\.js", "libcompat-v" + version + ".js", index)
index = re.sub("SequentTheme-v.*\.js", "SequentTheme-v" + version + ".js", index)
index = re.sub("appCommon-v.*\.js", "appCommon-v" + version + ".js", index)
index = re.sub("libCommon-v.*\.js", "libCommon-v" + version + ".js", index)
write_text_file(os.path.join(dir_path, "index.html"), index)
print("SequentConfig.js...")
SequentConfig = read_text_file(os.path.join(dir_path, "SequentConfig.js"))
SequentConfig = re.sub(
"var\s+SEQUENT_CONFIG_VERSION\s*=\s*'[^']+';",
"var SEQUENT_CONFIG_VERSION = '" + version + "';",
SequentConfig
)
SequentConfig = re.sub(
"mainVersion\s*[^,]+,\n",
"mainVersion: '" + version + "',\n",
SequentConfig
)
write_text_file(os.path.join(dir_path, "SequentConfig.js"), SequentConfig)
av_plugins_config_path = os.path.join(dir_path, "SequentPluginsConfig.js")
if os.path.isfile(av_plugins_config_path):
print("SequentPluginsConfig.js...")
SequentPluginsConfig = read_text_file(av_plugins_config_path)
SequentPluginsConfig = re.sub("var\s+SEQUENT_PLUGINS_CONFIG_VERSION\s*=\s*'[^']+';", "var SEQUENT_PLUGINS_CONFIG_VERSION = '" + version + "';", SequentPluginsConfig)
write_text_file(av_plugins_config_path, SequentPluginsConfig)
print("Gruntfile.js...")
Gruntfile = read_text_file(os.path.join(dir_path, "Gruntfile.js"))
Gruntfile = re.sub("var\s+SEQUENT_CONFIG_VERSION\s*=\s*'[^']+';", "var SEQUENT_CONFIG_VERSION = '" + version + "';", Gruntfile)
Gruntfile = re.sub("appCommon-v[0-9a-zA-Z.\-+]+\.js", "appCommon-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("libCommon-v[0-9a-zA-Z.\-+]+\.js", "libCommon-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("libnocompat-v[0-9a-zA-Z.\-+]+\.min\.js", "libnocompat-v" + version + ".min.js", Gruntfile)
Gruntfile = re.sub("libcompat-v[0-9a-zA-Z.\-+]+\.min\.js", "libcompat-v" + version + ".min.js", Gruntfile)
Gruntfile = re.sub("SequentConfig-v[0-9a-zA-Z.\-+]+\.js", "SequentConfig-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("SequentThemes-v[0-9a-zA-Z.\-+]+\.js", "SequentThemes-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("SequentPlugins-v[0-9a-zA-Z.\-+]+\.js", "SequentPlugins-v" + version + ".js", Gruntfile)
Gruntfile = re.sub("app-v[0-9a-zA-Z.\-+]+\.min\.js", "app-v" + version + ".min.js", Gruntfile)
Gruntfile = re.sub("lib-v[0-9a-zA-Z.\-+]+\.min\.js", "lib-v" + version + ".min.js", Gruntfile)
write_text_file(os.path.join(dir_path, "Gruntfile.js"), Gruntfile)
print("package.json...")
package = read_text_file(os.path.join(dir_path, "package.json"))
package = re.sub('"version"\s*:\s*"[^"]+"', '"version" : "'+ version + '"', package)
package = re.sub(
'"common-ui": "https://github.com/sequentech/common-ui\.git.*\"',
f'"common-ui": "https://github.com/sequentech/common-ui.git#{version}\"',
package
)
write_text_file(os.path.join(dir_path, "package.json"), package)
def do_ballot_box(dir_path, version):
print("build.sbt...")
build = read_text_file(os.path.join(dir_path, "build.sbt"))
build = re.sub('version\s*:=\s*"[^"]+"', 'version := "'+ version + '"', build)
write_text_file(os.path.join(dir_path, "build.sbt"), build)
def do_election_verifier(dir_path, version):
print("build.sbt...")
build = read_text_file(os.path.join(dir_path, "build.sbt"))
build = re.sub('version\s*:=\s*"[^"]+"', 'version := "'+ version + '"', build)
m = re.search('scalaVersion := "(?P<scalaVersion>[0-9]+\.[0-9]+)\.[0-9]"', build)
scalaVersion = m.group('scalaVersion')
print("scalaVersion is " + scalaVersion)
write_text_file(os.path.join(dir_path, "build.sbt"), build)
print("package.sh...")
package = read_text_file(os.path.join(dir_path, "package.sh"))
package = re.sub(
'cp target/scala-.*/proguard/election-verifier_.*\.jar dist',
'cp target/scala-' + scalaVersion + '/proguard/election-verifier_' + scalaVersion + '-' + version + '.jar dist',
package
)
write_text_file(os.path.join(dir_path, "package.sh"), package)
print('pverify.sh..')
pverify = read_text_file(os.path.join(dir_path, "pverify.sh"))
pverify = re.sub(
'java -Djava\.security\.egd=file:/dev/\./urandom -classpath election-verifier_.*\.jar org\.sequent\.sequent\.Verifier \$1 \$2',
'java -Djava.security.egd=file:/dev/./urandom -classpath election-verifier_' + scalaVersion + '-' + version + '.jar org.sequent.sequent.Verifier $1 $2',
pverify
)
write_text_file(os.path.join(dir_path, "pverify.sh"), pverify)
print('vmnc.sh..')
vmnc = read_text_file(os.path.join(dir_path, "vmnc.sh"))
vmnc = re.sub(
'java -Djava.security\.egd=file:/dev/\./urandom -classpath \$DIR/election-verifier_.*\.jar org\.sequent\.sequent\.Vmnc "\$@"',
'java -Djava.security.egd=file:/dev/./urandom -classpath $DIR/election-verifier_' + scalaVersion + '-' + version + '.jar org.sequent.sequent.Vmnc "$@"',
vmnc
)
write_text_file(os.path.join(dir_path, "vmnc.sh"), vmnc)
print('README.md..')
readme = read_text_file(os.path.join(dir_path, "README.md"))
readme = re.sub(
'using version `[^`]+`',
'using version `' + version + '`',
readme
)
readme = re.sub(
'export INTERNAL_GIT_VERSION=.*',
'export INTERNAL_GIT_VERSION="' + version + '"',
readme
)
write_text_file(os.path.join(dir_path, "README.md"), readme)
print("project.spdx.yml..")
spdx = read_text_file(os.path.join(dir_path, "project.spdx.yml"))
spdx = re.sub(
"name:\s*\"election-verifier-[^\"]+\"\s*",
"name: \"election-verifier-" + version +"\"\n",
spdx
)
spdx = re.sub(
" name:\s*\"election-verifier\"\s*\n versionInfo:\s*\"[^\"]+\"",
f" name: \"election-verifier\"\n versionInfo: \"{version}\"",
spdx,
flags=re.MULTILINE
)
spdx = re.sub(
'downloadLocation: "git\+https://github.com/sequentech/election-verifier\.git@.*\"',
f'downloadLocation: "git+https://github.com/sequentech/election-verifier.git@{version}\"',
spdx
)
write_text_file(os.path.join(dir_path, "project.spdx.yml"), spdx)
print(".github/workflows/unittests.yml...")
unittests_yml_path = os.path.join(
dir_path, ".github", "workflows", "unittests.yml"
)
unittests_yml = read_text_file(unittests_yml_path)
unittests_yml = re.sub(
'export INTERNAL_GIT_VERSION=.*',
f'export INTERNAL_GIT_VERSION="{version}"',
unittests_yml
)
write_text_file(unittests_yml_path, unittests_yml)
print("config.json in unit tests tarfdiles")
testdata_path = os.path.join(dir_path, "testdata")
tar_files = [
filename
for filename in os.listdir(testdata_path)
if (
os.path.isfile(os.path.join(testdata_path, filename)) and
filename.endswith(".tar")
)
]
# untar the tarfiles, edit them and recreate them
for tarfile_name in tar_files:
tarfile_path = os.path.join(testdata_path, tarfile_name)
with tempfile.TemporaryDirectory() as temp_dir:
call_process(
f"tar xf {tarfile_path} -C {temp_dir}",
shell=True,
cwd=dir_path
)
config_json_path = os.path.join(temp_dir, "config.json")
config_json = read_text_file(config_json_path)
config_json = re.sub(
"{\"version\"\s*:\s*\"[^\"]+\"\s*,",
"{\"version\": \"" + version +"\",",
config_json
)
write_text_file(config_json_path, config_json)
call_process(
f"tar cf {tarfile_path} -C {temp_dir} .",
shell=True,
cwd=dir_path
)
def do_frestq(dir_path, version):
invalid_version = re.match(r"^[a-zA-Z]+", version) is not None
print("setup.py...")
if not invalid_version:
repos = read_text_file(os.path.join(dir_path, "setup.py"))
repos = re.sub("version\s*=\s*'[^']+'\s*,", "version='" + version +"',", repos)
write_text_file(os.path.join(dir_path, "setup.py"), repos)
else:
print("leaving setup.py as is because of invalid version name")
def do_election_orchestra(dir_path, version):
print("requirements.txt...")
requirements = read_text_file(os.path.join(dir_path, "requirements.txt"))
requirements = re.sub(
'git\+https://github.com/sequentech/frestq\.git@.*',
'git+https://github.com/sequentech/frestq.git@'+ version,
requirements
)
write_text_file(os.path.join(dir_path, "requirements.txt"), requirements)
setup_py = read_text_file(os.path.join(dir_path, "setup.py"))
setup_py = re.sub(
"version\s*=\s*'[^']+'\s*,",
"version='" + version +"',",
setup_py
)
setup_py = re.sub(
'git\+https://github.com/sequentech/frestq\.git@[^\'"]+',
'git+https://github.com/sequentech/frestq.git@'+ version,
setup_py
)
write_text_file(os.path.join(dir_path, "setup.py"), setup_py)
def do_deployment_tool(dir_path, version):
print("repos.yml...")
repos = read_text_file(os.path.join(dir_path, "repos.yml"))
repos = re.sub('version:\s*.*\n', 'version: \''+ version + '\'\n', repos)
write_text_file(os.path.join(dir_path, "repos.yml"), repos)
print("config.yml...")
repos = read_text_file(os.path.join(dir_path, "config.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub(
'"version":\s*"[^"]+",\n',
'"version": "'+ version + '",\n',
repos
)
repos = re.sub(
'mainVersion:\s*\'[^\']+\'\n',
f'mainVersion: \'{version}\'\n',
repos
)
write_text_file(os.path.join(dir_path, "config.yml"), repos)
print("doc/devel/sequent.config.yml...")
repos = read_text_file(os.path.join(dir_path, "doc/devel/sequent.config.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "doc/devel/sequent.config.yml"), repos)
print("doc/devel/auth1.config.yml...")
repos = read_text_file(os.path.join(dir_path, "doc/devel/auth1.config.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "doc/devel/auth1.config.yml"), repos)
print("doc/devel/auth2.config.yml...")
repos = read_text_file(os.path.join(dir_path, "doc/devel/auth2.config.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "doc/devel/auth2.config.yml"), repos)
print("doc/production/config.auth.yml...")
repos = read_text_file(os.path.join(dir_path, "doc/production/config.auth.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "doc/production/config.auth.yml"), repos)
print("doc/production/config.master.yml...")
repos = read_text_file(os.path.join(dir_path, "doc/production/config.master.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "doc/production/config.master.yml"), repos)
print("helper-tools/config_prod_env.py...")
helper_script = read_text_file(os.path.join(dir_path, "helper-tools/config_prod_env.py"))
rx = re.compile("\s*OUTPUT_PROD_VERSION\s*=\s*['|\"]?([0-9a-zA-Z.\-+]*)['|\"]?\s*\n", re.MULTILINE)
search = rx.search(helper_script)
old_version = search.group(1)
helper_script = re.sub("INPUT_PROD_VERSION\s*=\s*['|\"]?[0-9a-zA-Z.\-+]*['|\"]?\s*\n", "INPUT_PROD_VERSION=\""+ old_version + "\"\n", helper_script)
helper_script = re.sub("INPUT_PRE_VERSION\s*=\s*['|\"]?[0-9a-zA-Z.\-+]*['|\"]?\s*\n", "INPUT_PRE_VERSION=\""+ version + "\"\n", helper_script)
helper_script = re.sub("OUTPUT_PROD_VERSION\s*=\s*['|\"]?[0-9a-zA-Z.\-+]*['|\"]?\s*\n", "OUTPUT_PROD_VERSION=\""+ version + "\"\n", helper_script)
write_text_file(os.path.join(dir_path, "helper-tools/config_prod_env.py"), helper_script)
print("sequent-ui/templates/SequentConfig.js...")
Gruntfile = read_text_file(os.path.join(dir_path, "sequent-ui/templates/SequentConfig.js"))
Gruntfile = re.sub("var\s+SEQUENT_CONFIG_VERSION\s*=\s*'[^']+';", "var SEQUENT_CONFIG_VERSION = '" + version + "';", Gruntfile)
write_text_file(os.path.join(dir_path, "sequent-ui/templates/SequentConfig.js"), Gruntfile)
def do_tally_methods(dir_path, version):
invalid_version = re.match(r"^[a-zA-Z]+", version) is not None
print("setup.py...")
if not invalid_version:
repos = read_text_file(os.path.join(dir_path, "setup.py"))
repos = re.sub("version\s*=\s*'[^']+'\s*,", "version='" + version +"',", repos)
write_text_file(os.path.join(dir_path, "setup.py"), repos)
else:
print("leaving setup.py as is because of invalid version name")
def do_tally_pipes(dir_path, version):
print("setup.py...")
repos = read_text_file(os.path.join(dir_path, "setup.py"))
repos = re.sub("version\s*=\s*'[^']+'\s*,", "version='" + version +"',", repos)
repos = re.sub('git\+https://github.com/sequentech/tally-methods\.git@.*', 'git+https://github.com/sequentech/tally-methods.git@'+ version + '\'', repos)
write_text_file(os.path.join(dir_path, "setup.py"), repos)
print("requirements.txt...")
requirements = read_text_file(os.path.join(dir_path, "requirements.txt"))
requirements = re.sub('git\+https://github.com/sequentech/tally-methods\.git@.*', 'git+https://github.com/sequentech/tally-methods.git@'+ version + "#egg=tally-methods", requirements)
write_text_file(os.path.join(dir_path, "requirements.txt"), requirements)
print("tally_pipes/main.py...")
main_path = os.path.join(dir_path, "tally_pipes/main.py")
if os.path.isfile(main_path):
main_file = read_text_file(main_path)
main_file = re.sub("VERSION\s*=\s*\"[^\"]+\"", "VERSION = \"" + version + "\"", main_file)
write_text_file(main_path, main_file)
def do_sequent_payment_api(dir_path, version):
print("setup.py...")
repos = read_text_file(os.path.join(dir_path, "setup.py"))
repos = re.sub("version\s*=\s*'[^']+'\s*,", "version='" + version +"',", repos)
write_text_file(os.path.join(dir_path, "setup.py"), repos)
def do_iam(dir_path, version):
pass
def do_misc_tools(dir_path, version):
print("setup.py...")
repos = read_text_file(os.path.join(dir_path, "setup.py"))
repos = re.sub("version\s*=\s*'[^']+'\s*,", "version='" + version +"',", repos)
write_text_file(os.path.join(dir_path, "setup.py"), repos)
def do_mixnet(dir_path, version):
print("project.spdx.yml..")
spdx = read_text_file(os.path.join(dir_path, "project.spdx.yml"))
str_datetime = datetime.now().isoformat(timespec="seconds")
spdx = re.sub(
"created:\s*\"[^\"]+\"\s*\n",
"created: \"" + str_datetime + "Z\"\n",
spdx
)
spdx = re.sub(
"^name:\s*\"mixnet-[^\"]+\"\s*",
"name: \"mixnet-" + version + "\"\n",
spdx
)
spdx = re.sub(
" name:\s*\"mixnet\"\s*\n versionInfo:\s*\"[^\"]+\"",
f" name: \"mixnet\"\n versionInfo: \"{version}\"",
spdx,
flags=re.MULTILINE
)
spdx = re.sub(
'downloadLocation: "git\+https://github.com/sequentech/mixnet\.git@.*\"',
f'downloadLocation: "git+https://github.com/sequentech/mixnet.git@{version}\"',
spdx
)
write_text_file(os.path.join(dir_path, "project.spdx.yml"), spdx)
def do_ballot_verifier(dir_path, version):
print("README.md...")
print("project.spdx.yml..")
spdx = read_text_file(os.path.join(dir_path, "project.spdx.yml"))
str_datetime = datetime.now().isoformat(timespec="seconds")
spdx = re.sub(
"created:\s*\"[^\"]+\"\s*\n",
"created: \"" + str_datetime + "Z\"\n",
spdx
)
spdx = re.sub(
"^name:\s*\"ballot-verifier-[^\"]+\"\s*",
"name: \"ballot-verifier-" + version + "\"\n",
spdx
)
spdx = re.sub(
" name:\s*\"ballot-verifier\"\s*\n versionInfo:\s*\"[^\"]+\"",
f" name: \"ballot-verifier\"\n versionInfo: \"{version}\"",
spdx,
flags=re.MULTILINE
)
spdx = re.sub(
'downloadLocation: "git\+https://github.com/sequentech/ballot-verifier\.git@.*\"',
f'downloadLocation: "git+https://github.com/sequentech/ballot-verifier.git@{version}\"',
spdx
)
write_text_file(os.path.join(dir_path, "project.spdx.yml"), spdx)
readme = read_text_file(os.path.join(dir_path, "README.md"))
readme = re.sub(
'https://github\.com/sequentech/ballot-verifier/releases/download/[^/]+/',
f'https://github.com/sequentech/ballot-verifier/releases/download/{version}/',
readme)
write_text_file(os.path.join(dir_path, "README.md"), readme)
def do_documentation(dir_path, version):
print("package.json...")
package = read_text_file(os.path.join(dir_path, "package.json"))
package = re.sub('"version"\s*:\s*"[^"]+"', '"version" : "'+ version + '"', package)
write_text_file(os.path.join(dir_path, "package.json"), package)
print("docs/general/guides/deployment/assets/config.auth.yml...")
repos = read_text_file(os.path.join(dir_path, "docs/general/guides/deployment/assets/config.auth.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub(
'mainVersion:\s*\'[^\']+\'\n',
f'mainVersion: \'{version}\'\n',
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "docs/general/guides/deployment/assets/config.auth.yml"), repos)
print("docs/general/guides/deployment/assets/config.master.yml...")
repos = read_text_file(os.path.join(dir_path, "docs/general/guides/deployment/assets/config.master.yml"))
repos = re.sub('version:\s*.*[^,]\n', 'version: \''+ version + '\'\n', repos)
repos = re.sub(
"tallyPipesConfig: {\n(\s*)version:\s*\'[^\']+\',?\n",
f"tallyPipesConfig: {{\n\\1version: \'{version}\',\n",
repos
)
repos = re.sub(
'mainVersion:\s*\'[^\']+\'\n',
f'mainVersion: \'{version}\'\n',
repos
)
repos = re.sub('"version":\s*"[^"]+",\n', '"version": "'+ version + '",\n', repos)
write_text_file(os.path.join(dir_path, "docs/general/guides/deployment/assets/config.master.yml"), repos)
def do_release_tool(dir_path, version):
pass
def apply_base_branch(dir_path, base_branches):
print("applying base_branch..")
call_process(f"git stash", shell=True, cwd=dir_path)
call_process(f"git fetch origin", shell=True, cwd=dir_path)
final_branch_name = base_branches[0]
branch_to_fork = None
for base_branch in base_branches:
ret_code = call_process(
f"git show-ref refs/heads/{base_branch}",
shell=True,
cwd=dir_path
)
if ret_code == 0:
branch_to_fork = base_branch
break
if branch_to_fork is None:
print(f"Error: branches {base_branches} do not exist")
exit(1)
call_process("git clean -f -d", shell=True, cwd=dir_path)
call_process(f"git checkout {branch_to_fork}", shell=True, cwd=dir_path)
call_process(f"git reset --hard origin/{branch_to_fork}", shell=True, cwd=dir_path)
if final_branch_name != branch_to_fork:
print(f"creating '{final_branch_name}' branch from '{branch_to_fork}' branch")
call_process(f"git checkout -b {final_branch_name}", shell=True, cwd=dir_path)
def do_commit_push_branch(dir_path, base_branch, version):
print(f"commit and push to base branch='{base_branch}'..")
call_process(f"git add -u && git add *", shell=True, cwd=dir_path)
call_process(
f"git status && git commit -m \"Release for version {version}\"",
shell=True,
cwd=dir_path
)
call_process(
f"git push origin {base_branch} --force",
shell=True,
cwd=dir_path
)
def do_create_branch(dir_path, create_branch, version):
print("creating branch..")
call_process(f"git branch -D {create_branch}", shell=True, cwd=dir_path)
call_process(f"git checkout -b {create_branch}", shell=True, cwd=dir_path)
call_process(f"git add -u && git add *", shell=True, cwd=dir_path)
call_process(
f"git status && git commit -m \"Release for version {version}\"",
shell=True,
cwd=dir_path
)
call_process(f"git push origin {create_branch} --force", shell=True, cwd=dir_path)
def do_create_tag(dir_path, version):
print("creating tag..")
call_process(
f"git tag {version} --force -a -m \"Release tag for version {version}\"",
shell=True,
cwd=dir_path
)
call_process(f"git push origin {version} --force", shell=True, cwd=dir_path)
def call_process(command, *args, **kwargs):
print(f"Executing: {command}")
return subprocess.call(command, *args, **kwargs)
def do_create_release(
dir_path,
version,
release_draft,
release_title,
release_notes_file,
generate_release_notes,
previous_tag_name,
prerelease
):
if not generate_release_notes:
release_notes_md = ""
else:
github_token = os.getenv("GITHUB_TOKEN")
gh = Github(github_token)
release_notes = defaultdict(list)
project_name = os.path.basename(dir_path)
repo_path = f"sequentech/{project_name}"
print(f"Generating release notes for repo {repo_path}..")
repo = gh.get_repo(repo_path)
with open(".github/release.yml") as release_template_yaml:
config = yaml.safe_load(release_template_yaml)
prev_major, prev_minor, prev_patch = get_sem_release(previous_tag_name)
new_major, new_minor, new_patch = get_sem_release(version)
prev_release_head = get_release_head(prev_major, prev_minor, prev_patch)
if new_patch or prev_major == new_major:
new_release_head = get_release_head(new_major, new_minor, new_patch)
else:
new_release_head = repo.default_branch
print(f"Previous Release Head: {prev_release_head}")
print(f"New Release Head: {new_release_head}")
if prev_major != new_major:
# if we are going to do a new major release for example
# new_release="8.0.0", we need to obtain a list of all the changes made
# in the previous major release cycle (from 7.0.0 to
# previous_release="7.4.0") and mark them as hidden.
prev_major_release_head = get_release_head(prev_major, 0, "0")
else:
prev_major_release_head = None
print(f"Previous Major Release Head: {prev_major_release_head}")
hidden_links = []
# if we are going to do a new major release for example
# new_release="8.0.0", we need to obtain a list of all the changes made
# in the previous major release cycle (from 7.0.0 to
# previous_release="7.4.0") and mark them as hidden.
if prev_major_release_head:
print(f"Generating release notes for hidden links:")
(_, hidden_links) = get_release_notes(
gh, repo, prev_major_release_head, prev_release_head, config,
hidden_links=[]
)
print(f"Generating release notes:")
(repo_notes, _) = get_release_notes(
gh, repo, prev_release_head, new_release_head, config,
hidden_links=hidden_links
)
print(f"..generated")
for category, notes in repo_notes.items():
release_notes[category].extend(notes)
release_notes_md = create_release_notes_md(release_notes, new_release_head)
print(f"Generated Release Notes markdown: {release_notes_md}")
generated_release_title = f"{new_release_head} release"
with tempfile.NamedTemporaryFile() as temp_release_file:
temp_release_file.write(release_notes_md.encode('utf-8'))
temp_release_file.flush()
print("checking if release exists to overwrite it..")
ret_code = call_process(
f"gh release view {version}",
shell=True,
cwd=dir_path
)
if ret_code == 0:
# release exists, so remove it first
ret_code = call_process(
f"gh release delete {version}",
shell=True,
cwd=dir_path
)
if ret_code != 0:
print("Error: couldn't remove existing release")
exit(1)
print("creating release..")
release_file_path = (
release_notes_file
if release_notes_file is not None
else temp_release_file.name
)
release_notes_opt = f"--notes-file \"{release_file_path}\"\\\n"
release_title_opt = (
f"--title \"{release_title}\"\\\n"
if release_title is not None
else generated_release_title
)
release_draft_opt = "--draft\\\n" if release_draft else ""
prerelease_opt = "--prerelease\\\n" if prerelease else ""
call_process(f"git fetch --tags origin", shell=True, cwd=dir_path)
release_opts_str = " ".join([
version,
release_title_opt,
release_notes_opt,
release_draft_opt,
prerelease_opt
])
ret_code = call_process(
f"gh release create {release_opts_str}",
shell=True,
cwd=dir_path
)
if ret_code != 0:
print("Error: couldn't create the release")
exit(1)
def do_set_dependabot_branches(project_path, branches):
'''
Configures the repository branches that will get dependabot security alerts.
'''
# change to pristine master branch
call_process(f"git stash", shell=True, cwd=project_path)
call_process(f"git fetch origin master", shell=True, cwd=project_path)
call_process(f"git clean -f -d", shell=True, cwd=project_path)
call_process(f"git checkout master", shell=True, cwd=project_path)
call_process(f"git reset --hard origin/master", shell=True, cwd=project_path)
# load the .github/dependabot.yml.tpl template and render it
env = Environment(
loader=FileSystemLoader(project_path),
autoescape=select_autoescape(),
lstrip_blocks=True,
trim_blocks=True
)
template = None
try:
template = env.get_template(".github/dependabot.yml.tpl")
except:
print("Error: couldn't load .github/dependabot.yml.tpl")
exit(1)
dependabot_yml_rendered = template.render(
branches=branches
)
# check if we don't have to update the dependabot.yml file and finish if
# that is the case
dependabot_file_path = os.path.join(project_path, ".github", "dependabot.yml")
current_dependabot_yml = read_text_file(dependabot_file_path)
if dependabot_yml_rendered == current_dependabot_yml:
print("Nothing to do, the dependabot.yml file is already correct")
return
# update the dependabot.yml file, commit and push to master
print("Updating .github/dependabot.yml..")
write_text_file(dependabot_file_path, dependabot_yml_rendered)
print(f"commit and push to master branch..")
call_process(f"git add .github/dependabot.yml", shell=True, cwd=project_path)
call_process(f"git diff --cached", shell=True, cwd=project_path)
call_process(
f"git status && git commit -m \"Updating branches in .github/dependabot.yml\"",
shell=True,
cwd=project_path
)
call_process(
f"git push origin master --force",
shell=True,
cwd=project_path
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--change-version",
action="store_true",
help="Execute the version changing scripts specific for the project"
)
parser.add_argument(
"--version",
type=str,
help="version name",
metavar="1.3.2"
)
parser.add_argument(
"--path",
type=str,
help="project directory path",
metavar="../voting-booth"
)
parser.add_argument(
"--parent-path",
type=str,
help="directory parent to all the projects",
metavar="path/to/dir"
)
parser.add_argument(
"--base-branch",
type=str,
help="use a specific base branch (if it doesn't exist, try the next one in the list) instead of the current one",
metavar="v2.x",
nargs='+'
)
parser.add_argument(
"--create-branch",
type=str,
help="create the branch for this release",
metavar="v1.x"
)
parser.add_argument(
"--push-current-branch",
action="store_true",
help="push and commit changes to the current branch"
)
parser.add_argument(
"--create-tag",
action="store_true",
help="create the tag for this release"
)
parser.add_argument(
"--create-release",
action="store_true",
help="create the github release, requires gh command"
)
parser.add_argument(
"--release-draft",
action="store_true",
help="github draft release"
)
parser.add_argument(
"--release-title",
type=str,
help="github release title",
metavar="\"v1.3.2 (beta 1)\""
)
parser.add_argument(
"--previous-tag-name",
type=str,
help="previous release tag name",
metavar="\"5.3.4\""
)
parser.add_argument(
"--release-notes-file",
type=str,
help="github release notes file",
metavar="path/to/notes-file"
)
parser.add_argument(
"--generate-release-notes",
action="store_true",
help="use github automatic release generation"
)
parser.add_argument(
"--prerelease",
action="store_true",
help="github release notes"
)
parser.add_argument(
"--set-dependabot-branches",
metavar="BRANCH-NAME",
type=str,
nargs="+",
help="Set the dependabot alerts only for the given repository branches"
)
parser.add_argument(
'--dry-run',
action='store_true',
help=(
'Output the release notes but do not create any tag, release or '
'new branch.'
)
)
args = parser.parse_args()
change_version = args.change_version
version = args.version
base_branch = args.base_branch
create_branch = args.create_branch
push_current_branch = args.push_current_branch
create_tag = args.create_tag
create_release = args.create_release
release_draft = args.release_draft
release_title = args.release_title
prerelease = args.prerelease
generate_release_notes = args.generate_release_notes
previous_tag_name = args.previous_tag_name
set_dependabot_branches = args.set_dependabot_branches
path = args.path
parent_path = args.parent_path
if path is not None:
if not os.path.isdir(path):
raise Exception(path + ": path does not exist or is not a directory")
path = os.path.realpath(path)
parent_path = os.path.dirname(path)
elif parent_path is not None:
if not os.path.isdir(parent_path):
raise Exception(parent_path + ": path does not exist or is not a directory")
parent_path = os.path.realpath(parent_path)
release_notes_file = args.release_notes_file
if release_notes_file is not None:
if not os.path.isfile(release_notes_file):
raise Exception(release_notes_file + ": path does not exist or is not a file")
release_notes_file = os.path.realpath(release_notes_file)
print(f"""Options:
- change-version: {change_version}
- version: {version}
- path: {path}
- parent_path: {parent_path}
- base_branch: {base_branch}
- create_branch: {create_branch}
- push_current_branch: {push_current_branch}
- create_tag: {create_tag}
- create_release: {create_release}
- release_draft: {release_draft}
- release_title: {release_title}
- release_notes_file: {release_notes_file}
- generate_release_notes: {generate_release_notes}
- previous_tag_name: {previous_tag_name}
- prerelease: {prerelease}
- set_dependabot_branches: {set_dependabot_branches}
""")
if path is not None:
projects = [ get_project_type(path) ]
else:
projects = [
"common-ui",
"admin-console",
"election-portal",
"voting-booth",
"election-verifier",
"ballot_box",
"deployment-tool",
"tally-pipes",
"tally-methods",
"frestq",
"election-orchestra",
"iam",
"misc-tools",
"mixnet",
"documentation",
"release-tool"
]
for project_type in projects:
if path is not None:
project_path = path
else:
project_path = os.path.join(parent_path, project_type)
print("project: " + project_type)
if base_branch is not None:
apply_base_branch(project_path, base_branch)
if change_version:
if 'common-ui' == project_type:
do_gui_common(project_path, version)
elif 'admin-console' == project_type:
do_gui_other(project_path, version)
elif 'election-portal' == project_type:
do_gui_other(project_path, version)
elif 'voting-booth' == project_type:
do_gui_other(project_path, version)
elif 'election-orchestra' == project_type:
do_election_orchestra(project_path, version)
elif 'election-verifier' == project_type:
do_election_verifier(project_path, version)
elif 'ballot_box' == project_type:
do_ballot_box(project_path, version)
elif 'deployment-tool' == project_type: