Skip to content

Commit

Permalink
Merge pull request #3121 from wazuh/change/3120-add-the-installation-…
Browse files Browse the repository at this point in the history
…assistant-version-bump

Add stage parameter in bump_version script
  • Loading branch information
MarcelKemp authored Sep 20, 2024
2 parents fa4ff6a + a4e2876 commit 8206087
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
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('-s', '--stage', action='store', dest='stage',
help='Stage to bump to. Default: none',
default='')
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))
Expand All @@ -42,7 +45,7 @@
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)
builder_files=glob.glob('**/unattended_installer/builder.sh', recursive=True)


#Format variables
SPEC_FORMAT_STRING="%a %b %d %Y"
Expand Down Expand Up @@ -85,11 +88,15 @@
install_variables_files_dict = {
r'wazuh_major=\"(\d+\.\d+)\"':
f'wazuh_major=\"{version.major}.{version.minor}\"',
r'wazuh_version=\"(\d+\.\d+\.\d+)\"':f'wazuh_version=\"{version}\"'}
r'wazuh_version=\"(\d+\.\d+\.\d+)\"': f'wazuh_version=\"{version}\"',
r'source_branch="v\$\{wazuh_version\}(-[a-zA-Z0-9]+)?"': f'source_branch=\"v${{wazuh_version}}-{args.stage}\"' if args.stage else
'source_branch="v${wazuh_version}"'}

unattended_builder_files_dict = {
r'source_branch="(\d+\.\d+\.\d+)"':f'source_branch="{version}"'}
r'source_branch="v(\d+\.\d+\.\d+)(-[a-zA-Z0-9]+)?"': f'source_branch=\"v{version}-{args.stage}\"' if args.stage else
f'source_branch="v{version}"'}

# if there is no line with version
changelog_md_files_dict = {
(r'All notable changes to this project '
r'will be documented in this file.'):
Expand All @@ -98,8 +105,6 @@
+ (f"## [{version}]\n\n- https://github.com/wazuh/"
f"wazuh-packages/releases/tag/v{version}\n")}

builder_files_dict = {
r'source_branch=\"(\d+\.\d+\.\d+)\"': f'source_branch=\"{version}\"'}

VERSION_files_dict = {
r'(\d+\.\d+\.\d+)': f'{version}'}
Expand All @@ -126,6 +131,24 @@ def bump_file_list(file_list, regex_replacement):
file.write(filedata)


def check_version_in_changelog_md():
for changelog_md_file in changelog_md_files:
with open(changelog_md_file, 'r', encoding="utf-8") as file:
filedata = file.read()
if re.search(rf'## \[{version}\]', filedata):
return True
return False


def check_version_in_spec_files():
for spec_file in spec_files:
with open(spec_file, 'r', encoding="utf-8") as file:
filedata = file.read()
if re.search(rf'support <info@wazuh.com> - {version}', filedata):
return True
return False


## Bump version in deb changelog files
for changelog_file in changelog_files:
with open(changelog_file, 'r', encoding="utf-8") as file:
Expand All @@ -145,13 +168,12 @@ def bump_file_list(file_list, regex_replacement):
file.write(filedata)


bump_file_list(spec_files,spec_files_dict)
None if check_version_in_spec_files() else bump_file_list(spec_files,spec_files_dict)
bump_file_list(copyright_files,copyright_files_dict)
bump_file_list(pkginfo_files,pkginfo_files_dict)
bump_file_list(pkgproj_files,pkgproj_files_dict)
bump_file_list(test_files,test_files_dict)
bump_file_list(install_variables_files,install_variables_files_dict)
bump_file_list(unattended_builder_files,unattended_builder_files_dict)
bump_file_list(changelog_md_files,changelog_md_files_dict)
None if check_version_in_changelog_md() else bump_file_list(changelog_md_files,changelog_md_files_dict)
bump_file_list(VERSION_files,VERSION_files_dict)
bump_file_list(builder_files,builder_files_dict)

0 comments on commit 8206087

Please sign in to comment.