Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid keeping version number in source code?

Up to now we keep the version number of our python source code in setup.py.

This version gets increased after every successful ci run.

This means the version of central libraries get increased several times per day.

Since the version number is stored in a file in the git repo, every increase of the version number is a new commit.

This means roughly 50% of all commits are not made by humans, but by CI.

I have got the feeling, that we are on the wrong track. Maybe it is no good solution to keep the version number in ci.

How could we avoid the "useless" CI commits which just increase the version number?

How to avoid keeping version number in source code?

Update

We live without manual release since several years. We do not have a versioning scheme like MAJOR.MINOR. And we have not missed this in the past. I know that this does not work for all environments. But it works for my current environment.

We have a version number which looks like this: YEAR.MONTH.X

This means every commit which passes CI is a new release.

After reading the answers I realize: I need to asks myself: Do I have a version number at all? I think no. I have a build number. More is not needed in this context.

(thank you for the up-votes. Before asking this question I was sure that this question will get closed because people will think it is "unclear" or "too broad")

like image 238
guettli Avatar asked Mar 29 '19 11:03

guettli


People also ask

How do I manage version numbers in git?

Another solution can be to use the Git tags to automatically generate the version number. A script can find the closest tag starting with v such as v0. 1.2 and use the tag name as the version number plus the first n digits of the current commit ( v0. 1.2 (build 4acd21) ).

How do I keep git versioning?

Git can be enabled on a specific folder/directory on your file system to version files within that directory (including sub-directories). In git (and other version control systems) terms, this “tracked folder” is called a repository (which formally is a specific data structure storing versioning information).

How do I mention a version?

This is a common convention in open source software. However, if the pre-release version is for an existing software package (e.g. version 2.5), then an "a" or "alpha" may be appended to the version number. So the alpha version of the 2.5 release might be identified as 2.5a or 2.5.

How do developers keep track of their software version numbers?

Having intelligible version numbers is one of the easiest ways for developers to keep track of their software in the wild. However, having to maintain version numbers manually across multiple projects can be an annoying, error-prone process, especially if you’re trying to build and release often. So how can we automate this task away?

Do you have to maintain version numbers manually across multiple projects?

However, having to maintain version numbers manually across multiple projects can be an annoying, error-prone process, especially if you’re trying to build and release often. So how can we automate this task away?

How do I get the most recent version of my code?

On merge into your main branch, this will kick off some actions such as bumping the version number and deploying your code. Here’s a GitHub action to automatically get your most recent version, bump the patch number, tag it, and push the tag: Just throw that in .github/workflows/bump.yml and you’re done!

How do you determine the version number of an assembly?

Every assembly has the exact same version number The option to manually specify a version number (say for infrequent builds that I release to the general public) The option for VS to auto-generate a build number (say for frequent builds that are released to beta testers)


2 Answers

It is a common practice to keep a version number in the source code, there is nothing wrong in that.

You need to separate CI procedures to regular builds, release publishing and release deployment.

Regular builds: run daily or even after each commit, can include static code analysis and automatic tests, check if the code can be built at all. Regular builds should not change the version number.

Release publishing: can only be triggered by explicit manual action by release manager.
The trigger action could be tagging a commit with a new version number, new merge into the release branch, or just a commit that changes version number kept in a special file (e.g. pom.xml). Refer to git flow for example.
Release publishing assigns a new version number (either automatically or manually), commits it into the source code if necessary, builds a binary package with a new version and uploads it to the binary package repository (e.g. Nexus, devpi, local APT repository, Docker registry and so on).

Release deployment: another manually triggered action that takes a ready binary package from a package repository and installs it to the target environment (dev, QA / UAT / staging, part of production for canary deployments or to the whole production environment).

like image 85
void Avatar answered Sep 26 '22 03:09

void


Premises:

I assume these are the premises under which the solution is discussed.

  1. Currently version number is kept in a git-tracked source file, but you are OK to get rid of it.
  2. No one manually manages version number, nor triggers a release procedure, which includes: (a) increase version number, (b) build from source and (c) store the built result somewhere. These are taken cared by CI, and SHOULD remain that way.

Solution:

  1. Instead of writing to a source file and create new commit, CI simply tag the specific commit that passed CI check, then push the tag to remote repo.
  2. The build script should read the tag of current HEAD commit, and use it as the version number for publishing a release.
  3. Optionally, you might want to use git filter-branch to rewrite your existing git repo history, tag previous release commits for consistency, remove and stop tracking the version number source cile, then get rid of those CI commits.
like image 42
hackape Avatar answered Sep 23 '22 03:09

hackape