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

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

Fix for an idiosyncracy dependent on this month's date (2013.06.) matching the regex substitution for the current gs3 version of 3.06.

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