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

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

Dr Bainbridge fixed the dec regex problem and other regex issues.

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