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

Last change on this file since 28299 was 28299, checked in by ak19, 11 years ago

The changes needed to have the nightly snapshot task uploading successfully to the caveat from the Mountain Lion mac

File size: 5.3 KB
Line 
1use File::Basename;
2my $sep = $^O eq "MSWin32" ? "\\" : "/";
3do "$ENV{'TASK_HOME'}/lib.pl";
4
5die "Could not determine your operating system"
6 unless ( $^O =~ "linux|darwin|MSWin32" );
7
8#arguments
9our $action = "";
10
11#intervening variables
12our $prefix = "";
13our $release_dir = "";
14our $rk = "";
15our $snapshot_id = "";
16our $branch_path = "";
17our $major_version = 0;
18
19# for Darwin, specify if this binary is for (Mountain)Lions in the filename, otherwise it's for Leopards
20# http://en.wikipedia.org/wiki/Darwin_(operating_system)
21# darwin11* Lion, darwin12* Mountain Lion, darwin9* and darwin10* are Leopard and Snow Leopard
22my $osversion = "";
23if($^O eq "darwin") {
24 #$osversion=`uname -r | sed 's/\..*$//'`;
25 $osversion=`uname -r`; #$osversion =~ s@\..*$@@;
26 $osversion = ($osversion =~ m@^1[1-9]@i) ? "-Lion" : "";
27}
28
29# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
30my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
31
32if ( exists $ARGV[0] ) {
33 $action = $ARGV[0];
34}
35
36if ( exists $ARGV[1] ) {
37 die "too many arguments to snapshot task\n";
38}
39
40#default data dir
41if ( ! exists $ENV{'DATA_DIR'} ) {
42 $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
43}
44
45#default identity dir
46if ( ! exists $ENV{'IDENTITY_DIR'} ) {
47 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
48}
49
50#choose the parameters of the build based on the task name
51if ( $ENV{'TASK_NAME'} =~ "gs2-(caveat|stable)" ) {
52 $major_version = 2;
53 $prefix="2s";
54 $rk="rk2";
55} elsif ( $ENV{'TASK_NAME'} =~ "gs3-(caveat|stable)" ) {
56 $major_version = 3;
57 $prefix="3s";
58 $rk="rk3";
59} elsif ( $ENV{'TASK_NAME'} =~ "gs2-src-(caveat|stable)" ) {
60 $major_version = 2;
61 $prefix="2s";
62 $rk="sork2";
63} elsif ( $ENV{'TASK_NAME'} =~ "gs3-src-(caveat|stable)" ) {
64 $major_version = 3;
65 $prefix="3s";
66 $rk="sork3";
67} elsif ( $ENV{'TASK_NAME'} =~ "gs2-cd-(caveat|stable)" ) {
68 $major_version = 2;
69 $prefix="2s";
70 $rk="cdrk2";
71} elsif ( $ENV{'TASK_NAME'} =~ "dec-(caveat|stable)" ) {
72 $prefix="";
73 $rk="derk";
74} else {
75 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
76}
77
78#keep wget/curl base command in a variable
79my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget -O -";
80
81#setup based on mode
82if ( $ENV{'TASK_NAME'} =~ "caveat\$" ) {
83 $ENV{'SNAPSHOT_MODE'} = "caveat";
84
85 if ( $major_version == 2 ) {
86 $ENV{'snapshot_id2'} = `$httpRetrieve http://www.greenstone.org/next-release.txt`;
87 chomp($ENV{'snapshot_id2'});
88 } else {
89 $ENV{'snapshot_id3'} = `$httpRetrieve http://www.greenstone.org/next-release-greenstone3.txt`;
90 chomp($ENV{'snapshot_id3'});
91 }
92
93 #change the filenames to have the date in them
94 my $id2 = $ENV{'snapshot_id2'};
95 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
96
97 my $id3 = $ENV{'snapshot_id3'};
98 (my $id3re = $id3) =~ s@\.@\\.@g;
99
100 $ENV{'munges'} = "s/-$id2re/-$id2$osversion-candidate-" . get_date() . "/g " if ($id2 =~ m/\S/);
101 $ENV{'munges'} .= "s/-$id3re/-$id3$osversion-candidate-" . get_date() . "/g" if ($id3 =~ m/\S/);
102
103 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
104 # 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
105
106 #set the path to server.exe
107 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/latest-server.exe";
108
109} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
110 $ENV{'SNAPSHOT_MODE'} = "stable";
111 $ENV{'BRANCH_PATH'} = "tags/stable";
112
113 #dont proceed if main/stable is old
114 #get last changed date from svn
115 open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
116 or die "Cant determine age of stable tag";
117 my $changed_date;
118 while ( my $line = <INFO>) {
119 chomp($line);
120 if ( $line =~ /^Last Changed Date:/ ) {
121 $changed_date = $line;
122 break;
123 }
124 }
125 close(INFO);
126 #change the format
127 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
128 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
129 die "Cant determine age of stable tag";
130 }
131 $changed_date =~ s/-/./g;
132 #check if main/stable is new
133 if ( $changed_date ne get_date() ) {
134 print "main/stable is old, will not create snapshot\n";
135 exit;
136 } else {
137 print "main/stable is fresh, will create snapshot\n";
138 }
139
140 #set the path to server.exe
141 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
142}
143
144#use the correct key for uploading
145$ENV{'IDENTITY_FILE'} =
146 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
147
148
149#always rename the log not to clash with other files on puka
150$ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
151
152#choose a snapshot ID
153if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
154 $snapshot_id = $ENV{'snapshot_id2'};
155} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
156 $snapshot_id = $ENV{'snapshot_id3'};
157} else {
158 $snapshot_id = gen_snapshot_id($prefix);
159}
160
161#set a release directory
162$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
163
164print "creating a snapshot release\n";
165print "release id : $snapshot_id\n";
166print "release dir: $release_dir\n";
167
168if ( $action eq "create" ) {
169 create();
170} elsif ( $action eq "upload" ) {
171 upload();
172} elsif ( $action eq "all" || !$action ) {
173 create();
174 upload();
175} else {
176 die "bad snapshot action\n";
177}
178
Note: See TracBrowser for help on using the repository browser.