Skip to content

Instantly share code, notes, and snippets.

@hongster
Last active April 12, 2019 07:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongster/242e6202d206f1d65eb8 to your computer and use it in GitHub Desktop.
Save hongster/242e6202d206f1d65eb8 to your computer and use it in GitHub Desktop.
Generating build number from git branch name and commit count.
<?php
/**
* Generate a build number based on Git commit count and current branch.
* @return string Format: "{$branch}.{$commitCount}"
*/
public function buildNumber()
{
$branch = exec('git rev-parse --abbrev-ref HEAD');
$commitCount = exec('git rev-list HEAD --count');
return "{$branch}.{$commitCount}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment