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

Get the version number using git tags #128

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

nbelakovski
Copy link
Contributor

This lets us avoid having a hardcoded file in the repo and having to update it for a release. This way releases can be done simply by tagging the appropriate commit and rebuilding.

This will be useful for when we publish packages, since it lets us publish a package every time we run CI and not have it conflict with or overwrite the latest package.

@jschueller
Copy link
Collaborator

jschueller commented Dec 26, 2023

this will fail on windows or if we build from the github tarball
maybe try this ?
https://github.com/antoniovazquezblanco/cmake-gitversiondetect/blob/main/GitVersionDetect.cmake

@nbelakovski
Copy link
Contributor Author

It works on Windows, I specifically modified the code so that it would. Why would we build from the github tarball?

@zaikunzhang
Copy link
Member

@nbelakovski, thank you for proposing this. Ping me when both you and @jschueller think it is ready.

@jschueller
Copy link
Collaborator

it wont work on windows without bash support, why not call directly the git command from cmake instead ?

@jschueller
Copy link
Collaborator

also it should work from the tarball, macports already uses it, and so will linux distro usually

CMakeLists.txt Fixed Show fixed Hide fixed
@nbelakovski nbelakovski force-pushed the use_git_describe branch 2 times, most recently from f26e901 to cebf464 Compare December 28, 2023 07:45
@nbelakovski
Copy link
Contributor Author

I changed it to use git describe so that it's not necessary to use a bash script. I had actually initially wanted to use it, but I think I didn't like the default output and so I wanted to make my own but long story short I'd rather keep things simple.

I also learned about export-subst in this process, which lets you write a file in such a way that git archive will substitute certain placeholders in the file with git information, and can even include the output of describe. This should solve the macports case.

I validated that the .git-archival.txt file is set up correctly by performing the following actions on my machine (I obtained the githash from going into the actions and looking at the output of the clone repository action):

$ curl -L https://api.github.com/repos/libprima/prima/tarball/9a0485ea -o myarchive.tgz
$ tar xzf myarchive.tgz
$ cd libprima-prima-9a0485e
$ cat .git-archival.txt
v0.7.2-162-g9a0485ea5

Note that the above commands will return a blank output on forked repos since they do not copy tags by default.

CMakeLists.txt Outdated Show resolved Hide resolved
This lets us avoid having a hardcoded file in the repo and having to
update it for a release. This way releases can be done simply by
tagging the appropriate commit and rebuilding.

This will be useful for when we publish packages, since it lets us publish
a package every time we run CI and not have it conflict with or overwrite
the latest package.
@zaikunzhang
Copy link
Member

Hi @nbelakovski and @jschueller , is the PR ready? Thank you.

@zaikunzhang zaikunzhang merged commit c3196b7 into libprima:main Jan 2, 2024
35 checks passed
@nbelakovski nbelakovski deleted the use_git_describe branch January 5, 2024 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants