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

Last change on this file since 37371 was 37371, checked in by kjdon, 16 months ago

allow dec-caveat-x64, and set the x64 envirnment var if needed

  • Property svn:executable set to *
File size: 6.8 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 if ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)-x64$/i ) {
92 print "setting env x64\n";
93 $ENV{'x64'} = "true";
94 }
95 $prefix="";
96 $rk="derk";
97} else {
98 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
99}
100
101#keep wget/curl base command in a variable
102my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget --no-check-certificate -O -";
103
104#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
105# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
106
107#setup based on mode
108if ( $ENV{'TASK_NAME'} =~ m/caveat/ ) {
109 $ENV{'SNAPSHOT_MODE'} = "caveat";
110
111 if ( $major_version == 2 ) {
112 $ENV{'snapshot_id2'} = `$httpRetrieve https://www.greenstone.org/next-release.txt`;
113 chomp($ENV{'snapshot_id2'});
114 } else {
115 $ENV{'snapshot_id3'} = `$httpRetrieve https://www.greenstone.org/next-release-greenstone3.txt`;
116 chomp($ENV{'snapshot_id3'});
117 }
118
119 #change the filenames to have the date in them
120 my $id2 = $ENV{'snapshot_id2'};
121 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
122
123 my $id3 = $ENV{'snapshot_id3'};
124 (my $id3re = $id3) =~ s@\.@\\.@g;
125
126 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
127 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
128 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
129
130 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
131 # 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
132
133 #set the path to server.exe
134 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/caveat-emptor/latest-server.exe";
135
136} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
137 $ENV{'SNAPSHOT_MODE'} = "stable";
138 $ENV{'BRANCH_PATH'} = "tags/stable";
139
140 #dont proceed if main/stable is old
141 #get last changed date from svn
142 open( INFO, "svn --non-interactive --trust-server-cert info https://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
143 or die "Cant determine age of stable tag";
144 my $changed_date;
145 while ( my $line = <INFO>) {
146 chomp($line);
147 if ( $line =~ /^Last Changed Date:/ ) {
148 $changed_date = $line;
149 break;
150 }
151 }
152 close(INFO);
153 #change the format
154 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
155 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
156 die "Cant determine age of stable tag";
157 }
158 $changed_date =~ s/-/./g;
159 #check if main/stable is new
160 if ( $changed_date ne get_date() ) {
161 print "main/stable is old, will not create snapshot\n";
162 exit;
163 } else {
164 print "main/stable is fresh, will create snapshot\n";
165 }
166
167 #set the path to server.exe
168 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
169}
170
171#always rename the log not to clash with other files on puka
172if ( $ENV{'x64'} ) {
173 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-x64-log.txt/";
174# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-x64-log.txt/";
175}
176else {
177 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
178# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
179}
180
181#choose a snapshot ID
182if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
183 $snapshot_id = $ENV{'snapshot_id2'};
184} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
185 $snapshot_id = $ENV{'snapshot_id3'};
186} else {
187 $snapshot_id = gen_snapshot_id($prefix);
188}
189
190#set a release directory
191$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
192
193print "creating a snapshot release\n";
194print "release id : $snapshot_id\n";
195print "release dir: $release_dir\n";
196
197if ( $action eq "create" ) {
198 create();
199} elsif ( $action eq "upload" ) {
200# emailing doesn't work as no SMTP setup on release-kit LSB machines
201# send_mail_on_releasekit_fail();
202 upload();
203} elsif ( $action eq "all" || !$action ) {
204 create();
205# emailing doesn't work as no SMTP setup on release-kit LSB machines
206# send_mail_on_releasekit_fail();
207 upload();
208} else {
209 die "bad snapshot action\n";
210}
211
Note: See TracBrowser for help on using the repository browser.