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

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

made the snapshot task work in windows

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