This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
release.py
executable file
·126 lines (96 loc) · 3.91 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
#!/usr/bin/env python
import argparse
import fileinput
from distutils.util import strtobool
import os
import subprocess
from build_and_push_images import IMAGES, docker_build, docker_push
def ask_yes_no(question):
return strtobool(input(question))
def continue_or_stop(text):
print(text)
if not ask_yes_no("are you sure to continue? (y/n) "):
print("exiting.")
exit(0)
def execute(command, shell=False):
if isinstance(command, str):
command = command.split()
subprocess.check_call(command, shell=shell)
def execute_steps(steps):
for step in steps:
execute(step)
def build_and_push_images(release_version):
for image in IMAGES:
docker_build(release=release_version, **image)
for image in IMAGES:
docker_push(release=release_version, **image)
def prepare_for_release(release_version):
execute_steps([
"git checkout develop",
"git pull --ff-only",
"git flow release start {}".format(release_version),
])
def create_data_schema_documentation():
import pypandoc as converter
module_folder = os.path.dirname(__file__)
docs_folder = os.path.abspath(os.path.join(module_folder, 'docs'))
output_file = os.path.abspath(os.path.join(
module_folder,
'osmaxx', 'conversion', 'converters', 'converter_gis', 'static', 'doc', 'osmaxx_data_schema.html')
)
html = converter.convert(os.path.join(docs_folder, 'osmaxx_data_schema.md'), 'html5')
with open(output_file, 'w') as output:
output.write(html)
def make_release_specific_changes(release_version):
execute_steps([
"python ./web_frontend/manage.py makemessages -l en",
"python ./web_frontend/manage.py compilemessages -l en",
["git", "commit", "-m", 'added makemessages output', 'osmaxx/locale'],
])
create_data_schema_documentation()
try:
execute(
[
"git", "commit", "-m", 'updated schema documentation HTML',
'osmaxx/conversion/converters/converter_gis/static/doc/osmaxx_data_schema.html',
]
)
except subprocess.CalledProcessError as err:
print(err.output)
continue_or_stop('The error above happened. Do you wish to continue?')
version_file_path = os.path.join(os.path.dirname(__file__), 'osmaxx', '__init__.py')
for line in fileinput.input(version_file_path, inplace=True):
line = line.rstrip(os.linesep)
if line.startswith('__version__'):
line = "__version__ = '{}'".format(release_version)
print(line)
print("""################### Updated VERSION file
{}
""".format(execute("git diff osmaxx/__init__.py")))
continue_or_stop('Is the version file correct?')
execute(["git", "commit", "-m", 'bump version to {}'.format(release_version), 'osmaxx/__init__.py'])
def release_finish(release_version):
execute_steps([
["git", "flow", "release", "finish", release_version, "-m", "'OSMaxx release {}'".format(release_version)],
["git", "push", "origin", "develop:develop", "master:master", release_version],
])
execute(["git", "checkout", release_version])
build_and_push_images(release_version)
execute(["git", "checkout", "develop"])
def release_done():
print("""
---------------------------------
release {} finished
You can now use this in your deployment.
""".format(release_version))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('release', type=str, help='version to be released')
args = parser.parse_args()
release_version = args.release
continue_or_stop("You want to make a new release {}".format(release_version))
prepare_for_release(release_version)
make_release_specific_changes(release_version)
continue_or_stop("Should be continued to push the release to the repository?")
release_finish(release_version)
release_done()