source: main/trunk/gs-release-builder/envi/etc/tasks/snapshot/task.pl@ 37345

Last change on this file since 37345 was 37345, checked in by kjdon, 14 months ago

use --non-interactive and --trust-server-cert options to svn so that we don't need to manually accept the certificate every 3 months (and which causes the build to fail when it hasn't been done)

  • Property svn:executable set to *
File size: 6.7 KB
Line 
1use File::Basename;
2#use Mail::Sendmail;
3
4
5my $sep = $^O eq "MSWin32" ? "\\" : "/";
6do "$ENV{'TASK_HOME'}/lib.pl";
7
8die "Could not determine your operating system"
9 unless ( $^O =~ "linux|darwin|MSWin32" );
10
11#arguments
12our $action = "";
13
14#intervening variables
15our $prefix = "";
16our $release_dir = "";
17our $rk = "";
18our $snapshot_id = "";
19our $branch_path = "";
20our $major_version = 0;
21
22
23# SET THIS EMAIL SO THAT WE MAY BE INFORMED WHEN A BUILD FAILS
24$ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
25if(!defined $ENV{'MONITOR_EMAIL'}) {
26 die "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
27}
28
29
30# for Darwin, specify if this binary is for (Mountain)Lions in the filename, otherwise it's for Leopards
31# http://en.wikipedia.org/wiki/Darwin_(operating_system)
32# darwin11* Lion, darwin12* Mountain Lion, darwin9* and darwin10* are Leopard and Snow Leopard
33my $osversion = "";
34if($^O eq "darwin") {
35 #$osversion=`uname -r | sed 's/\..*$//'`;
36 $osversion=`uname -r`; #$osversion =~ s@\..*$@@;
37 $osversion = ($osversion =~ m@^1[1-9]@i) ? "-Lion" : "";
38}
39
40# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
41my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
42
43if ( exists $ARGV[0] ) {
44 $action = $ARGV[0];
45}
46
47if ( exists $ARGV[1] ) {
48 die "too many arguments to snapshot task\n";
49}
50
51#default data dir
52if ( ! exists $ENV{'DATA_DIR'} ) {
53 $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
54}
55
56#choose the parameters of the build based on the task name
57if ( $ENV{'TASK_NAME'} =~ "release" ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
58 if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {
59 create_release($ARGV[0]);
60 exit;
61 } else {
62 die "Run snapshot task with gs<full-version>[rc#]\n";
63 }
64} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)/i ) {
65 if ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)-x64$/i ) {
66 $ENV{'x64'} = "true";
67 }
68 $major_version = 2;
69 $prefix="2s";
70 $rk="rk2";
71} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)/i ) {
72 if ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)-x64$/i ) {
73 $ENV{'x64'} = "true";
74 }
75 $major_version = 3;
76 $prefix="3s";
77 $rk="rk3";
78} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-src-(caveat|stable)$/i ) {
79 $major_version = 2;
80 $prefix="2s";
81 $rk="sork2";
82} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-src-(caveat|stable)$/i ) {
83 $major_version = 3;
84 $prefix="3s";
85 $rk="sork3";
86} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-cd-(caveat|stable)$/i ) {
87 $major_version = 2;
88 $prefix="2s";
89 $rk="cdrk2";
90} elsif ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)$/i ) {
91 $prefix="";
92 $rk="derk";
93} else {
94 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
95}
96
97#keep wget/curl base command in a variable
98my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget --no-check-certificate -O -";
99
100#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
101# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
102
103#setup based on mode
104if ( $ENV{'TASK_NAME'} =~ m/caveat/ ) {
105 $ENV{'SNAPSHOT_MODE'} = "caveat";
106
107 if ( $major_version == 2 ) {
108 $ENV{'snapshot_id2'} = `$httpRetrieve https://www.greenstone.org/next-release.txt`;
109 chomp($ENV{'snapshot_id2'});
110 } else {
111 $ENV{'snapshot_id3'} = `$httpRetrieve https://www.greenstone.org/next-release-greenstone3.txt`;
112 chomp($ENV{'snapshot_id3'});
113 }
114
115 #change the filenames to have the date in them
116 my $id2 = $ENV{'snapshot_id2'};
117 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
118
119 my $id3 = $ENV{'snapshot_id3'};
120 (my $id3re = $id3) =~ s@\.@\\.@g;
121
122 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
123 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
124 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
125
126 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
127 # Greenstone-documented-examples-2013.06.18.tar.gz gets changed to Greenstone-documented-examples-2013.06-candidate-<daterepeat of 2013.06.18>.18.tar.gz
128
129 #set the path to server.exe
130 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/caveat-emptor/latest-server.exe";
131
132} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
133 $ENV{'SNAPSHOT_MODE'} = "stable";
134 $ENV{'BRANCH_PATH'} = "tags/stable";
135
136 #dont proceed if main/stable is old
137 #get last changed date from svn
138 open( INFO, "svn --non-interactive --trust-server-cert info https://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
139 or die "Cant determine age of stable tag";
140 my $changed_date;
141 while ( my $line = <INFO>) {
142 chomp($line);
143 if ( $line =~ /^Last Changed Date:/ ) {
144 $changed_date = $line;
145 break;
146 }
147 }
148 close(INFO);
149 #change the format
150 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
151 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
152 die "Cant determine age of stable tag";
153 }
154 $changed_date =~ s/-/./g;
155 #check if main/stable is new
156 if ( $changed_date ne get_date() ) {
157 print "main/stable is old, will not create snapshot\n";
158 exit;
159 } else {
160 print "main/stable is fresh, will create snapshot\n";
161 }
162
163 #set the path to server.exe
164 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
165}
166
167#always rename the log not to clash with other files on puka
168if ( $ENV{'x64'} ) {
169 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-x64-log.txt/";
170# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-x64-log.txt/";
171}
172else {
173 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
174# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
175}
176
177#choose a snapshot ID
178if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
179 $snapshot_id = $ENV{'snapshot_id2'};
180} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
181 $snapshot_id = $ENV{'snapshot_id3'};
182} else {
183 $snapshot_id = gen_snapshot_id($prefix);
184}
185
186#set a release directory
187$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
188
189print "creating a snapshot release\n";
190print "release id : $snapshot_id\n";
191print "release dir: $release_dir\n";
192
193if ( $action eq "create" ) {
194 create();
195} elsif ( $action eq "upload" ) {
196# emailing doesn't work as no SMTP setup on release-kit LSB machines
197# send_mail_on_releasekit_fail();
198 upload();
199} elsif ( $action eq "all" || !$action ) {
200 create();
201# emailing doesn't work as no SMTP setup on release-kit LSB machines
202# send_mail_on_releasekit_fail();
203 upload();
204} else {
205 die "bad snapshot action\n";
206}
207
Note: See TracBrowser for help on using the repository browser.