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

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

Envi passes an extra arg, the env_verbosity, to all tasks now. It's passed in as the first parameter. So the diffcol and snapshot tasks have to take it into account

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