forked from briandfoy/rakudo-star-chocolatey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cook_templates
executable file
·119 lines (85 loc) · 2.81 KB
/
cook_templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!perl -s
use v5.24;
use vars qw($v $dry $U);
use feature qw(signatures);
no warnings qw(experimental::signatures);
use open qw(:std :utf8);
use Data::Dumper;
use File::Basename qw(dirname);
use File::Path qw(make_path);
use FindBin;
use XML::Entities;
=encoding utf8
=head1 NAME
cook_templates - fill in the details for the chocolatey files
=head1 SYNOPSIS
% perl5.24 cook_templates
# extra debugging stuff
% perl5.24 cook_templates -v
=head1 DESCRIPTION
Fetch the latest Rakudo Star release for Perl 6, extract various details,
and fill in the chocolatey files.
=back
=head1 SOURCE AVAILABILITY
This module is in Github:
https://github.com/briandfoy/rakudo-star-chocolatey
=head1 AUTHOR
brian d foy, C<< <[email protected]> >>
=head1 COPYRIGHT AND LICENSE
Copyright © 2017-2019, brian d foy C<< <[email protected]> >>. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the Artistic License 2. A LICENSE file should have accompanied
this distribution.
=cut
require "$FindBin::Bin/latest_rakudo_msi_details";
require "$FindBin::Bin/get_readme";
$ENV{LATEST_RAKUDO_MSI_UNLINK} = 0 if $U;
my $last_rakudo_details = latest_rakudo_msi_details::get_details();
say Dumper($last_rakudo_details) if $v;
my $readme_details = get_readme::get_readme_stuff();
say Dumper($readme_details) if $v;
$readme_details->{markdown_xml_escaped} = XML::Entities::numify( 'all', $readme_details->{markdown} );
my @templates = glob( 'templates/*.template templates/*/*.template' );
my $cooked_dir = 'cooked_templates';
make_path $cooked_dir;
foreach my $template ( @templates ) {
say "Cooking template $template";
my $data = do { local( @ARGV, $/ ) = $template; <> };
my $file = "cooked_$template";
$file =~ s/\.template$//;
my $dirname = dirname $file;
make_path $dirname;
open my $fh, '>:utf8', $file
or die "Could not open <cooked_$template>: $!";
$data =~ s/%%SHA256%%/$last_rakudo_details->{sha256}/g;
$data =~ s/%%VERSION%%/$last_rakudo_details->{version}/g;
$data =~ s/%%URL%%/$last_rakudo_details->{url}/g;
$data =~ s/%%README%%/$readme_details->{markdown_xml_escaped}/g;
print {$fh} $data;
close $fh;
}
#######################################################################
# Now do the choco stuff
{
my $choco = 'choco';
say "Now we'll try to automatically pack and push the update.";
say "This is a dry run and we won't push." if $dry;
unless( chdir $cooked_dir ) {
die "Could not change to $cooked_dir: $!\n";
}
{
my $rc = system $choco, 'pack';
say "result of pack was [$rc]";
if( $rc ) { die "pack seems to have failed. Aborting.\n" }
}
say "About to push. Haven't tried this live yet!";
unless( $dry ) {
my $rc = system $choco, 'push';
say "result of push was [$rc]";
if( $rc ) { die "push seems to have failed.\n" }
}
else {
say "Not pushing because this is a dry run.";
}
}
__END__