Latest git hash needs to be speicified in installer's name

188 Views Asked by At

Consider a situation in which Git is installed in Windows and is available only in Git Bash, not Windows cmd environment. Having a vdproj to create installer for an application, but need to intercalate the latest git hash to the MSI package's name. For example, at the moment it produces: Behnama.msi But we need it to produce: Behnama_49ee23d3b33ba0fa5ce0ac128f50ed00345e9ce3.msi The hash 49ee... is what in top when I enter 'git log' in Git Bash. When a new commit is created, then come and build the vdproj, I want the hash to be changed in the name of the msi file.

3

There are 3 best solutions below

0
On

A solution is to install ActivePerl or any perl binary to be able to run perl scripts. Then run it as a post build event. This perl script may obtain the hash I want:

$folder = '';
while (! -d "$folder.git") {
    $folder .= '../';
}
open IF, "$folder.git/logs/HEAD" or die $!;
while (<IF>) {
    s/\s+$//;
    $lastline = $_ if $_;
}
close IF;
@ar = split /\s+/, $lastline;
print "$ar[1]\n";

The last statement might be something like this:

rename("Behnama.msi", "Behnama_$ar[1].msi");

instead.

4
On

VDPROJ isn't MSBuild based so it can't do that much. Your best bet would be to have a postbuild command that renamed Product.msi to Product_%SHA%.msi.

6
On

You need a few steps

  1. Get the last git commit ID
  2. Write the ID to a wxi-file
  3. Include the wxi-file to original wxs-file
  4. Use the value as variable

For 1) you can use git log -1 --pretty=format:"%h" (short hash) or git log -1 --pretty=format:"%H" (long hash) to get the last commit id.

For 2) On a Windows System type git log -1 --pretty=format:"%H" > gitLastCommit.wxi to store the last commit as a wxi-file. HINT: You need to wrap the simple ID with<include><?define mylastGitCommit = "VALUE OF COMMT ID" ?></include>

For 3) Add a similar line <?include .\gitLastCommit.wxi ?> to your wxs file.

For 4) Use the defined variable $(var.mylastGitCommit) in your wxs file where it is needed