Search code examples
githubdevopsversioningsemantic-versioning

Github Status Check for Versioning


Im trying to achieve the following scenario.

Our developers maintain a version.plist file in the repo. Lets consider master has version 1.1.1. (Follow semver 2.0 specs)

When a dev A works on a feature, he creates PR and updates version to 1.2.1. I would like a status check on the PR, to say whether the PR has the correct version to be merged to master.

I don't want a scenario where merge can happen if the version is same or lower than master.

Let us consider similarly another developer B also works on another feature and updates his version.plist to 1.2.1 also. He merges it to master and now master has ver 1.2.1.

I would like above status check to repeat the test and notify that the PR of Dev A to be unmergeable, even though previously it was okay to merge.

Can anyone suggest any guidelines on how to do this via Status API/Events API. This is on an organization GitHub integrated with azure pipelines.


Solution

  • You can use githooks to solve this use-case.

    • Make sure server side githooks are available on your git.
    • Use pre-merge-commit hook that will run prior to each merge.
    • Read the file names for current branch at $GIT_DIR.
    • Read the file names of master branch
    git ls-tree -r --name-only <branch>
    
    • Compare the file names.
    • The hook should exit with non-zero status after issuing an appropriate message to stderr if it wants to stop the merge commit.

    You might need to hardcode the read only git credentials.

    More details can be found here.