1 | #!/usr/bin/perl |
---|
2 | # ------------------------------------------------------------------------------ |
---|
3 | # (C) Crown copyright Met Office. All rights reserved. |
---|
4 | # For further details please refer to the file COPYRIGHT.txt |
---|
5 | # which you should have received as part of this distribution. |
---|
6 | # ------------------------------------------------------------------------------ |
---|
7 | |
---|
8 | use strict; |
---|
9 | use warnings; |
---|
10 | |
---|
11 | use FindBin; |
---|
12 | use lib "$FindBin::Bin/../lib"; |
---|
13 | use Fcntl qw{:mode}; # for S_IXUSR, S_IXGRP, S_IXOTH, etc |
---|
14 | use File::Basename qw{dirname basename}; |
---|
15 | use File::Spec; |
---|
16 | use File::Temp qw{tempdir}; |
---|
17 | use FCM::Admin::Project; |
---|
18 | use FCM::Admin::Runner; |
---|
19 | use FCM::Admin::Util qw{ |
---|
20 | option2config |
---|
21 | run_create_archive |
---|
22 | run_html2pdf |
---|
23 | run_mkpath |
---|
24 | run_rename |
---|
25 | run_rmtree |
---|
26 | sed_file |
---|
27 | write_file |
---|
28 | }; |
---|
29 | use Getopt::Long qw{GetOptions}; |
---|
30 | use IO::Dir; |
---|
31 | use Pod::Usage qw{pod2usage}; |
---|
32 | use SVN::Client; |
---|
33 | |
---|
34 | main(); |
---|
35 | |
---|
36 | sub main { |
---|
37 | my %option = (); |
---|
38 | my $result = GetOptions( |
---|
39 | \%option, |
---|
40 | q{help|usage|h}, |
---|
41 | q{revision|r=s}, |
---|
42 | q{svn-live-dir=s}, |
---|
43 | q{svn-project-suffix=s}, |
---|
44 | ); |
---|
45 | if (!$result) { |
---|
46 | pod2usage(1); |
---|
47 | } |
---|
48 | if (exists($option{help})) { |
---|
49 | pod2usage(q{-verbose} => 1); |
---|
50 | } |
---|
51 | option2config(\%option); |
---|
52 | my $user_revision = exists($option{revision}) ? $option{revision} : q{HEAD}; |
---|
53 | if (@ARGV != 1) { |
---|
54 | my $message = sprintf( |
---|
55 | qq{Expected exactly 1 argument, %d given.}, scalar(@ARGV), |
---|
56 | ); |
---|
57 | pod2usage({q{-exitval} => 1, q{-message} => $message}); |
---|
58 | } |
---|
59 | my ($release_name) = @ARGV; |
---|
60 | my $out_file = "fcm-$release_name.tgz"; |
---|
61 | if (-e $out_file) { |
---|
62 | die("$out_file: already exists.\n"); |
---|
63 | } |
---|
64 | |
---|
65 | my $fcm_project = FCM::Admin::Project->new({name => q{FCM}}); |
---|
66 | my $fcm_repos_uri = $fcm_project->get_svn_file_uri(); |
---|
67 | my $revision = svn_info_revision($fcm_repos_uri, $user_revision); |
---|
68 | |
---|
69 | # Exports the trees of FCM and Admin to a temporary working area |
---|
70 | my $work_dir = tempdir(CLEANUP => 1); |
---|
71 | my $fcm_work_path = File::Spec->catfile($work_dir, q{fcm-} . $release_name); |
---|
72 | my $admin_work_path = File::Spec->catfile($work_dir, q{admin}); |
---|
73 | svn_export( |
---|
74 | join(q{/}, $fcm_repos_uri , qw{FCM trunk}), |
---|
75 | $fcm_work_path, |
---|
76 | $revision, |
---|
77 | ); |
---|
78 | svn_export( |
---|
79 | join(q{/}, $fcm_repos_uri , qw{Admin trunk}), |
---|
80 | $admin_work_path, |
---|
81 | $revision, |
---|
82 | ); |
---|
83 | |
---|
84 | manipulate_src_tree($fcm_work_path); |
---|
85 | manipulate_doc_tree($fcm_work_path); |
---|
86 | add_examples($fcm_work_path, $admin_work_path); |
---|
87 | add_tutorial(($fcm_work_path, $admin_work_path)); |
---|
88 | add_readme($fcm_work_path, $release_name, $revision); |
---|
89 | |
---|
90 | run_create_archive($out_file, $work_dir, basename($fcm_work_path)); |
---|
91 | } |
---|
92 | |
---|
93 | # ------------------------------------------------------------------------------ |
---|
94 | # Adds a README to the distribution. |
---|
95 | sub add_readme { |
---|
96 | my ($fcm_work_path, $release_name, $revision) = @_; |
---|
97 | write_file( |
---|
98 | File::Spec->catfile($fcm_work_path, q{README}), |
---|
99 | <<"README_FILE", |
---|
100 | FCM release $release_name created from revision $revision. |
---|
101 | |
---|
102 | For further details please refer to the release notes |
---|
103 | which can be found in the directory doc/release_notes. |
---|
104 | README_FILE |
---|
105 | ); |
---|
106 | } |
---|
107 | |
---|
108 | # ------------------------------------------------------------------------------ |
---|
109 | # Adds admin examples to the distribution. |
---|
110 | sub add_examples { |
---|
111 | my ($fcm_work_path, $admin_work_path) = @_; |
---|
112 | # Add utilities |
---|
113 | my $fcm_examples_path = File::Spec->catfile($fcm_work_path, qw{examples}); |
---|
114 | run_mkpath($fcm_examples_path); |
---|
115 | for my $path ( |
---|
116 | File::Spec->catfile($admin_work_path, qw{etc regular-update.eg}), |
---|
117 | glob(File::Spec->catfile($admin_work_path, qw{lib FCM*})), |
---|
118 | glob(File::Spec->catfile($admin_work_path, qw{sbin fcm-*})), |
---|
119 | ) { |
---|
120 | my $rel_path = File::Spec->abs2rel($path, $admin_work_path); |
---|
121 | my $new_path = File::Spec->catfile($fcm_examples_path, $rel_path); |
---|
122 | run_rename($path, $new_path); |
---|
123 | } |
---|
124 | |
---|
125 | # Add hooks |
---|
126 | my $fcm_example_hook_path |
---|
127 | = File::Spec->catfile($fcm_work_path, qw{examples svn-hooks}); |
---|
128 | my $admin_hook_path = File::Spec->catfile($admin_work_path, qw{svn-hooks}); |
---|
129 | run_mkpath($fcm_example_hook_path); |
---|
130 | for my $path (glob(File::Spec->catfile($admin_hook_path, q{*}))) { |
---|
131 | if (!-d $path) { |
---|
132 | my $new_path |
---|
133 | = File::Spec->catfile($fcm_example_hook_path, basename($path)); |
---|
134 | run_rename($path, $new_path); |
---|
135 | } |
---|
136 | } |
---|
137 | run_rename( |
---|
138 | File::Spec->catfile($admin_hook_path, qw{FCM background_updates.pl}), |
---|
139 | File::Spec->catfile($fcm_example_hook_path, q{background_updates.pl}), |
---|
140 | ); |
---|
141 | |
---|
142 | # Replaces FCM e-mail with an anonymous one |
---|
143 | for my $path ( |
---|
144 | glob(File::Spec->catfile($fcm_examples_path, qw{FCM Admin *})), |
---|
145 | glob(File::Spec->catfile($fcm_example_hook_path, q{*})), |
---|
146 | ) { |
---|
147 | sed_file( |
---|
148 | $path, |
---|
149 | sub { |
---|
150 | my ($line) = @_; |
---|
151 | $line =~ s{fcm\@metoffice\.gov\.uk} |
---|
152 | {my.name\@somewhere.org}gxms; |
---|
153 | return $line; |
---|
154 | }, |
---|
155 | ); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | # ------------------------------------------------------------------------------ |
---|
160 | # Adds the tutorial to the distribution. |
---|
161 | sub add_tutorial { |
---|
162 | my ($fcm_work_path, $admin_work_path) = @_; |
---|
163 | my $fcm_tutorial_path = File::Spec->catfile($fcm_work_path, q{tutorial}); |
---|
164 | my $admin_tutorial_path |
---|
165 | = File::Spec->catfile($admin_work_path, q{tutorial}); |
---|
166 | run_rename($admin_tutorial_path, $fcm_tutorial_path); |
---|
167 | my $admin_hook_tutorial_path |
---|
168 | = File::Spec->catfile($admin_work_path, qw{svn-hooks tutorial}); |
---|
169 | my $fcm_tutorial_hook_path |
---|
170 | = File::Spec->catfile($fcm_tutorial_path, q{hooks}); |
---|
171 | for my $path (glob(File::Spec->catfile($admin_hook_tutorial_path, q{*}))) { |
---|
172 | my $new_path |
---|
173 | = File::Spec->catfile($fcm_tutorial_hook_path, basename($path)); |
---|
174 | run_rename($path, $new_path); |
---|
175 | } |
---|
176 | my $fcm_example_svnperms_path = File::Spec->catfile( |
---|
177 | $fcm_work_path, qw{examples svn-hooks svnperms.py}, |
---|
178 | ); |
---|
179 | my $fcm_tutorial_svnperms_path |
---|
180 | = File::Spec->catfile($fcm_tutorial_hook_path, q{svnperms.py}); |
---|
181 | run_rename($fcm_example_svnperms_path, $fcm_tutorial_svnperms_path); |
---|
182 | } |
---|
183 | |
---|
184 | # ------------------------------------------------------------------------------ |
---|
185 | # Modifies the doc/ tree for the distribution. |
---|
186 | sub manipulate_doc_tree { |
---|
187 | my ($fcm_work_path) = @_; |
---|
188 | # Renames items in the documentation tree |
---|
189 | for my $path (glob(File::Spec->catfile($fcm_work_path, qw{doc * *.ppt}))) { |
---|
190 | run_rmtree($path); |
---|
191 | } |
---|
192 | sed_file( |
---|
193 | File::Spec->catfile($fcm_work_path, qw{doc etc fcm.js}), |
---|
194 | sub { |
---|
195 | my ($line) = @_; |
---|
196 | $line =~ s{\A(\s*URL_OF_TEAM:)\s*'.*',}{$1 null,}gxms; |
---|
197 | return $line; |
---|
198 | }, |
---|
199 | ); |
---|
200 | |
---|
201 | # Creates PDF versions of the documentations |
---|
202 | for ( |
---|
203 | [[qw{user_guide index.html} ], q{fcm-user-guide} ], |
---|
204 | [[qw{collaboration index.html} ], q{fcm-collaboration} ], |
---|
205 | [[qw{standards fortran_standard.html}], q{fcm-fortran-standard}], |
---|
206 | [[qw{standards perl_standard.html} ], q{fcm-perl-standard} ], |
---|
207 | ) { |
---|
208 | my ($html_path_ref, $pdf_name) = @{$_}; |
---|
209 | my $html_path |
---|
210 | = File::Spec->catfile($fcm_work_path, q{doc}, @{$html_path_ref}); |
---|
211 | my $pdf_path |
---|
212 | = File::Spec->catfile(dirname($html_path), "$pdf_name.pdf"); |
---|
213 | run_html2pdf($html_path, $pdf_path); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | # ------------------------------------------------------------------------------ |
---|
218 | # Modifies the src/ tree for the distribution. |
---|
219 | sub manipulate_src_tree { |
---|
220 | my ($fcm_work_path) = @_; |
---|
221 | run_rename( |
---|
222 | File::Spec->catfile($fcm_work_path, qw{etc fcm.cfg}), |
---|
223 | File::Spec->catfile($fcm_work_path, qw{etc fcm.cfg.eg}), |
---|
224 | ); |
---|
225 | } |
---|
226 | |
---|
227 | # ------------------------------------------------------------------------------ |
---|
228 | # Exports the Subversion URI "$from" (at $revision) to a path at "$to". |
---|
229 | sub svn_export { |
---|
230 | my ($from, $to, $revision) = @_; |
---|
231 | my $svn_client = SVN::Client->new(); |
---|
232 | FCM::Admin::Runner->instance()->run( |
---|
233 | "exporting $from to $to", |
---|
234 | sub {return $svn_client->export($from, $to, $revision, 0)}, |
---|
235 | ); |
---|
236 | } |
---|
237 | |
---|
238 | # ------------------------------------------------------------------------------ |
---|
239 | # Returns the actual revision of $svn_repos_uri (at a specified $user_revision). |
---|
240 | sub svn_info_revision { |
---|
241 | my ($svn_repos_uri, $user_revision) = @_; |
---|
242 | my $revision; |
---|
243 | my $svn_client = SVN::Client->new(); |
---|
244 | $svn_client->info( |
---|
245 | $svn_repos_uri, |
---|
246 | $user_revision, |
---|
247 | $user_revision, |
---|
248 | sub {$revision = $_[1]->rev()}, |
---|
249 | 1, |
---|
250 | ); |
---|
251 | if (!$revision) { |
---|
252 | die("$svn_repos_uri: cannot determine actual revision.\n"); |
---|
253 | } |
---|
254 | return $revision; |
---|
255 | } |
---|
256 | |
---|
257 | __END__ |
---|
258 | |
---|
259 | =head1 NAME |
---|
260 | |
---|
261 | fcm-create-release |
---|
262 | |
---|
263 | =head1 SYNOPSIS |
---|
264 | |
---|
265 | fcm-create-release [--revision=REV] RELEASE-NAME |
---|
266 | |
---|
267 | =head1 DESCRIPTION |
---|
268 | |
---|
269 | Creates a release of FCM in a compressed-tar ball. |
---|
270 | |
---|
271 | =head1 ARGUMENTS |
---|
272 | |
---|
273 | =over 4 |
---|
274 | |
---|
275 | =item RELEASE-NAME |
---|
276 | |
---|
277 | The name of the release |
---|
278 | |
---|
279 | =back |
---|
280 | |
---|
281 | =head1 OPTIONS |
---|
282 | |
---|
283 | =over 4 |
---|
284 | |
---|
285 | =item --help, -h, --usage |
---|
286 | |
---|
287 | Prints help and exits. |
---|
288 | |
---|
289 | =item --revision=REV, -rREV |
---|
290 | |
---|
291 | Specifies a revision of the trunk for creating the release. If not specified, |
---|
292 | the program uses the last commit revision at the HEAD of the trunk. |
---|
293 | |
---|
294 | =item --svn-live-dir=DIR |
---|
295 | |
---|
296 | Specifies the root location of the live directory of Subversion repositories. |
---|
297 | See L<FCM::Admin::Config|FCM::Admin::Config> for the current default. |
---|
298 | |
---|
299 | =item --svn-project-suffix=NAME |
---|
300 | |
---|
301 | Specifies the suffix added to the project name for Subversion repositories. The |
---|
302 | default is "_svn". |
---|
303 | |
---|
304 | =back |
---|
305 | |
---|
306 | =head1 SEE ALSO |
---|
307 | |
---|
308 | L<FCM::Admin::Config|FCM::Admin::Config>, |
---|
309 | L<FCM::Admin::Project|FCM::Admin::Project>, |
---|
310 | L<FCM::Admin::Runner|FCM::Admin::Runner>, |
---|
311 | L<FCM::Admin::Util|FCM::Admin::Util> |
---|
312 | |
---|
313 | =head1 COPYRIGHT |
---|
314 | |
---|
315 | E<169> Crown copyright Met Office. All rights reserved. |
---|
316 | |
---|
317 | =cut |
---|