-
Notifications
You must be signed in to change notification settings - Fork 135
/
release.py
executable file
·115 lines (91 loc) · 4.11 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
#!/usr/bin/env python3
import yaml
import argparse
import sys
parser = argparse.ArgumentParser(
description='Release utility for the Graylog Docker image.')
parser.add_argument('--get-graylog-version',
help="Get Graylog image version.", action='store_true')
parser.add_argument('--get-forwarder-version',
help="Get Forwarder version.", action='store_true')
parser.add_argument('--get-forwarder-image-version',
help="Get Forwarder image version.", action='store_true')
parser.add_argument('--generate-readme',
help="Generate a new README.md with the latest tags", action='store_true')
parser.add_argument('--bump', dest='bump',
choices=['graylog', 'forwarder'], help="Bump the given version")
parser.add_argument('--version', dest='version',
help="The new version and revision")
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
if args.bump and not args.version:
parser.error('Missing --version parameter')
version_parsed = None
with open('version.yml', 'r') as version_file:
version_parsed = yaml.safe_load(version_file)
if args.get_graylog_version:
print(str(version_parsed['graylog']['major_version']) + '.' + str(version_parsed['graylog']
['minor_version']) + '.' + str(version_parsed['graylog']['patch_version']), end='')
if args.get_forwarder_version:
print(str(version_parsed['forwarder']['version']), end='')
if args.get_forwarder_image_version:
print(str(version_parsed['forwarder']['version']) + '-' +
str(version_parsed['forwarder']['release']), end='')
if args.generate_readme:
from jinja2 import Template
with open('README.j2', 'r') as template_file:
j2_template = Template(template_file.read())
with open("README.md", "w") as readme_file:
readme_file.write(j2_template.render(version_parsed))
if args.bump == 'graylog':
print(f'Bumping {args.bump} to {args.version}')
# 6.0.0-alpha.1-1 => version="6.0.0", suffixes=["alpha.1", "1"]
# 6.0.0-1 => version="6.0.0", suffixes=["1"]
version, *suffixes = args.version.split('-', 2)
# 6.0.0 => major=6, minor=0, patch= 0
major, minor, patch = version.split('.', 2)
suffix = None
release = None
if len(suffixes) == 0:
raise RuntimeError("Missing revision suffix!")
elif len(suffixes) > 1:
suffix = suffixes[0]
release = suffixes[1]
else:
suffix = None
release = suffixes[0]
version_parsed[args.bump]['major_version'] = major
version_parsed[args.bump]['minor_version'] = minor
version_parsed[args.bump]['patch_version'] = f'{patch}-{suffix}' if suffix else patch
version_parsed[args.bump]['release'] = int(release)
print(version_parsed[args.bump])
if args.bump == 'forwarder':
print(f'Bumping {args.bump} to {args.version}')
# 6.0-alpha.1-1 => version="6.0", suffixes=["alpha.1", "1"]
# 6.0-1 => version="6.0", suffixes=["1"]
version, *suffixes = args.version.split('-', 2)
suffix = None
release = None
if len(suffixes) == 0:
raise RuntimeError("Missing revision suffix!")
elif len(suffixes) > 1:
suffix = suffixes[0]
release = suffixes[1]
else:
suffix = None
release = suffixes[0]
version_parsed[args.bump]['version'] = f'{version}-{suffix}' if suffix else version
version_parsed[args.bump]['release'] = int(release)
print(version_parsed[args.bump])
if version_parsed and args.bump:
with open('version.yml', 'w') as f:
yaml.dump(version_parsed, f, sort_keys=False)
with open('version.yml', 'r+') as f:
content = f.read()
f.seek(0, 0)
# Preserve some comments
f.write('# For pre-releases: patch_version=0-beta.1, patch_version=0-rc.1\n')
f.write('# For GA releases: patch_version=0\n')
f.write(content)