1

I want to add a version on my Laravel app automatically when some new code is pushed in any branch, preferably using the SemVer convention.

I have found packages such as https://github.com/antonioribeiro/version and though this does solve the issue of actually having a consistent versioning system, I cannot figure out a way to automate the process.

More specifically I would like the version to be bumped up whenever changes are pushed to the repo, and ideally this should have to be consistent across all branches.

Also I would like this solution to work across all developers in the team (so preferably no local config).

Currently I am using bitbucket for repo hosting and Laravel Forge for development.

I am thinking that Bitbucket Pipelines would be of use, but I cannot think how this would work. The main problem I have is that if I use bitbucket to up the version and then commit and push this automatically then that would trigger another circle of upping the version and so on.

So ideally I would like the following workflow:

  • Changes are commited
  • (App version bump) //This can happen here
  • New changes are pushed
  • (App version bump) //Or here

I might be overthinking it so has anyone been in the same situation/has any ideas?

Thanks

vasilaou
  • 35
  • 5

1 Answers1

1

You can use the library you mentioned. It provides a script for incrementing the semver version, which could be executed before each commit.

Install the dependency:

composer require pragmarx/version
php artisan vendor:publish --provider="PragmaRX\Version\Package\ServiceProvider"

Go into the created config/version.yml and set the mode to increment.

For example you could create a script .scripts/commit.sh like the following:

#!/bin/bash

php artisan version:patch
git add config/version.yml
git commit -m $1

When you are ready to commit, just add the files you want to push and call ./commit.sh "My commit message" and you are up a patch version.

You could extend that script for further use (e.g. implement a parameter of what part of the version should be incremented [major,minor,patch]) or make use of git-hooks.

  • Thanks @Tobias, that is useful. However I don't see how this can work among many different developers -unless of course they all use the same script. In this case though that means that there is no ability to select specific changes to commit. Any further ideas maybe? – vasilaou Nov 08 '21 at 14:11
  • Hey @vasilaou, I updated my answer to be a bit more precise. If you need a quick solution, this should work just fine, even with multiple developers. If you need a more advanced version, you should look in to the `pre-commit` hook of https://githooks.com/. – Tobias Dittmann Nov 08 '21 at 14:30
  • Hi @Tobias, this is really helpful now! Thanks! – vasilaou Nov 08 '21 at 14:57