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

Last change on this file since 32048 was 32048, checked in by ak19, 7 years ago

Uploading a copy of snapshot binary to dev. (Also introducing a commented out debug line in task.pl)

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