How to increase version numbers in secure branches of GitHub?

I am looking for a good process to control the version number of my project when my main branch has GitHub branch protection.

In an ideal world, when you merged with the release branch, your continuous integration server ran its tests, and then automatically increased the version number of your project and returned back to your SCM system.

However, with branch protection, you cannot commit your branch without a Pull request, so you have catch-22 where your CI server cannot click on your secure branch when trying to update the version number.

I can come up with several works, all of which are optimal:

  • Lift the system so that your CI server makes a PR to update the version. I'm not sure that you can even do this with GitHub, but even so, two Pull requests are generated for each "real" PR, which is inconvenient.
  • Remove branch protection - now anyone can push something to the branches, and you must manage your developers using the manual process.
  • Update the version manually before requesting a migration. this is slightly better than # 2, but it opens the door for developers to make mistakes when choosing a new version number or merging the desired version number with the wrong branch.

I hope there are other options that I have not thought about.

We use Javascript and npm, but I believe that the problem is agnostic of the language, of course, the same problem will exist with Java and Maven, for example.

+7
github versioning
source share
1 answer

I used git tags to automate version control using Jenkins. Therefore, every time the task was completed, he occupied the last tag and increased it. Because tags are different from commits, adding a tag does not conflict with Branch protection.

 # get last tag last=$(git describe --abbrev=0 --tags) # increment and tag again git tag $(($last + 1)) git push origin $(($last + 1)) 

This script is for a simple integer version number, but you can follow semver if you want. This was for an Android project, so I added a gradle function that will output the last tag and will use it if for the version number when creating.

 /* * Gets the version name from the latest Git tag */ def getVersionName = { -> def stdout = new ByteArrayOutputStream() exec { commandLine 'git', 'describe', '--tags' standardOutput = stdout } return stdout.toString().trim() } 

I am sure you can use a similar setting with Javascript.

+1
source share

All Articles