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

Last change on this file since 29347 was 29347, checked in by ak19, 10 years ago

Slight improvement to yesterday's commit. Now the rc# part of the release folder name is optional.

File size: 5.7 KB
RevLine 
[21709]1use File::Basename;
[21798]2my $sep = $^O eq "MSWin32" ? "\\" : "/";
[21709]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
[28299]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
[27676]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
[21709]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
[21723]40#default data dir
41if ( ! exists $ENV{'DATA_DIR'} ) {
[21798]42 $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
[21723]43}
44
[21774]45#default identity dir
46if ( ! exists $ENV{'IDENTITY_DIR'} ) {
[21798]47 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
[21774]48}
49
[21709]50#choose the parameters of the build based on the task name
[29346]51if ( $ENV{'TASK_NAME'} =~ "release" ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
[29347]52 if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {
[29346]53 create_release($ARGV[0]);
54 exit;
55 } else {
56 die "Run snapshot task with gs<full-version>[rc#]\n";
57 }
58} elsif ( $ENV{'TASK_NAME'} =~ "gs2-(caveat|stable)" ) {
[21709]59 $major_version = 2;
60 $prefix="2s";
61 $rk="rk2";
62} elsif ( $ENV{'TASK_NAME'} =~ "gs3-(caveat|stable)" ) {
63 $major_version = 3;
64 $prefix="3s";
65 $rk="rk3";
66} elsif ( $ENV{'TASK_NAME'} =~ "gs2-src-(caveat|stable)" ) {
67 $major_version = 2;
68 $prefix="2s";
69 $rk="sork2";
70} elsif ( $ENV{'TASK_NAME'} =~ "gs3-src-(caveat|stable)" ) {
71 $major_version = 3;
72 $prefix="3s";
73 $rk="sork3";
74} elsif ( $ENV{'TASK_NAME'} =~ "gs2-cd-(caveat|stable)" ) {
75 $major_version = 2;
76 $prefix="2s";
77 $rk="cdrk2";
78} elsif ( $ENV{'TASK_NAME'} =~ "dec-(caveat|stable)" ) {
79 $prefix="";
80 $rk="derk";
81} else {
82 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
83}
84
[21797]85#keep wget/curl base command in a variable
86my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget -O -";
87
[21709]88#setup based on mode
89if ( $ENV{'TASK_NAME'} =~ "caveat\$" ) {
[21774]90 $ENV{'SNAPSHOT_MODE'} = "caveat";
[21709]91
[21773]92 if ( $major_version == 2 ) {
[27662]93 $ENV{'snapshot_id2'} = `$httpRetrieve http://www.greenstone.org/next-release.txt`;
[21773]94 chomp($ENV{'snapshot_id2'});
95 } else {
[21797]96 $ENV{'snapshot_id3'} = `$httpRetrieve http://www.greenstone.org/next-release-greenstone3.txt`;
[21773]97 chomp($ENV{'snapshot_id3'});
98 }
99
[21709]100 #change the filenames to have the date in them
[27662]101 my $id2 = $ENV{'snapshot_id2'};
[28299]102 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
[27662]103
104 my $id3 = $ENV{'snapshot_id3'};
105 (my $id3re = $id3) =~ s@\.@\\.@g;
106
[28321]107 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
108 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
109 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
[27662]110
[27655]111 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
112 # 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
[21709]113
114 #set the path to server.exe
[22411]115 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/latest-server.exe";
[21709]116
[21774]117} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
118 $ENV{'SNAPSHOT_MODE'} = "stable";
119 $ENV{'BRANCH_PATH'} = "tags/stable";
[21723]120
[21774]121 #dont proceed if main/stable is old
122 #get last changed date from svn
123 open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
124 or die "Cant determine age of stable tag";
125 my $changed_date;
126 while ( my $line = <INFO>) {
127 chomp($line);
128 if ( $line =~ /^Last Changed Date:/ ) {
129 $changed_date = $line;
130 break;
[21723]131 }
[21709]132 }
[21774]133 close(INFO);
134 #change the format
135 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
136 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
137 die "Cant determine age of stable tag";
138 }
139 $changed_date =~ s/-/./g;
140 #check if main/stable is new
141 if ( $changed_date ne get_date() ) {
142 print "main/stable is old, will not create snapshot\n";
143 exit;
144 } else {
145 print "main/stable is fresh, will create snapshot\n";
146 }
[21709]147
148 #set the path to server.exe
149 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
150}
151
[21774]152#use the correct key for uploading
153$ENV{'IDENTITY_FILE'} =
[21798]154 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
[21774]155
156
[21709]157#always rename the log not to clash with other files on puka
[28299]158$ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
[21709]159
160#choose a snapshot ID
161if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
162 $snapshot_id = $ENV{'snapshot_id2'};
163} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
164 $snapshot_id = $ENV{'snapshot_id3'};
165} else {
166 $snapshot_id = gen_snapshot_id($prefix);
167}
168
169#set a release directory
[21798]170$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
[21709]171
172print "creating a snapshot release\n";
173print "release id : $snapshot_id\n";
174print "release dir: $release_dir\n";
175
176if ( $action eq "create" ) {
177 create();
178} elsif ( $action eq "upload" ) {
179 upload();
180} elsif ( $action eq "all" || !$action ) {
181 create();
182 upload();
183} else {
184 die "bad snapshot action\n";
185}
186
Note: See TracBrowser for help on using the repository browser.