Where to put last git commit id in an rpm
Asked Answered
A

1

7

I would like to add the last "git commit id" to my rpms to have a foolproof way to track back the sources used to build a package.

I could use the rpm release tag, but this is already used for release numbers and dates in case of snapshots. I don't want to overload this any further.

Is there another tag or mechanism to store the last commit-id in an rpm?

Ambulance answered 22/5, 2014 at 12:59 Comment(2)
Do you need this to be available to users via the rpm or yum commands, or do you simply want a way for packagers to know what sources they used?Hypogeal
I would like it to be able from rpm or yum commands, but as a tag. Encoding it in the rpm name would be ugly imho.Ambulance
H
10

I'm not aware of anything in the Spec format specifically designed for this, but I do see a couple of options:

  • Use the version tag
    • You mentioned the release tag in your question, but this is for the package version, not the software version. A Git revision is much more like a software version than a package version.
    • For stable releases you can still use numeric tags like 1.0 if you want, but I'd advise you to make sure that this corresponds to a Git tag with the same name so your version will always be meaningful to Git.
    • Doing this means that you should probably also use the serial tag, so RPM can figure out how to order versions. (This may not be necessary if you tag properly and use the method below for determining your version.)
    • This will include the revision in the name of your package, or at least in the file name, and it sounds like you don't want that.
  • Name your source archive with the Git hash and then use a url tag like http://example.com/software/software-abcd123.zip.
    • You will not need to include the revision in your package file name using this method.

In the first case case (and possibly the second), it may be worthwhile to use git describe to determine your Git-aware version number, e.g.

$ git describe HEAD
1.0.0-3-gabcd123
'-.-' | |'--.--'
  |   | |   `---- Short Git hash
  |   | `-------- Indicates that a Git hash follows
  |   `---------- Three commits ahead of the previous tag name
  `-------------- The name of the base tag

Note that your RPM version cannot contain hyphens, so this version may have to be transcribed to something like 1.0.0_3_gabcd123.

Hypogeal answered 22/5, 2014 at 13:59 Comment(1)
Note that "serial" has been renamed to "epoch" in newer RPM versions...Fotheringhay

© 2022 - 2024 — McMap. All rights reserved.