Upload stuff on git push when branch is not master

- Development, Resources

The first rule of optimization is: When something require many steps and can be automatized, do a script.

At least in my mind this my first rule and I do a script when I do the same things to many times.

For that reason I maintain a folder with scripts and different suite like this one.

Automatize help you to sleep better and be sure that everything will works in the same way across the time.

For my requirements of development I am improving our projects quality so I am using different tools for that.

One of them is PHPMetrics that we will take as example for this post.

The idea is to upload on our company VPS the report updated at the last commit of branches that are not master.

Git is helpful because can execute that not at every commit but also at every push to simplify the execution of this steps.

Using the pre-push hook our script will be execute on git push. For the documentation about it check on https://git-scm.com/book/uz/v2/Customizing-Git-Git-Hooks.

The script required to be put on .git/hook folder with execution permission inside your project.

You can find the snippet on https://gist.github.com/Mte90/f2786da09ed7a5dd5245376730e0a46a.

As you can see is pretty simple, check the branch, execute PHP Metrics connect to the VPS with ssh to upload the folder.

The only weak of that code is the use of password in clear but in this case was the most simple but of course there are many ways of to do it.

That’s all!

See you to the next post!

 

Liked it? Take a second to support Mte90 on Patreon!

Become a Patreon
All the stuff released in this website, where the author is Daniele Scasciafratte, is under the GPL 2.0 license except when the resources have their licenses.

Leave a Reply