-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-workflow.pl
executable file
·45 lines (36 loc) · 1.26 KB
/
update-workflow.pl
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
#!/usr/bin/env nix-shell
#! nix-shell -i perl -p perl538 -p perl538Packages.JSON -p perl538Packages.FileSlurp -p perl538Packages.DataDump -p perl538Packages.ModernPerl -p perl538Packages.TextSimpleTable
use Text::SimpleTable;
use Modern::Perl;
use feature qw(say postderef);
use File::Slurp;
use JSON;
my $json = JSON->new->utf8->pretty(1)->canonical(1)->allow_nonref;
my $file = '.github/workflows/main.yml';
my $x = read_file('sources.json');
my $sources = $json->decode($x);
my $f = read_file($file);
my $workflow = $json->decode($f);
$workflow->{jobs}->{build}->{strategy}->{matrix}->{version}->@* =
sort { $b cmp $a } map { $_->{package}->{name} } $sources->@*;
write_file( $file, $json->encode($workflow) );
sub update_readme() {
my $f = 'README.md';
my $c = read_file($f);
my @d = map { [ $_->{version} => $_ ] } sort { $b->{version} cmp $a->{version} } $sources->@*;
my $m = "|Version|Package|Date|\n";
$m.= "|---|---|---|\n";
for my $k ( @d ) {
$m.="|";
$m.= join "|", ($k->[0], "<b>" . $k->[1]->{package}->{name} . "</b>",
$k->[1]->{date} );
$m.="|\n";
}
$c =~ s{
(?<=\<\!--START--\>\R)
.*
(?=\<\!--END--\>\R)
}{$m}xgms;
write_file( $f, $c );
}
update_readme();