#! /usr/bin/env perl

use strict;
use warnings;
use File::Slurp;

my $tag = shift or die "Need a tag";

print "Building windows release of Tundra with tag \"$tag\":\n";
print " - Tundra-Setup-$tag.exe\n";
print " - Tundra-Binaries-$tag.zip\n";

system "make CROSSMINGW=yes installer windows-zip";
die "build failed" unless $? == 0;

for my $f (qw(Tundra-Setup.exe Tundra-Binaries.zip)) {
  die "build.mingw/$f missing" unless -f "build.mingw/$f";
}

my @server_names = ();
my @md5s = ();

for my $f (qw(Tundra-Setup.exe Tundra-Binaries.zip)) {
  my $mod_name = $f;
  $mod_name =~ s/^(.*)\.([^.]*)$/$1-$tag.$2/;
  push @server_names, $mod_name;
  my $md5 = `md5 build.mingw/$f`;
  ($md5) = ($md5 =~ /= ([A-Fa-f0-9]{32})\s*$/);
  chomp $md5;
  push @md5s, $md5;
  system "s3cmd put --acl-public build.mingw/$f s3://tundra2-builds/$mod_name\n";
  die "failed to upload $f" unless $? == 0;
}

my $base_uri = 'http://tundra2-builds.s3.amazonaws.com';
my $readme = read_file 'README.md';
my @now = localtime;
my $date = sprintf "%04d-%02d-%02d", $now[5] + 1900, $now[4] + 1, $now[3];
my $note =<<TEXT
- 2.0 $tag ($date)
  - [installer]($base_uri/$server_names[0]) MD5: \`$md5s[0]\`
  - [zip]($base_uri/$server_names[1]) MD5: \`$md5s[1]\`
TEXT
;

$readme =~ s/(Windows installers are available for download:\s*)/$1$note/;

open my $fh, '>', 'README.md';
print $fh $readme;
close $fh;

Add script to automate windows release publishing
Add script to automate windows release publishing
