Search code examples
gitjenkinszipbitbucketsoftware-distribution

How to add version information to a git repository which is distributed as ZIP archive?


I'm looking for best practices when it comes to adding version information to the content of a ZIP archive which is currently created from a git repository by bitbucket (the state of HEAD; git-related files are removed automatically).

The ZIP contains the git commit hash in the name of the top-level directory. However users of the ZIP are required to rename the directory after extracting it and might do so, even if they're not required to, so the version information is lost.

If there's no a bitbucket plugin the easiest approach would be to automate the versioning with Jenkins. It's trying to wrap my head around this, but I'm stuck at the logical loop that every commit creates a new version which creates a change in the version file which creates a new commit which creates a change which...


Solution

  • I think the Exporting Your Repository section might be what you're looking for.

    just change whatever you need in that top level file i.e your LAST_COMMIT file would only have the commit hash in it.

    $Format:%H
    

    and your .gitattributes file would be exactly the same:

    LAST_COMMIT export-subst
    

    there's a --remote flag for git-archive if you want to do it all in one shot but I haven't used it before.

    https://git-scm.com/docs/git-archive#Documentation/git-archive.txt---remoteltrepogt