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

Last change on this file since 21797 was 21797, checked in by oranfry, 14 years ago

imrpoved cross-platform compatibility, stopped using compression for upload, upload logs even if products dont exist and fixed log names to include OS

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