Skip to content

Commit

Permalink
Add autospec information to spec header
Browse files Browse the repository at this point in the history
Add information about what autospec version was used to create the
spec file.

New header will appear as:

+# autospec version: v2
+# autospec commit: 1234567

With this change we'll restart tagging autospec. Changes that get
tagged (after PR merge, tag likely just pushed via git cli) should be
doing something that would benefit from a larger package ecosystem
rebuild.

Signed-off-by: William Douglas <[email protected]>
  • Loading branch information
bryteise committed Oct 16, 2023
1 parent 623d973 commit 4a415bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit 4a415bc

Please sign in to comment.