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

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

In the filename for the mac binaries, we now indicate that it's a dmg for a Lion after the date instead of before

File size: 5.4 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-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
101 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
102 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
103
104 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
105 # 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
106
107 #set the path to server.exe
108 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/latest-server.exe";
109
110} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
111 $ENV{'SNAPSHOT_MODE'} = "stable";
112 $ENV{'BRANCH_PATH'} = "tags/stable";
113
114 #dont proceed if main/stable is old
115 #get last changed date from svn
116 open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
117 or die "Cant determine age of stable tag";
118 my $changed_date;
119 while ( my $line = <INFO>) {
120 chomp($line);
121 if ( $line =~ /^Last Changed Date:/ ) {
122 $changed_date = $line;
123 break;
124 }
125 }
126 close(INFO);
127 #change the format
128 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
129 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
130 die "Cant determine age of stable tag";
131 }
132 $changed_date =~ s/-/./g;
133 #check if main/stable is new
134 if ( $changed_date ne get_date() ) {
135 print "main/stable is old, will not create snapshot\n";
136 exit;
137 } else {
138 print "main/stable is fresh, will create snapshot\n";
139 }
140
141 #set the path to server.exe
142 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
143}
144
145#use the correct key for uploading
146$ENV{'IDENTITY_FILE'} =
147 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
148
149
150#always rename the log not to clash with other files on puka
151$ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
152
153#choose a snapshot ID
154if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
155 $snapshot_id = $ENV{'snapshot_id2'};
156} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
157 $snapshot_id = $ENV{'snapshot_id3'};
158} else {
159 $snapshot_id = gen_snapshot_id($prefix);
160}
161
162#set a release directory
163$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
164
165print "creating a snapshot release\n";
166print "release id : $snapshot_id\n";
167print "release dir: $release_dir\n";
168
169if ( $action eq "create" ) {
170 create();
171} elsif ( $action eq "upload" ) {
172 upload();
173} elsif ( $action eq "all" || !$action ) {
174 create();
175 upload();
176} else {
177 die "bad snapshot action\n";
178}
179
Note: See TracBrowser for help on using the repository browser.