-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathea4-tool-post-update
More file actions
executable file
·141 lines (100 loc) · 3.51 KB
/
ea4-tool-post-update
File metadata and controls
executable file
·141 lines (100 loc) · 3.51 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - ea4-tool-post-update Copyright(c) 2022 cPanel, L.L.C.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
package ea_nginx::ea4_tool_post_update;
use strict;
use warnings;
use lib "../ea-tools/lib/ea4_tool"; # assumes ea-tools is checked out next to this repo
use ea4_tool::cmd::change ();
use ea4_tool::cmd::list ();
use ea4_tool::cmd::obs ();
use ea4_tool::cmd::refresh ();
use ea4_tool::util ();
use File::chdir;
use Path::Tiny;
use Try::Tiny;
our $case;
exit( run(@ARGV) ? 0 : 1 ) if !caller;
sub run {
my ( $old_ver, $new_ver ) = @_;
_update_include_binary( $old_ver, $new_ver );
_update_nginx_module_pkgs($new_ver);
print "Done!\n";
return 1;
}
sub _update_include_binary {
my ( $old_ver, $new_ver ) = @_;
print "Update the include binary for debian to the newest sourceball version\n";
my $file = 'debify/debian/source/include-binaries';
my @lines = path($file)->lines;
foreach my $line (@lines) {
if ( $line =~ /\Q$old_ver\E/ ) {
$line =~ s/\Q$old_ver\E/$new_ver/;
}
}
path($file)->spew(@lines);
print "Committing change to $file …\n";
my $git = ea4_tool::util::git($CWD);
my $branch = $git->current_branch();
$git->run( add => $file );
$git->run( commit => "-m", "$branch: ea4-tool-post-update update include-binaries to new tarball" );
ea4_tool::util::pushup( $git, $branch );
return;
}
sub _update_nginx_module_pkgs {
my ($new_ver) = @_;
foreach my $repo ( ea4_tool::cmd::list::run() ) {
_check_if_repo_needs_update( $new_ver, $repo ) if $repo =~ m/nginx/;
}
return;
}
sub _check_if_repo_needs_update {
my ( $new_ver, $repo ) = @_;
# need to get the case before we start changing CWD
my $case = _get_case();
local $CWD = try {
ea4_tool::util::get_path_of_repo($repo);
}
catch {
ea4_tool::cmd::refresh::run();
ea4_tool::util::get_path_of_repo($repo);
};
my $spec = ea4_tool::util::specfile($CWD);
my @spec_lines = path($spec)->lines;
foreach my $line (@spec_lines) {
if ( $line =~ m/^\s*BuildRequires:\s+ea-nginx-ngxdev\s*$/ ) {
_update_repo( $new_ver, $repo, $case );
last;
}
}
return;
}
sub _get_case {
return $case if $case;
my $git = ea4_tool::util::git($CWD);
my $branch = $git->current_branch();
if ( $branch =~ m/^(.*)-ea-nginx$/ ) {
$case = $1;
}
die "Could not determine case" if !$case;
return $case;
}
sub _update_repo {
my ( $new_ver, $repo, $case ) = @_;
print "Updating “$repo” to show the version of nginx the module built against\n";
my $changelog = "Build against ea-nginx version v$new_ver";
ea4_tool::cmd::change::run( undef, $repo, $case, $changelog );
my $git = ea4_tool::util::git($CWD);
my $branch = $git->current_branch();
my $default = ea4_tool::util::git_default_branch($git);
ea4_tool::util::pushup( $git, $branch );
my $gitapi = ea4_tool::util::gitapi->new();
my $title = "$case: $changelog";
$gitapi->create_pull_request( $repo => $title, $branch => $default );
print "Build $repo in home directory\n";
ea4_tool::cmd::obs::run( undef, '--file-list-changed=0' );
return;
}
1;