-
Notifications
You must be signed in to change notification settings - Fork 97
/
bump_version.py
executable file
·218 lines (183 loc) · 8.72 KB
/
bump_version.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
#! /usr/bin/env python3
"""
This script is used to bump the version of the Wazuh packages repository.
Copyright (C) 2015-2020, Wazuh Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import argparse
import datetime
import glob
import re
from packaging.version import Version
FORMAT_STRING="%m-%d-%Y"
arg_parser=argparse.ArgumentParser()
arg_parser.add_argument('-v', '--version', action='store', dest='version',
help='Version to bump to', required=True)
arg_parser.add_argument('-r', '--revision', action='store', dest='revision',
help='Revision to bump to. Default: 1', default=1)
arg_parser.add_argument('-d', '--date', action='store', dest='date',
help='Date to bump to. Format: m-d-Y. Default: today',
default=datetime.date.today().strftime(FORMAT_STRING))
args=arg_parser.parse_args()
date=datetime.datetime.strptime(args.date, FORMAT_STRING)
version=Version(args.version)
## Find files to bump .spec, changelog, pkginfo, .pkgproj, test-*.sh,
## installVariables.sh, unattended_installer/builder.sh, CHANGELOG.md
spec_files=glob.glob('**/*.spec', recursive=True)
changelog_files=glob.glob('**/changelog', recursive=True)
copyright_files=glob.glob('**/copyright', recursive=True)
pkginfo_files=glob.glob('**/pkginfo', recursive=True)
pkgproj_files=glob.glob('**/*.pkgproj', recursive=True)
test_files=glob.glob('**/test-*.sh', recursive=True)
install_variables_files=glob.glob('**/installVariables.sh', recursive=True)
unattended_builder_files=glob.glob('**/unattended_installer/builder.sh', recursive=True)
changelog_md_files=glob.glob('**/CHANGELOG.md', recursive=True)
VERSION_files=glob.glob('**/VERSION', recursive=True)
## Bump version in .spec files
SPEC_FORMAT_STRING="%a %b %d %Y"
spec_date=date.strftime(SPEC_FORMAT_STRING)
for spec_file in spec_files:
with open(spec_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + spec_file)
filedata=file.read()
# Replace version and revision
REGEX=r'Version:\s*(\d+\.\d+\.\d+)'
filedata=re.sub(REGEX, f"Version: {version}", filedata)
REGEX=r'Revision:\s*(\d+)'
filedata=re.sub(REGEX, 'Revision: ' + str(args.revision),
filedata)
# Add new version to changelog
REGEX=r'%changelog'
changelog_string=(f"* {spec_date} support <[email protected]> - {version}"
"\n- More info: https://documentation.wazuh.com/current/release-"
f"notes/release-{version.major}-{version.minor}-"
f"{version.micro}.html")
filedata=re.sub(REGEX, '%changelog\n' + changelog_string, filedata)
with open(spec_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in deb changelog files
DEB_FORMAT_STRING="%a, %d %b %Y %H:%M:%S +0000"
deb_changelog_date=date.strftime(DEB_FORMAT_STRING)
for changelog_file in changelog_files:
with open(changelog_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + changelog_file)
filedata=file.read()
install_type=re.search(r'(wazuh-(agent|manager|indexer|dashboard))',
filedata).group(1)
changelog_string=(f"{install_type} ({version}-RELEASE) stable; "
"urgency=low\n\n * More info: https://documentation.wazuh.com/"
f"current/release-notes/release-{version.major}-{version.minor}-"
f"{version.micro}.html\n\n -- "
f"Wazuh, Inc <[email protected]> {deb_changelog_date}\n\n")
# Add new version to changelog
filedata=changelog_string + filedata
with open(changelog_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in deb copyrigth files
for copyrigth_file in copyright_files:
with open(copyrigth_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + copyrigth_file)
filedata=file.read()
# Replace version and revision
REGEX=(r'Wazuh, Inc <[email protected]> on '
r'(\w+),\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+)\s\+(\d+)')
filedata=re.sub(REGEX,
f"Wazuh, Inc <[email protected]> on {deb_changelog_date}",
filedata)
with open(copyrigth_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in pkginfo files
PKGINFO_FORMAT_STRING="%d%b%Y"
for pkginfo_file in pkginfo_files:
with open(pkginfo_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + pkginfo_file)
filedata=file.read()
# Replace version and revision
REGEX=r'VERSION=\"(\d+\.\d+\.\d+)\"'
filedata=re.sub(REGEX, f'VERSION=\"{version}\"', filedata)
REGEX=r'PSTAMP=(.*)'
filedata=re.sub(REGEX,
f'PSTAMP=\"{date.strftime(PKGINFO_FORMAT_STRING)}\"',
filedata)
with open(pkginfo_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in .pkgproj files
for pkgproj_file in pkgproj_files:
with open(pkgproj_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + pkgproj_file)
filedata=file.read()
# Replace version and revision
REGEX=r'<string>(\d+\.\d+\.\d+)-(\d+)</string>'
filedata=re.sub(REGEX, f'<string>{version}-{args.revision}</string>',
filedata)
REGEX=r'<string>wazuh-agent-(\d+\.\d+\.\d+)-(\d+)'
filedata=re.sub(REGEX,
f'<string>wazuh-agent-{version}-{args.revision}',
filedata)
with open(pkgproj_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in test-*.sh files
for test_file in test_files:
with open(test_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + test_file)
filedata=file.read()
# Replace version and revision
REGEX=r'wazuh-manager.x86_64\s+(\d+\.\d+\.\d+)-(\d+)'
filedata=re.sub(REGEX,
f'wazuh-manager.x86_64 {version}-{args.revision}',
filedata)
REGEX=r'wazuh_version=\"(\d+\.\d+\.\d+)\"'
filedata=re.sub(REGEX, f'wazuh_version=\"{version}\"', filedata)
with open(test_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in installVariables.sh files
for install_variables_file in install_variables_files:
with open(install_variables_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + install_variables_file)
filedata=file.read()
# Replace version and revision
REGEX=r'wazuh_major=\"(\d+\.\d+)\"'
filedata=re.sub(REGEX,
f'wazuh_major=\"{version.major}.{version.minor}\"',
filedata)
REGEX=r'wazuh_version=\"(\d+\.\d+\.\d+)\"'
filedata=re.sub(REGEX, f'wazuh_version=\"{version}\"', filedata)
with open(install_variables_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in unattended installer build file
for builder_file in unattended_builder_files:
with open(builder_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + builder_file)
filedata=file.read()
# Replace version and revision
REGEX=r'source_branch="(\d+\.\d+\.\d+)"'
filedata=re.sub(REGEX, f'source_branch="{version}"', filedata)
with open(builder_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in CHANGELOG.md files
for changelog_md_file in changelog_md_files:
with open(changelog_md_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + changelog_md_file)
filedata=file.read()
# Add new version to changelog
REGEX=(r'All notable changes to this project '
r'will be documented in this file.')
changelog_string=(f"## [{version}]\n\n- https://github.com/wazuh/"
f"wazuh-packages/releases/tag/v{version}\n")
filedata=re.sub(REGEX, REGEX + '\n' + changelog_string,
filedata)
with open(changelog_md_file, 'w', encoding="utf-8") as file:
file.write(filedata)
## Bump version in VERSION files
for VERSION_file in VERSION_files:
with open(VERSION_file, 'r', encoding="utf-8") as file:
print('Bumping version in ' + VERSION_file)
filedata=file.read()
# Replace version and revision
REGEX=r'(\d+\.\d+\.\d+)'
filedata=re.sub(REGEX, f'{version}', filedata)
with open(VERSION_file, 'w', encoding="utf-8") as file:
file.write(filedata)