-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-packages
executable file
·67 lines (51 loc) · 1.87 KB
/
update-packages
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
#!/usr/bin/perl
use strict;
use warnings;
use 5.028;
use XML::Twig;
use HTTP::Tiny;
use JSON;
use Dir::Self;
chdir __DIR__;
my $twig = XML::Twig->new(pretty_print => 'indented');
$twig->parsefile('./packages.config');
my $http = HTTP::Tiny->new();
my %outdated;
for my $package ($twig->root->children) {
my %attrs = $package->{att}->%*;
my ($id, $version) = @attrs{qw(id version)};
my $nuget_url = "https://api.nuget.org/v3-flatcontainer/$id/index.json";
my $response = $http->get($nuget_url);
die "Failed to contact the nuget API for package $id" unless $response->{success};
my $json = $response->{content};
my @versions = decode_json($json)->{versions}->@*;
@versions = grep {!m/[a-zA-Z]/} @versions; # Only prerelease versions contain letters
my $latest = $versions[-1];
next if $latest eq $version;
$package->{att}->{version} = $latest;
$outdated{$id} = $latest;
say "Upgrading $id from $version to $latest";
}
$twig->print_to_file("./packages.config");
for my $proj (glob 'TIO-*.*proj') {
$twig->parsefile($proj);
for my $ItemGroup ($twig->root->children('ItemGroup')) {
for my $Reference ($ItemGroup->children('Reference')) {
my $HintPath = $Reference->first_child('HintPath');
next unless defined($HintPath);
my $path = "";
open my $pathfh, '>', \$path;
$HintPath->first_child->print($pathfh);
$path =~ m/^packages\\([^\\]+)/;
my $idver = $1;
my ($id, $ver) = $idver =~ m/(.+?)\.(\d.*)/;
next unless exists $outdated{$id};
$ver = $outdated{$id};
$idver = "$id.$ver";
$path =~ s/^.*?\\\K[^\\]+/$idver/;
$HintPath->set_inner_xml($path);
}
}
$twig->print_to_file($proj);
}
say "Finished upgrading " . scalar(%outdated) . " package(s).";