This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upgrade
executable file
·86 lines (65 loc) · 2 KB
/
upgrade
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
#!/usr/bin/perl
# eg upgrade.perl 6.0.0 5.11.0 4.4.3 0.12.13
# clean start
system("git", "checkout", "master");
system("git", "reset", "--hard");
my @types = ("", "base-");
foreach my $rootversion (@ARGV) {
foreach my $buildtype (@types) {
my $version="${buildtype}${rootversion}";
print "\nUpdating to ${version}\n\n";
system("git", "checkout", "-b", $version);
system("sed", "-i", "", "s|alpine.node:6\.0\.0|alpine-node:${version}|", "Dockerfile");
system("git", "commit", "-a", "-m", "Upgrade to ${version}");
my @tags = get_tags($rootversion, $buildtype);
print "\nTagging ${version} as @tags\n\n";
foreach my $tag (@tags) {
system("git", "tag", "-a", $tag, "-m", "Upgrade to ${version}", "-f");
}
system("git", "checkout", "master");
system("git", "branch", "-d", "-f", $version);
print "${version}\n";
}
}
sub get_tags {
local $rootversion = shift;
local $buildtype = shift;
local @existing_tags = `git tag | grep -v 'latest\|base'`;
$rootversion =~ /^(\d+)\.(\d+)\.(\d+)/;
local $major = $1;
local $minor = $2;
local $patch = $3;
local $is_latest = 1;
local $is_new_major = 1;
local $is_new_minor = 1;
local @new_tags = ("${buildtype}${rootversion}");
foreach my $t (@existing_tags) {
$t =~ /^(\d+)\.(\d+)\.(\d+)/;
local $existing_major = $1;
local $existing_minor = $2;
local $existing_patch = $3;
# test version here
if ($major < $existing_major) {
$is_latest = 0;
}
if ($major == $existing_major && $minor < $existing_minor) {
$is_latest = 0;
$is_new_major = 0;
}
if ($major == $existing_major && $minor == $existing_minor && $patch < $existing_patch) {
$is_latest = 0;
$is_new_major = 0;
$is_new_minor = 0;
}
}
if ($is_latest) {
push @new_tags, "${buildtype}latest";
}
if ($is_new_major) {
push @new_tags, "${buildtype}${major}";
}
if ($is_new_minor) {
push @new_tags, "${buildtype}${major}.${minor}";
}
return @new_tags;
}