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

packit, don't touch version, change release #748

Merged
merged 1 commit into from Mar 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packit/config/package_config.py
Expand Up @@ -113,6 +113,7 @@ def __init__(
self.current_version_command: List[str] = current_version_command or [
"git",
"describe",
"--abbrev=0",
"--tags",
"--match",
"*",
Expand Down
41 changes: 40 additions & 1 deletion packit/upstream.py
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Comment on lines +492 to +494
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work for all projects? Are tags always versions only? The reason for asking is b/c in git.centos.org, I see tags like imports/c8/rpm-4.14.2-25.el8, which also contain a version, but they will fail to be processed this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

that's git-describe specific, it uses dashes to separate different data - sadly one cannot format it

yeah, we may need to polish this for centos stream - or figure out how to operate with release and version - we will be in control of the repos, so we may use more sensible tags

Copy link
Member Author

Choose a reason for hiding this comment

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

what I wrote is bullshit, I thought we're talking about something else - in your case, curse all the people who use dashes in tags

# 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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would using a format-string and dropping template make things easier to read?

Copy link
Member Author

Choose a reason for hiding this comment

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

uuhhhhhhhhhhhhhhhh

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")
Expand Down
21 changes: 18 additions & 3 deletions tests/integration/test_upstream.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down