Skip to content

Commit b5066b9

Browse files
committed
Add step to generate releases.json snippet
Integration with the releases.json file needs some hand-editing to provide the final URLs but this generates all the other details. Long-double and 64-bit int builds are unverified for now but the results can still be hand-edited before integration.
1 parent 4d88cd6 commit b5066b9

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package Perl::Dist::Strawberry::Step::OutputReleasesJSONSnippet;
2+
3+
use 5.012;
4+
use warnings;
5+
use base 'Perl::Dist::Strawberry::Step';
6+
7+
use Time::Piece;
8+
use JSON;
9+
10+
use File::Spec::Functions qw(catfile);
11+
12+
sub run {
13+
my $self = shift;
14+
15+
my $output_basename = $self->global->{output_basename} // 'perl-output';
16+
my $json_file = catfile($self->global->{output_dir}, "${output_basename}_releases_snippet.json.");
17+
18+
$self->boss->message(2, "gonna create '$json_file'");
19+
# backup already existing json_file;
20+
$self->backup_file($json_file);
21+
22+
use Data::Printer;
23+
#p $self;
24+
my $params = $self->global;
25+
#p $params;
26+
27+
my $app_version = $params->{app_version};
28+
my $bits = $params->{bits};
29+
30+
my $t = localtime();
31+
my $year = $t->year;
32+
my $month = $t->month;
33+
my $date_ymd = $t->strftime('%Y-%m-%d');
34+
35+
my $name = "$month $year / $app_version / ${bits}bit";
36+
my $archname = "MSWin32-x${bits}-multi-thread";
37+
# next two if-blocks are unverified as we have not built these types
38+
if ($params->{perl_64bitint}) {
39+
$name .= ' / with USE_64_BIT_INT';
40+
$archname .= '-64int';
41+
}
42+
if ($params->{perl_ldouble}) {
43+
$name .= ' / with USE_LONG_DOUBLE';
44+
$archname .= '-ld';
45+
}
46+
47+
# could use a map but it would be less readable
48+
my @v_parts = split /,/, $params->{app_rc_version};
49+
my $numver = $v_parts[0] + 1e-3 * $v_parts[1] + 1e-6 * $v_parts[2] + 1e-9 * $v_parts[3];
50+
51+
my @editions = grep {$_ =~ /^(zip|portable_zip|msi|pdl_zip)$/} keys %{$params->{output}};
52+
53+
my $edition_hash = {};
54+
EDITION:
55+
foreach my $edition (sort @editions) {
56+
my $f = $params->{output}{$edition};
57+
if (!$f or !-e $f) {
58+
warn "Unable to locate $edition output $f, cannot add to releases.json snippet.";
59+
next EDITION;
60+
}
61+
62+
my $size = -s $f;
63+
# could use a proper method...
64+
my $re_sep = qr|[/\\]|;
65+
my @path = split $re_sep, $f;
66+
my $basename = $path[-1];
67+
68+
my $hash = {
69+
sha1 => $params->{output}{"${edition}_sha1"} // $self->sha1_file($f),
70+
sha256 => $params->{output}{"${edition}_sha256"} // $self->sha256_file($f),
71+
size => $size,
72+
url => "__XXXXfixURL__ $basename",
73+
};
74+
$edition_hash->{$edition} = $hash;
75+
}
76+
77+
78+
#build snippet
79+
my $snippet = {
80+
archname => $archname,
81+
date => $date_ymd,
82+
edition => $edition_hash,
83+
name => $name,
84+
numver => $numver,
85+
relnotes => "__XXXXfixURL__ $params->{output_basename}.html",
86+
version => $app_version,
87+
};
88+
89+
#p $snippet;
90+
my $json_snippet = JSON->new->utf8->pretty->canonical->encode($snippet);
91+
open my $fh, '>', $json_file or die "Unable to open $json_file, $!";
92+
print {$fh} $json_snippet;
93+
$fh->close;
94+
95+
}
96+
97+
1;

0 commit comments

Comments
 (0)