From a3dd6ab57a4ee842341c7a2971f8490268ebb439 Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Thu, 5 Mar 2020 18:43:55 +0100 Subject: [PATCH] packit, don't touch version, change release only by default Fixes #693 Read that issue for more info (and get a coffee). Signed-off-by: Tomas Tomecek --- packit/config/package_config.py | 1 + packit/upstream.py | 41 +++++++++++++++++++++++++++++- tests/integration/test_upstream.py | 21 ++++++++++++--- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packit/config/package_config.py b/packit/config/package_config.py index 7b116e33c..ed9d4f56c 100644 --- a/packit/config/package_config.py +++ b/packit/config/package_config.py @@ -113,6 +113,7 @@ def __init__( self.current_version_command: List[str] = current_version_command or [ "git", "describe", + "--abbrev=0", "--tags", "--match", "*", diff --git a/packit/upstream.py b/packit/upstream.py index bd011dd60..f3c2e31ac 100644 --- a/packit/upstream.py +++ b/packit/upstream.py @@ -19,6 +19,7 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import datetime import logging import os import re @@ -466,11 +467,49 @@ def fix_spec(self, archive: str, version: str, commit: str): :param version: version to set in the spec :param commit: commit to set in the changelog """ + # we only care about the first number in the release + # so that we can re-run `packit srpm` + original_release_number = self.specfile.get_release_number().split(".", 1)[0] + + current_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S%f") + + git_des_command = [ + "git", + "describe", + "--tags", + "--long", + "--dirty", + "--match", + "*", + ] + try: + git_des_out = run_command(git_des_command, output=True).strip() + except PackitCommandFailedError as ex: + logger.info(f"Exception while describing the repository: {ex}") + # probably no tags in the git repo + git_desc_suffix = "" + else: + # git adds various info in the output separated by - + # so let's just drop version and reuse everything else + g_desc_raw = git_des_out.split("-", 1)[1] + # release components are meanto to be separated by ".", not "-" + git_desc_suffix = "." + g_desc_raw.replace("-", ".") + # instead of changing version, we change Release field + # upstream projects should take care of versions + template = "{original_release_number}.{current_time}{git_desc_suffix}" self._fix_spec_source(archive) self._fix_spec_prep(version) msg = f"- Development snapshot ({commit})" - self.specfile.set_spec_version(version=f"{version}", changelog_entry=msg) + release = template.format( + original_release_number=original_release_number, + current_time=current_time, + git_desc_suffix=git_desc_suffix, + ) + logger.debug(f"Setting Release in spec to {release!r}") + self.specfile.set_spec_version( + version=version, release=release, changelog_entry=msg, + ) def _fix_spec_prep(self, version): prep = self.specfile.spec_content.section("%prep") diff --git a/tests/integration/test_upstream.py b/tests/integration/test_upstream.py index d56202c39..63bd17d4c 100644 --- a/tests/integration/test_upstream.py +++ b/tests/integration/test_upstream.py @@ -77,8 +77,7 @@ def test_get_version(upstream_instance, m_v, exp): subprocess.check_call(["git", "add", "."], cwd=u) subprocess.check_call(["git", "commit", "-m", "More awesome changes"], cwd=u) - # 0.1.0.1.ge98cee1 - assert re.match(r"0\.1\.0\.1\.\w{8}", ups.get_current_version()) + assert ups.get_current_version() == "0.1.0" def test_get_version_macro(upstream_instance): @@ -163,7 +162,9 @@ def test_create_archive(upstream_instance, extension): ups.create_archive() - assert len(list(u.glob(f"*{extension}"))) == 2 + # there is still only one archive - we no longer use --long git-describe + # by default, upstreams should handle versions themselves + assert len(list(u.glob(f"*{extension}"))) == 1 def test_create_uncommon_archive(upstream_instance): @@ -210,6 +211,20 @@ def test_create_srpm(upstream_instance, tmpdir): build_srpm(srpm) +def test_create_srpm_git_desc_release(upstream_instance, tmpdir): + u, ups = upstream_instance + u.joinpath("README").write_text("\nEven better now!\n") + subprocess.check_call(["git", "add", "."], cwd=u) + subprocess.check_call(["git", "commit", "-m", "More awesome changes"], cwd=u) + + ups.create_archive() + ups.prepare_upstream_for_srpm_creation() + srpm = ups.create_srpm() + assert srpm.exists() + build_srpm(srpm) + assert re.match(r".+beer-0.1.0-1.\d+.fc\d{2}.src.rpm$", str(srpm)) + + def test_github_app(upstream_instance, tmpdir): u, ups = upstream_instance t = Path(tmpdir)