Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: T6904: allow development builds to have version strings #842

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions scripts/image-build/build-vyos-image
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ if __name__ == "__main__":
'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', None),
'vyos-mirror': ('VyOS package mirror', None),
'build-type': ('Build type, release or development', lambda x: x in ['release', 'development']),
'version': ('Version number (release builds only)', None),
'version': ('Version string', None),
'build-comment': ('Optional build comment', None),
'build-hook-opts': ('Custom options for the post-build hook', None)
}
Expand Down Expand Up @@ -269,19 +269,11 @@ if __name__ == "__main__":
if pre_build_config['pbuilder_debian_mirror'] is None:
args['pbuilder_debian_mirror'] = pre_build_config['pbuilder_debian_mirror'] = pre_build_config['debian_mirror']

# Version can only be set for release builds,
# for dev builds it hardly makes any sense
if pre_build_config['build_type'] == 'development':
if args['version'] is not None:
print("E: Version can only be set for release builds")
print("Use --build-type=release option if you want to set version number")
sys.exit(1)

# Validate characters in version name
if 'version' in args and args['version'] != None:
if args.get('version'):
allowed = string.ascii_letters + string.digits + '.' + '-' + '+'
if not set(args['version']) <= set(allowed):
print(f'Version contained illegal character(s), allowed: {allowed}')
print(f'Version string contains illegal character(s), allowed: {allowed}')
sys.exit(1)

## Inject some useful hardcoded options
Expand Down Expand Up @@ -413,8 +405,10 @@ if __name__ == "__main__":
build_git = ""
git_branch = ""

# Create the build version string
if build_config['build_type'] == 'development':
# Create the build version string, if it's not explicitly given
if build_config.get('version'):
version = build_config['version']
else:
try:
if not git_branch:
raise ValueError("git branch could not be determined")
Expand All @@ -429,9 +423,6 @@ if __name__ == "__main__":
except Exception as e:
print("W: Could not build a version string specific to git branch, falling back to default: {0}".format(str(e)))
version = "999.{0}".format(build_timestamp)
else:
# Release build, use the version from ./configure arguments
version = build_config['version']

version_data = {
'version': version,
Expand Down Expand Up @@ -674,7 +665,7 @@ Pin-Priority: 600
# If not, build additional flavors from the ISO.
if build_config["image_format"] != ["iso"]:
# For all non-iso formats, we always build a raw image first
raw_image = raw_image.create_raw_image(build_config, iso_file, "tmp/")
version_data, raw_image = raw_image.create_raw_image(build_config, iso_file, "tmp/")
manifest['artifacts'].append(raw_image)

# If there are other formats in the flavor, the assumptions is that
Expand Down Expand Up @@ -704,8 +695,10 @@ Pin-Priority: 600
hook_opts = build_config["build_hook_opts"]
else:
hook_opts = ""
custom_image = rc_cmd(f"./build_hook {raw_image} {build_config['version']} \
{build_config['architecture']} {hook_opts}")
build_hook_command = f"./build_hook {raw_image} {version_data['version']} \
{build_config['architecture']} {hook_opts}"
print(f'I: executing build hook command: {build_hook_command}')
custom_image = rc_cmd(build_hook_command)
manifest['artifacts'].append(custom_image)

# Filter out unwanted files from the artifact list
Expand Down
2 changes: 1 addition & 1 deletion scripts/image-build/raw_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ def create_raw_image(build_config, iso_file, work_dir):
install_image(con, version)
install_grub(con, version)

return raw_file
return (version_data, raw_file)
Loading