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

Last change on this file since 34524 was 34524, checked in by ak19, 3 years ago

Correct Mac OS name in log file being uploaded

File size: 6.9 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 # e.g. https://en.wikipedia.org/wiki/MacOS_Mojave has darwin kernel version 18.7.0
29 # uname -r returns the major number. 18 in Mojave's example
30 if($osversion =~ m@^11@i) {
31 $osversion = "-Lion";
32 } elsif($osversion =~ m@^12@i) {
33 $osversion = "-Mountain-Lion";
34 } elsif($osversion =~ m@^13@i) {
35 $osversion = "-Mavericks"; # official name is not Maverick but Mavericks
36 } elsif($osversion =~ m@^14@i) {
37 $osversion = "-Yosemite";
38 } elsif($osversion =~ m@^15@i) {
39 $osversion = "-ElCapitan";
40 } elsif($osversion =~ m@^16@i) {
41 $osversion = "-Sierra";
42 } elsif($osversion =~ m@^17@i) {
43 $osversion = "-HighSierra";
44 } elsif($osversion =~ m@^18@i) {
45 # Running uname -v, shows that darwin kernel version = 18.7.0, which is Mojave
46 # see https://en.wikipedia.org/wiki/MacOS_Mojave
47 $osversion = "-Mojave";
48 }
49}
50
51# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
52my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
53
54if ( exists $ARGV[0] ) {
55 $action = $ARGV[0];
56}
57
58if ( exists $ARGV[1] ) {
59 die "too many arguments to snapshot task\n";
60}
61
62#default data dir
63if ( ! exists $ENV{'DATA_DIR'} ) {
64 $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
65}
66
67#default identity dir
68if ( ! exists $ENV{'IDENTITY_DIR'} ) {
69 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
70}
71
72#choose the parameters of the build based on the task name
73if ( $ENV{'TASK_NAME'} =~ "release" ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
74 if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {
75 create_release($ARGV[0]);
76 exit;
77 } else {
78 die "Run snapshot task with gs<full-version>[rc#]\n";
79 }
80} elsif ( $ENV{'TASK_NAME'} =~ "gs2-(caveat|stable)" ) {
81 $major_version = 2;
82 $prefix="2s";
83 $rk="rk2";
84} elsif ( $ENV{'TASK_NAME'} =~ "gs3-(caveat|stable)" ) {
85 $major_version = 3;
86 $prefix="3s";
87 $rk="rk3";
88} elsif ( $ENV{'TASK_NAME'} =~ "gs2-src-(caveat|stable)" ) {
89 $major_version = 2;
90 $prefix="2s";
91 $rk="sork2";
92} elsif ( $ENV{'TASK_NAME'} =~ "gs3-src-(caveat|stable)" ) {
93 $major_version = 3;
94 $prefix="3s";
95 $rk="sork3";
96} elsif ( $ENV{'TASK_NAME'} =~ "gs2-cd-(caveat|stable)" ) {
97 $major_version = 2;
98 $prefix="2s";
99 $rk="cdrk2";
100} elsif ( $ENV{'TASK_NAME'} =~ "dec-(caveat|stable)" ) {
101 $prefix="";
102 $rk="derk";
103} else {
104 die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
105}
106
107#keep wget/curl base command in a variable
108my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget -O -";
109
110#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
111# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
112
113#setup based on mode
114if ( $ENV{'TASK_NAME'} =~ "caveat\$" ) {
115 $ENV{'SNAPSHOT_MODE'} = "caveat";
116
117 if ( $major_version == 2 ) {
118 $ENV{'snapshot_id2'} = `$httpRetrieve http://www.greenstone.org/next-release.txt`;
119 chomp($ENV{'snapshot_id2'});
120 } else {
121 $ENV{'snapshot_id3'} = `$httpRetrieve http://www.greenstone.org/next-release-greenstone3.txt`;
122 chomp($ENV{'snapshot_id3'});
123 }
124
125 #change the filenames to have the date in them
126 my $id2 = $ENV{'snapshot_id2'};
127 (my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
128
129 my $id3 = $ENV{'snapshot_id3'};
130 (my $id3re = $id3) =~ s@\.@\\.@g;
131
132 print STDERR "SNAPSHOT ID: $id3\n";
133 print STDERR "SNAPSHOT ID RE: $id3re\n";
134
135 $ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
136 $ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
137 #$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";
138
139 # the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
140 # 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
141
142 #set the path to server.exe
143 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/latest-server.exe";
144
145} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
146 $ENV{'SNAPSHOT_MODE'} = "stable";
147 $ENV{'BRANCH_PATH'} = "tags/stable";
148
149 #dont proceed if main/stable is old
150 #get last changed date from svn
151 open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
152 or die "Cant determine age of stable tag";
153 my $changed_date;
154 while ( my $line = <INFO>) {
155 chomp($line);
156 if ( $line =~ /^Last Changed Date:/ ) {
157 $changed_date = $line;
158 break;
159 }
160 }
161 close(INFO);
162 #change the format
163 $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
164 if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
165 die "Cant determine age of stable tag";
166 }
167 $changed_date =~ s/-/./g;
168 #check if main/stable is new
169 if ( $changed_date ne get_date() ) {
170 print "main/stable is old, will not create snapshot\n";
171 exit;
172 } else {
173 print "main/stable is fresh, will create snapshot\n";
174 }
175
176 #set the path to server.exe
177 $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
178}
179
180#use the correct key for uploading
181$ENV{'IDENTITY_FILE'} =
182 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
183#use the correct key for uploading - ed25519 for www-internal
184$ENV{'IDENTITY_FILE_ED25519'} =
185 "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} ."-ed25519". ($^O eq "MSWin32" ? ".ppk" : "");
186
187
188#always rename the log not to clash with other files on puka
189$ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
190
191#choose a snapshot ID
192if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
193 $snapshot_id = $ENV{'snapshot_id2'};
194} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
195 $snapshot_id = $ENV{'snapshot_id3'};
196} else {
197 $snapshot_id = gen_snapshot_id($prefix);
198}
199
200#set a release directory
201$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
202
203print "creating a snapshot release\n";
204print "release id : $snapshot_id\n";
205print "release dir: $release_dir\n";
206
207if ( $action eq "create" ) {
208 create();
209} elsif ( $action eq "upload" ) {
210 upload();
211} elsif ( $action eq "all" || !$action ) {
212 create();
213 upload();
214} else {
215 die "bad snapshot action\n";
216}
217
Note: See TracBrowser for help on using the repository browser.