Git Auto Tagging With PHP Deployer

Adding a git tag when deploying is useful when tracking down issues in previous releases. You just need to create a relevant git tagging task, which would look something like this.

task('git:tag:push', function () {
  // Generate the tag, here we are using the current timestamp.
  $tag = date('d-m-Y-Hi');
  
  $tagOutput = runLocally("git tag " . $tag);
  writeln($tagOutput);
  
  $pushOutput = runLocally("git push origin " . $tag);
  writeln($pushOutput);
  info('Tag created.');
});

The $tag variable here is up to you. You could even get the current release name from the release history.

$tag = get('release_name');

Be careful when using this method as it can lead to duplicate tags on new hosts. This is easily fixed by changing the value in the file ".dep/latest_release" in your release server.

Then, it's just a case of adding this to your deploy tasks.

task('deploy', [
  'git:tag:push',
  // Etc...
]);

With this in place, the current state of the target branch is tagged before being released.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 14 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.