Automate the population of the windows exe metadata

This commit is contained in:
2022-05-01 17:39:00 +09:30
parent 243c349366
commit 9423bc32e9
4 changed files with 35 additions and 10 deletions

View File

@@ -2,17 +2,27 @@
use strict;
use warnings;
use Mojo::JSON qw/encode_json decode_json/;
use Mojo::File;
open my $fh, "<", "version/version.go" || die $!;
my $version;
while (<$fh>) {
$version = $1 if /^const\s+CurrentVersion.*?"(v[\d\.]+)"/;
$version = $1 if /^const\s+CurrentVersion.*?"v([\d\.]+)"/;
}
close $fh;
die "no version?" unless defined $version;
my @version_parts = split /\./, $version;
die "bad version?" unless defined $version_parts[2];
foreach (@version_parts) {
$_ = 0 + $_;
}
$version = "v$version";
# quit if tests fail
system("go test ./...") && die "not building release with failing tests";
@@ -42,6 +52,20 @@ foreach my $type (keys %build) {
my @ldflags = ();
if ($type eq "win") {
# create the versioninfo.json based on the current version
my $tmp = Mojo::File->new("versioninfo.json-template")->slurp();
my $vdata = decode_json($tmp);
$vdata->{FixedFileInfo}->{FileVersion}->{Major} = $version_parts[0] ;
$vdata->{FixedFileInfo}->{FileVersion}->{Minor} = $version_parts[1] ;
$vdata->{FixedFileInfo}->{FileVersion}->{Patch} = $version_parts[2] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Major} = $version_parts[0] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Minor} = $version_parts[1] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Patch} = $version_parts[2] ;
$vdata->{StringFileInfo}->{ProductVersion} = $version;
Mojo::File->new("versioninfo.json")->spurt(encode_json($vdata));
@ldflags = (qw/ -ldflags -H=windowsgui/);
system "go", "generate";
}