Shurik
Shurik

Reputation: 572

how to manage version file in git

I need to have the version file in my git repository.

I have release process (pipeline) that triggered manually when we decide to do release, this process should do:

  1. clone the repo
  2. run tests
  3. calculate the new version
  4. update the version file with new version
  5. commit and push the new version file
  6. create tag/branch in git with the new version

Now, when I will do clone from this tag, the version file should contains the correct version.

What happened if when the tests are running (#2) someone else commit changes to the repo, does the tag that generated in #6 will contains also the changes that not tested in release process?

Does the logic of this flow is correct, or I have better way to manage the version file?

Upvotes: 0

Views: 4390

Answers (1)

VonC
VonC

Reputation: 1328972

The version is not something stored statically, as a new revision of a file.
That is because the act of storing a new revision of that file means... the Git repository itself has a new commit, which needs to be fetch, and forces team members to merge or rebase their own work on top of that new commit.

The version is stored at build time, when building the deliverable.
For instance, in Go, you would use a flag pass to the Go linker in order to initialize a string variable.

That way, at runtime, the binary is able to produce not only the version, but any other build time information that you would chose to record.
I usually integrate that way:

  • the Git commit hash at the time of the build
  • a static version based on API changes
  • the user launching the build
  • the build date

That way, your program can display a lot of information about its build version.

Upvotes: 2

Related Questions