forked from openbmc/openbmc-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobump.pl
executable file
·120 lines (98 loc) · 3.34 KB
/
autobump.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
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
120
#!/usr/bin/env perl
# Contributors Listed Below - COPYRIGHT 2017
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
use strict;
use File::Basename qw/basename/;
my $metas_to_search = "meta-phosphor meta-openbmc-machines meta-openbmc-bsp";
my $master_project = "openbmc";
my $server = "https://gerrit.openbmc-project.xyz";
system("cd $master_project && git fetch origin && git checkout origin/master");
open(FILES, "cd $master_project && git grep -l -e \"_URI\" --and -e \"github\" -- $metas_to_search |");
my @to_update = ();
while(my $file = <FILES>)
{
chomp $file;
my $entry = {};
$entry->{FILE} = "$file";
$entry->{BRANCH} = "master";
open(FILE, "$master_project/$entry->{FILE}");
while(my $line = <FILE>)
{
chomp $line;
if ($line =~ m/SRCREV ?.*=/)
{
if ($line =~ m/"([0-9a-f]*)"/)
{
$entry->{SRCREV} = $1;
}
}
elsif ($line =~ m/_URI/ and $line =~ m/github.com\/$master_project\//)
{
$line =~ s/.*$master_project\//$master_project\//;
$line =~ s/"//g;
$line =~ s/\.git$//;
$entry->{SRC_URI} = $line;
print "$file : $line\n";
}
}
close FILE;
if (exists $entry->{SRC_URI} and exists $entry->{SRCREV})
{
push @to_update, $entry;
}
}
foreach my $entry (@to_update)
{
my $project = $entry->{SRC_URI};
$project =~ s/\//%2F/g;
my $revision =
`curl -s $server/projects/$project/branches/$entry->{BRANCH} | \
grep revision`;
if (not $revision =~ m/revision/)
{
next;
}
if ($revision =~ m/$entry->{SRCREV}/)
{
print "$entry->{SRC_URI} is up to date @ $entry->{SRCREV}\n";
next;
}
$revision =~ m/"([0-9a-f]*)"/;
$revision = $1;
print "$entry->{SRC_URI} needs to be updated\n";
print "\t$entry->{SRCREV} -> $revision\n";
my $changeId = `echo autobump $entry->{FILE} $entry->{SRCREV} $revision | git hash-object -t blob --stdin`;
chomp $changeId;
$changeId =~ s/[ \t]*//;
$changeId = "I$changeId";
my $change =
`curl -s $server/changes/$master_project%2F$master_project~$entry->{BRANCH}~$changeId | \
grep change_id`;
if ($change =~ m/$changeId/)
{
print "\t$changeId already present.\n";
next;
}
system("cd $master_project && git checkout origin/master --force &&".
" sed -i \"s/$entry->{SRCREV}/$revision/\" $entry->{FILE} &&".
" git add $entry->{FILE}");
open(COMMIT, "| cd $master_project && git commit -s -F -");
print COMMIT (basename $entry->{FILE}).": bump version\n";
print COMMIT "\n";
print COMMIT "Change-Id: $changeId\n";
close(COMMIT);
system("cd $master_project && git push origin HEAD:refs/for/master/autobump");
}