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

Add autospec information to spec header #805

Merged
merged 1 commit into from
Oct 16, 2023
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
25 changes: 24 additions & 1 deletion autospec/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,31 @@
import glob
import os
import subprocess
import sys
import tempfile

from util import call, write_out
from util import call, open_auto, write_out


def get_autospec_info():
"""Get the latest tag from autospec."""
path = os.path.dirname(sys.path[0])
git_out = tempfile.mkstemp()[1]
try:
call("git tag -l --sort=-v:refname", git_out, cwd=path)
with open_auto(git_out) as gfile:
tag = gfile.readlines()[0].strip()
except Exception:
tag = ""
os.unlink(git_out)
try:
call('git log -1 --pretty=format:"%h"', git_out, cwd=path)
with open_auto(git_out) as gfile:
commit = gfile.readlines()[0].strip()
except Exception:
commit = ""
os.unlink(git_out)
return tag, commit


def commit_to_git(config, name, success):
Expand Down
4 changes: 4 additions & 0 deletions autospec/specfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import types
from collections import OrderedDict

import git
from util import _file_write, open_auto


Expand Down Expand Up @@ -104,6 +105,9 @@ def write_comment_header(self):
self._write("# This file is auto-generated. DO NOT EDIT\n")
self._write("# Generated by: autospec.py\n")
self._write(f"# Using build pattern: {self.config.default_pattern}\n")
tag, commit = git.get_autospec_info()
self._write(f"# autospec version: {tag}\n")
self._write(f"# autospec commit: {commit}\n")
self._write("#\n")

# if package was verified, write public key information
Expand Down
2 changes: 2 additions & 0 deletions tests/test_specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def test_write_comment_header(self):
"#\n",
"# Source0 file verified with key 0x1 (email)",
"#"]
# skipping autospec version lines as they change
self.WRITES = self.WRITES[:4] + self.WRITES[6:]
self.assertEqual(expect, self.WRITES)

def test_write_nvr_no_urlban(self):
Expand Down