source: other-projects/nightly-tasks/snapshot/trunk/task.pl

Last change on this file was 38170, checked in by anupama, 7 months ago

The task names that contain caveat aren't guaranteed to end on caveat suffix, as they can have a further minux-x64 suffix also.

File size: 8.6 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 # e.g. https://en.wikipedia.org/wiki/MacOS_Mojave has darwin kernel version 18.7.0
40 # uname -r returns the major number. 18 in Mojave's example
41 if($osversion =~ m@^11@i) {
42 $osversion = "-Lion";
43 } elsif($osversion =~ m@^12@i) {
44 $osversion = "-Mountain-Lion";
45 } elsif($osversion =~ m@^13@i) {
46 $osversion = "-Mavericks"; # official name is not Maverick but Mavericks
47 } elsif($osversion =~ m@^14@i) {
48 $osversion = "-Yosemite";
49 } elsif($osversion =~ m@^15@i) {
50 $osversion = "-ElCapitan";
51 } elsif($osversion =~ m@^16@i) {
52 $osversion = "-Sierra";
53 } elsif($osversion =~ m@^17@i) {
54 $osversion = "-HighSierra";
55 } elsif($osversion =~ m@^18@i) {
56 # Running uname -v, shows that darwin kernel version = 18.7.0, which is Mojave
57 # see https://en.wikipedia.org/wiki/MacOS_Mojave
58 $osversion = "-Mojave";
59 } elsif($osversion =~ m@^19@i) {
60 $osversion = "-Catalina";
61 } elsif($osversion =~ m@^20@i) {
62 $osversion = "-BigSur";
63 } elsif($osversion =~ m@^21@i) {
64 $osversion = "-Monterey";
65 }
66}
67
68# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
69my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
70
71if ( exists $ARGV[0] ) {
72 $action = $ARGV[0];
73}
74
75if ( exists $ARGV[1] ) {
76 die "too many arguments to snapshot task\n";
77}
78
79#default data dir
80if ( ! exists $ENV{'DATA_DIR'} ) {
81 $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
82}
83
84#default identity dir
85if ( ! exists $ENV{'IDENTITY_DIR'} ) {
86 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
87}
88
89#choose the parameters of the build based on the task name
90if ( $ENV{'TASK_NAME'} =~ m/release/ ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
91 if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {
92 create_release($ARGV[0]);
93 exit;
94 } else {
95 die "Run snapshot task with gs<full-version>[rc#]\n";
96 }
97} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)/i ) {
98 if ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)-x64$/i ) {
99 $ENV{'x64'} = "true";
100 }
101 $major_version = 2;
102 $prefix="2s";
103 $rk="rk2";
104} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)/i ) {
105 if ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)-x64$/i ) {
106 $ENV{'x64'} = "true";
107 }
108 $major_version = 3;
109 $prefix="3s";
110 $rk="rk3";
111} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-src-(caveat|stable)$/i ) {
112 $major_version = 2;
113 $prefix="2s";
114 $rk="sork2";
115} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-src-(caveat|stable)$/i ) {
116 $major_version = 3;
117 $prefix="3s";
118 $rk="sork3";
119} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-cd-(caveat|stable)$/i ) {
120 $major_version = 2;
121 $prefix="2s";
122 $rk="cdrk2";
123} elsif ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)/i ) {
124 if ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)-x64$/i ) {
125 print "setting env x64\n";
126 $ENV{'x64'} = "true";
127 }
128 $prefix="";
129 $rk="derk";
130} else {
131 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
132}
133
134#keep wget/curl base command in a variable
135my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget --no-check-certificate -O -";
136
137#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
138# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
139
140#setup based on mode
141if ( $ENV{'TASK_NAME'} =~ m/caveat/ ) {
142 $ENV{'SNAPSHOT_MODE'} = "caveat";
143
144 if ( $major_version == 2 ) {
145 $ENV{'snapshot_id2'} = `$httpRetrieve https://www.greenstone.org/next-release.txt`;
146 #HARDCODED DUE TO THE 32 BIT LSB ENVIRONMENT NOT HAVING WGET
147 #$ENV{'snapshot_id2'} = "2.88";
148 chomp($ENV{'snapshot_id2'});
149 } else {
150 $ENV{'snapshot_id3'} = `$httpRetrieve https://www.greenstone.org/next-release-greenstone3.txt`;
151 #HARDCODED DUE TO THE 32 BIT LSB ENVIRONMENT NOT HAVING WGET
152 #$ENV{'snapshot_id3'} = "3.10";
153 chomp($ENV{'snapshot_id3'});
154 }
155
156 #change the filenames to have the date in them
157 my $id2 = $ENV{'snapshot_id2'};
158 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
159
160 my $id3 = $ENV{'snapshot_id3'};
161 (my $id3re = $id3) =~ s@\.@\\.@g;
162
163 #print STDERR "SNAPSHOT ID: $id3\n";
164 #print STDERR "SNAPSHOT ID RE: $id3re\n";
165
166 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
167 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
168 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
169
170 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
171 # 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
172
173 #set the path to server.exe
174 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/caveat-emptor/latest-server.exe";
175
176} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
177 $ENV{'SNAPSHOT_MODE'} = "stable";
178 $ENV{'BRANCH_PATH'} = "tags/stable";
179
180 #dont proceed if main/stable is old
181 #get last changed date from svn
182 #open( INFO, "svn info https://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
183 open( INFO, "svn --non-interactive --trust-server-cert info https://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
184 or die "Cant determine age of stable tag";
185 my $changed_date;
186 while ( my $line = <INFO>) {
187 chomp($line);
188 if ( $line =~ /^Last Changed Date:/ ) {
189 $changed_date = $line;
190 break;
191 }
192 }
193 close(INFO);
194 #change the format
195 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
196 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
197 die "Can't determine age of stable tag";
198 }
199 $changed_date =~ s/-/./g;
200 #check if main/stable is new
201 if ( $changed_date ne get_date() ) {
202 print "main/stable is old, will not create snapshot\n";
203 exit;
204 } else {
205 print "main/stable is fresh, will create snapshot\n";
206 }
207
208 #set the path to server.exe
209 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
210}
211
212#use the correct key for uploading
213$ENV{'IDENTITY_FILE'} =
214 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
215#use the correct key for uploading - ed25519 for www-internal
216$ENV{'IDENTITY_FILE_ED25519'} =
217 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} ."-ed25519". ($^O eq "MSWin32" ? ".ppk" : "");
218
219
220#always rename the log not to clash with other files on puka
221if ( $ENV{'x64'} ) {
222 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-x64-log.txt/";
223# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-x64-log.txt/";
224}
225else {
226 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
227# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
228}
229
230#choose a snapshot ID
231if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
232 $snapshot_id = $ENV{'snapshot_id2'};
233} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
234 $snapshot_id = $ENV{'snapshot_id3'};
235} else {
236 $snapshot_id = gen_snapshot_id($prefix);
237}
238
239#set a release directory
240$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
241
242print "creating a snapshot release\n";
243print "release id : $snapshot_id\n";
244print "release dir: $release_dir\n";
245
246if ( $action eq "create" ) {
247 create();
248} elsif ( $action eq "upload" ) {
249# emailing doesn't work as no SMTP setup on release-kit LSB machines
250# send_mail_on_releasekit_fail();
251 upload();
252} elsif ( $action eq "all" || !$action ) {
253 create();
254# emailing doesn't work as no SMTP setup on release-kit LSB machines
255# send_mail_on_releasekit_fail();
256 upload();
257} else {
258 die "bad snapshot action\n";
259}
260
Note: See TracBrowser for help on using the repository browser.