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

Added test_version parameter to cli #394

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions src/tito/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(self, name=None, build_dir=None,
self.rpmbuild_options = self._get_optional_arg(kwargs, 'rpmbuild_options', '')

self.test = self._get_optional_arg(kwargs, 'test', False)
self.test_version = self._get_optional_arg(kwargs, 'test_version', None)
# Allow a builder arg to override the test setting passed in, used by
# releasers in their config sections.
if args and 'test' in args:
Expand Down Expand Up @@ -598,12 +599,12 @@ def _setup_test_specfile(self):
munge_specfile(
self.spec_file,
sha,
self.commit_count,
self.test_version,
fullname,
self.tgz_filename,
)

self.build_version += ".git." + str(self.commit_count) + "." + str(sha)
self.build_version += ".git." + str(self.test_version) + "." + str(sha)
self.ran_setup_test_specfile = True

def _get_rpmbuild_dir_options(self):
Expand Down Expand Up @@ -632,8 +633,9 @@ def _get_display_version(self):
if self.test:
# should get latest commit for given directory *NOT* HEAD
latest_commit = get_latest_commit(".")
self.commit_count = get_commit_count(self.build_tag, latest_commit)
version = "git-%s.%s" % (self.commit_count, latest_commit[:7])
if self.test_version is None:
self.test_version = get_commit_count(self.build_tag, latest_commit)
version = "git-%s.%s" % (self.test_version, latest_commit[:7])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

else:
version = self.build_version.split("-")[0]
return version
Expand Down Expand Up @@ -681,11 +683,11 @@ def _setup_test_specfile(self):
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
debug("setup_test_specfile:commit_count = %s" % str(self.commit_count))
debug("setup_test_specfile:test_version = %s" % str(self.test_version))
munge_specfile(
self.spec_file,
self.git_commit_id[:7],
self.commit_count
self.test_version
)


Expand Down Expand Up @@ -1101,7 +1103,7 @@ def _setup_test_specfile(self):
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
self.build_version += ".git." + str(self.commit_count) + "." + str(self.git_commit_id[:7])
self.build_version += ".git." + str(self.test_version) + "." + str(self.git_commit_id[:7])
replace_spec_release(self.spec_file, self.spec_release)
self.ran_setup_test_specfile = True

Expand Down
3 changes: 3 additions & 0 deletions src/tito/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def __init__(self):

self.parser.add_option("--test", dest="test", action="store_true",
help="use current branch HEAD instead of latest package tag")
self.parser.add_option("--test-version", dest="test_version", metavar="TESTVERSION",
help="overrides the commit count number in the produced artifact name in test build")
self.parser.add_option("--no-cleanup", dest="no_cleanup",
action="store_true",
help="do not clean up temporary tito build directories/files, and disable rpmbuild %clean")
Expand Down Expand Up @@ -369,6 +371,7 @@ def main(self, argv):
kwargs = {
'dist': self.options.dist,
'test': self.options.test,
'test_version': self.options.test_version,
'offline': self.options.offline,
'auto_install': self.options.auto_install,
'rpmbuild_options': self.options.rpmbuild_options,
Expand Down