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.
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
Git is helpful because can execute that not at every commit but also at every push to simplify the execution of this steps.
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.
See you to the next post!