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

Last change on this file since 36214 was 36214, checked in by kjdon, 6 months ago

initial version of snapshot task. copied from bedrock. based on other-projects/nightly-tasks/snapshot. which I would like to get rid of eventually, and just have it living in here

  • Property svn:executable set to *
File size: 7.1 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#default identity dir
57if ( ! exists $ENV{'IDENTITY_DIR'} ) {
58 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
59}
60
61#choose the parameters of the build based on the task name
62if ( $ENV{'TASK_NAME'} =~ "release" ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
63 if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {
64 create_release($ARGV[0]);
65 exit;
66 } else {
67 die "Run snapshot task with gs<full-version>[rc#]\n";
68 }
69} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)/i ) {
70 if ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)-x64$/i ) {
71 # $ENV{'branch_path'} = "branches/64_bit_Greenstone";
72 $ENV{'x64'} = "true";
73 }
74 $major_version = 2;
75 $prefix="2s";
76 $rk="rk2";
77} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)/i ) {
78 if ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)-x64$/i ) {
79 # $ENV{'branch_path'} = "branches/64_bit_Greenstone";
80 $ENV{'x64'} = "true";
81 }
82 $major_version = 3;
83 $prefix="3s";
84 $rk="rk3";
85} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-src-(caveat|stable)$/i ) {
86 $major_version = 2;
87 $prefix="2s";
88 $rk="sork2";
89} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-src-(caveat|stable)$/i ) {
90 $major_version = 3;
91 $prefix="3s";
92 $rk="sork3";
93} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-cd-(caveat|stable)$/i ) {
94 $major_version = 2;
95 $prefix="2s";
96 $rk="cdrk2";
97} elsif ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)$/i ) {
98 $prefix="";
99 $rk="derk";
100} else {
101 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
102}
103
104#keep wget/curl base command in a variable
105my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget --no-check-certificate -O -";
106
107#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
108# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
109
110#setup based on mode
111if ( $ENV{'TASK_NAME'} =~ m/caveat/ ) {
112 $ENV{'SNAPSHOT_MODE'} = "caveat";
113
114 if ( $major_version == 2 ) {
115 $ENV{'snapshot_id2'} = `$httpRetrieve https://www.greenstone.org/next-release.txt`;
116 chomp($ENV{'snapshot_id2'});
117 } else {
118 $ENV{'snapshot_id3'} = `$httpRetrieve https://www.greenstone.org/next-release-greenstone3.txt`;
119 chomp($ENV{'snapshot_id3'});
120 }
121
122 #change the filenames to have the date in them
123 my $id2 = $ENV{'snapshot_id2'};
124 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
125
126 my $id3 = $ENV{'snapshot_id3'};
127 (my $id3re = $id3) =~ s@\.@\\.@g;
128
129 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
130 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
131 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
132
133 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
134 # 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
135
136 #set the path to server.exe
137 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/caveat-emptor/latest-server.exe";
138
139} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
140 $ENV{'SNAPSHOT_MODE'} = "stable";
141 $ENV{'BRANCH_PATH'} = "tags/stable";
142
143 #dont proceed if main/stable is old
144 #get last changed date from svn
145 open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
146 or die "Cant determine age of stable tag";
147 my $changed_date;
148 while ( my $line = <INFO>) {
149 chomp($line);
150 if ( $line =~ /^Last Changed Date:/ ) {
151 $changed_date = $line;
152 break;
153 }
154 }
155 close(INFO);
156 #change the format
157 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
158 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
159 die "Cant determine age of stable tag";
160 }
161 $changed_date =~ s/-/./g;
162 #check if main/stable is new
163 if ( $changed_date ne get_date() ) {
164 print "main/stable is old, will not create snapshot\n";
165 exit;
166 } else {
167 print "main/stable is fresh, will create snapshot\n";
168 }
169
170 #set the path to server.exe
171 $ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
172 #$ENV{'SERVER_EXE_LOCATION'} = "http://community.nzdl.org/gs3files/latest-server.exe";
173}
174
175#use the correct key for uploading
176$ENV{'IDENTITY_FILE'} =
177 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
178
179
180#always rename the log not to clash with other files on puka
181if ( $ENV{'x64'} ) {
182 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-x64-log.txt/";
183# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-x64-log.txt/";
184}
185else {
186 $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
187# $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
188}
189
190#choose a snapshot ID
191if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
192 $snapshot_id = $ENV{'snapshot_id2'};
193} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
194 $snapshot_id = $ENV{'snapshot_id3'};
195} else {
196 $snapshot_id = gen_snapshot_id($prefix);
197}
198
199#set a release directory
200$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
201
202print "creating a snapshot release\n";
203print "release id : $snapshot_id\n";
204print "release dir: $release_dir\n";
205
206if ( $action eq "create" ) {
207 create();
208} elsif ( $action eq "upload" ) {
209# emailing doesn't work as no SMTP setup on release-kit LSB machines
210# send_mail_on_releasekit_fail();
211 upload();
212} elsif ( $action eq "all" || !$action ) {
213 create();
214# emailing doesn't work as no SMTP setup on release-kit LSB machines
215# send_mail_on_releasekit_fail();
216 upload();
217} else {
218 die "bad snapshot action\n";
219}
220
Note: See TracBrowser for help on using the repository browser.