blob: bec2f82dbad1d420304db9d5efb62215d1c93a2f [file] [log] [blame]
Brad Bishopca5cd072017-10-31 14:51:48 -04001#!/usr/bin/env perl
2
3# Contributors Listed Below - COPYRIGHT 2017
4# [+] International Business Machines Corp.
5#
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16# implied. See the License for the specific language governing
17# permissions and limitations under the License.
18
19use strict;
20use File::Basename qw/basename/;
21
22my $metas_to_search = "meta-phosphor meta-openbmc-machines meta-openbmc-bsp";
23my $master_project = "openbmc";
24my $server = "https://gerrit.openbmc-project.xyz";
25
26system("cd $master_project && git fetch origin && git checkout origin/master");
27
28open(FILES, "cd $master_project && git grep -l -e \"_URI\" --and -e \"github\" -- $metas_to_search |");
29
30my @to_update = ();
31
32while(my $file = <FILES>)
33{
34 chomp $file;
35
36 my $entry = {};
37 $entry->{FILE} = "$file";
38 $entry->{BRANCH} = "master";
39
40 open(FILE, "$master_project/$entry->{FILE}");
41 while(my $line = <FILE>)
42 {
43 chomp $line;
44
45 if ($line =~ m/SRCREV ?.*=/)
46 {
47 if ($line =~ m/"([0-9a-f]*)"/)
48 {
49 $entry->{SRCREV} = $1;
50 }
51 }
52 elsif ($line =~ m/_URI/ and $line =~ m/github.com\/$master_project\//)
53 {
54 $line =~ s/.*$master_project\//$master_project\//;
55 $line =~ s/"//g;
56 $line =~ s/\.git$//;
57 $entry->{SRC_URI} = $line;
58 print "$file : $line\n";
59 }
60 }
61 close FILE;
62
63 if (exists $entry->{SRC_URI} and exists $entry->{SRCREV})
64 {
65 push @to_update, $entry;
66 }
67}
68
69foreach my $entry (@to_update)
70{
71 my $project = $entry->{SRC_URI};
72 $project =~ s/\//%2F/g;
73 my $revision =
74 `curl -s $server/projects/$project/branches/$entry->{BRANCH} | \
75 grep revision`;
76
77 if (not $revision =~ m/revision/)
78 {
79 next;
80 }
81 if ($revision =~ m/$entry->{SRCREV}/)
82 {
83 print "$entry->{SRC_URI} is up to date @ $entry->{SRCREV}\n";
84 next;
85 }
86
87 $revision =~ m/"([0-9a-f]*)"/;
88 $revision = $1;
89
90 print "$entry->{SRC_URI} needs to be updated\n";
91 print "\t$entry->{SRCREV} -> $revision\n";
92
93 my $changeId = `echo autobump $entry->{FILE} $entry->{SRCREV} $revision | git hash-object -t blob --stdin`;
94 chomp $changeId;
95 $changeId =~ s/[ \t]*//;
96 $changeId = "I$changeId";
97
98 my $change =
99 `curl -s $server/changes/$master_project%2F$master_project~$entry->{BRANCH}~$changeId | \
100 grep change_id`;
101
102 if ($change =~ m/$changeId/)
103 {
104 print "\t$changeId already present.\n";
105 next;
106 }
107
108 system("cd $master_project && git checkout origin/master --force &&".
109 " sed -i \"s/$entry->{SRCREV}/$revision/\" $entry->{FILE} &&".
110 " git add $entry->{FILE}");
111
112 open(COMMIT, "| cd $master_project && git commit -s -F -");
113 print COMMIT (basename $entry->{FILE}).": bump version\n";
114 print COMMIT "\n";
115 print COMMIT "Change-Id: $changeId\n";
116 close(COMMIT);
117
118 system("cd $master_project && git push origin HEAD:refs/for/master/autobump");
119
120}