5

We're using Git as our VCS and RPMs for packaging. I'd like to store the Git hash a package was built from, but I'm not sure on the most appropriate place.

There are a number of tags available to an RPM, however I don't see any for a VCS version (maybe glanced over it?).

I'm quite leery about adding a custom tag, just looking at the 50,000 ft level.

One solution that feels pretty hacky would be to put the Git hash in the description field. We're not using it for anything else at this point, but wow, that just feels ugly.

So what is the most appropriate place to store a VCS version in an RPM?

quickshiftin
  • 2,025
  • 5
  • 27
  • 41

2 Answers2

4

Fedora (and very rarely RHEL) place this information in the Release tag.

For instance:

Name:           mypackage
Version:        0.0.1
Release:        20140114git0abcdef
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Currently I'm using the build number from Jenkins for the release tag, but it might make more sense to use the hash instead, or a combination thereof. It's nice to have both really, if at all possible. Thanks for your answer and the link, very helpful. – quickshiftin Jan 14 '14 at 21:35
  • If you do more than one build per day, then throwing in the build number would be helpful. – Michael Hampton Jan 14 '14 at 21:37
3

RPM actually has a poorly documented VCS tag.

It doesn't appear to have any sort of guidelines on its use, but it exists and is supported.

cat > test.spec <<'__END__'
Name: foo
Version: 1
Summary: foo
License: None
Release: 1
VCS: git:repo=my-repo:branch=my-branch:sha=1234deadbeef

%description
foo
__END__


$ rpmspec -q test.spec --qf "%{VCS}\n"
git:repo=my-repo:branch=my-branch:sha=1234deadbeef

It appears to be limited to a single parse token. Still useful. I didn't find any documentation on a well defined format or structure for it, and its adoption is limited. On my Fedora 32 system I found two packages using it, with different formats:

$ rpm -qa --qf '%{Name} %{VCS}\n' |grep -v '(none)'
bcache-tools https://github.com/g2p/bcache-tools.git
libcue scm:git:https://github.com/lipnitsk/libcue.git
$

Frankly it's a real shame rpm doesn't give us the ability to inject custom tag info. I want to record the Jenkins build ID and job name, the git commit hash, and git branch or tag, but don't really want them in the changelog.

I can do this in debs with X-BS-foo tags.


You can see a list of allowed rpm tags with rpm --querytags.

The DISTURL tag appears to be reserved for another use but could be a candidate.

There's also URL; you could choose to embed SCM info there, and have a redirect that takes the URL to a reasonable location if visited by a browser.


You may see references to "rpm5" supporting custom tags. This seems to be a dead fork of rpm, not the rpm.org distribution used on most major distros.

Craig Ringer
  • 10,553
  • 9
  • 38
  • 59