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

Last change on this file since 37770 was 37770, checked in by anupama, 12 months ago

Some modifications to the snapshots envi task (lib.pl and task.pl) that were made when the uploading Mac Monterey's rk3 caveat and rk3 to www-internal finally worked. This is one of several related commits

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