root/other-projects/nightly-tasks/snapshot/trunk/lib.pl @ 29346

Revision 29346, 5.7 KB (checked in by ak19, 5 years ago)

Creating release binaries and not just nightly caveat binaries using envi from now on. Needed because a GS3 release bin generated on windows could not successfully build the lucene demo collection whereas in the caveat it was properly built. Caveat uses envi and release binary process doesn't. And since only the caveats are tested against the tutorials and not release binaries, we want them to go through an identical binary-generation process and have an identical environment when generated. Tested on Windows.

Line 
1my $sep = $^O eq "MSWin32" ? "\\" : "/";
2
3sub get_date {
4    local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
5    local $day = $mday;
6    local $month = $mon+1;
7    local $year = $year+1900;
8    if ( length $month == 1 ) {
9        $month = join( "", "0", $month);
10    }
11    if ( length $day== 1 ) {
12        $day = join( "", "0", $day );
13    }
14    local $date = join( ".", $year,$month,$day );
15    return $date;
16}
17
18sub gen_snapshot_id {
19    if ( exists $_[0] && exists $_[1] ) {
20        return $_[0] . get_date() . $_[1];
21    }
22
23    if ( exists $_[0] ) {
24        return $_[0] . get_date();
25    }
26    return get_date();
27}
28
29sub create_release {
30
31    die "Must provide parameter to create_release\n" unless (exists $_[0]);
32   
33    my $release_folder_name = $_[0];
34    my $release_dir = "$ENV{'DATA_DIR'}${sep}$release_folder_name";     
35   
36    my $release_version = $release_folder_name;
37    $release_version =~ s/^gs-?//;
38    $release_version =~ s/rc\d$//;
39    my $major_version = $release_version;
40    $major_version =~ s/^(3|2).*/$1/;   
41    $release_version =~ s/^($major_version)\.?(\d*).*/$1.$2/;
42    my $rk = "rk".$major_version;
43   
44    my $release_version_extra;
45    if ($release_folder_name =~ m/(rc\d)$/) {
46        $release_version_extra = $1;
47    }
48    if ($release_folder_name !~ m/^gs/) { # prefix gs
49        $release_folder_name = "gs".$release_folder_name;
50    }
51   
52    print "major_version: $major_version\n";
53    print "version: $release_version\n";
54    print "versionextra: $release_version_extra\n";
55    print "release_folder_name: $release_folder_name\n";   
56   
57    print "about to clean up old snapshots (Ctrl-C to cancel)";
58    local $| = 1;
59    for ( my $i=0; $i<5; $i++ ) {
60        print ".";
61        sleep 1;
62    }
63    $| = 0;
64
65    print "cleaning up previous release snapshot $release_dir\n";
66   
67    if(-d $release_dir) {
68        if ( $^O eq "MSWin32" ) {
69            system("rd /q /s \"$release_dir\"");
70        } else {
71            system("rm -rf \"$release_dir\"");
72        }
73    }
74       
75    print "creating the release dir\n";
76    mkdir $release_dir or die "couldn't create release directory\n";
77
78    print "changing to the release dir\n";
79    chdir $release_dir;
80
81    #version property
82    print "setting up todays properties\n";
83    `echo version:$release_version> $rk-build.properties`;
84
85    if($release_version_extra) {
86        `echo version-extra:$release_version_extra>> $rk-build.properties`;
87    }   
88   
89    #processor propertylocal $| = 1;
90    if ( $^O eq "darwin" ) {
91        print "setting processor\n";
92        if ( `uname -p` eq "i386" ) {
93            `echo processor:intel>> $rk-build.properties`;
94        } elsif ( `uname -p` eq "powerpc" ) {
95            `echo processor:ppc>> $rk-build.properties`;
96        } else {
97            print "unable to determine processor type, using intel\n";
98            `echo processor:intel>> $rk-build.properties`;
99        }
100    } elsif ( $^O eq "linux" ) {
101        if(`uname -m` =~ m/64$/) {
102            print "Setting linux architecture to 64 bit";
103            `echo x64:true>> $rk-build.properties`;
104        }       
105    }
106
107    #branch path property
108    if ( $ENV{'branch_path'} ) {
109        `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
110    }
111
112    #server.exe.location
113    if ( $major_version eq "2" && exists $ENV{'SERVER_EXE_LOCATION'} ) {
114        `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
115    }
116
117    print "creating the snapshot using $rk\n";
118    system( $rk );
119}
120
121sub create {
122   
123    die "release_dir not set, cant create\n" unless $release_dir;
124
125    print "about to clean up old snapshots (Ctrl-C to cancel)";
126    local $| = 1;
127    for ( my $i=0; $i<5; $i++ ) {
128        print ".";
129        sleep 1;
130    }
131    $| = 0;
132
133    print "cleaning up previous snapshot\n";
134    local $release_parent = dirname($release_dir);
135    if ( $^O eq "MSWin32" ) {
136        system("rd /q /s \"$release_parent\"");
137    } else {
138        system("rm -rf \"$release_parent\"");
139    }
140
141    print "creating the release dir\n";
142    mkdir $release_parent or die "couldn't create release parent directory\n";
143    mkdir $release_dir or die "couldn't create release directory\n";
144
145    print "changing to the release dir\n";
146    chdir $release_dir;
147
148    #version property
149    print "setting up todays properties\n";
150    `echo version:$snapshot_id> $rk-build.properties`;
151
152    #processor propertylocal $| = 1;
153    if ( $^O eq "darwin" ) {
154        print "setting processor\n";
155        if ( `uname -p` eq "i386" ) {
156            `echo processor:intel>> $rk-build.properties`;
157        } elsif ( `uname -p` eq "powerpc" ) {
158            `echo processor:ppc>> $rk-build.properties`;
159        } else {
160            print "unable to determine processor type, using intel\n";
161            `echo processor:intel>> $rk-build.properties`;
162        }
163    }
164
165    #branch path property
166    if ( $ENV{'branch_path'} ) {
167        `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
168    }
169
170    #server.exe.location
171    if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
172        `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
173    }
174
175    print "creating the snapshot using $rk\n";
176    system( $rk );
177
178}
179
180sub upload {
181    print "uploading files\n";
182
183    my @munges = ();
184    if ( exists $ENV{'munges'} ) {
185        @munges = split(' ', $ENV{'munges'});
186    }
187
188    #copy products to a temporary folder, giving them their new names
189    if ( -d "$release_dir${sep}uploads" ) {
190        system( "rm -rf '$release_dir${sep}uploads'" );
191    }
192    mkdir "$release_dir${sep}uploads";
193
194    my @files;
195    if ( -d "$release_dir${sep}products" ) {
196        @files = <$release_dir${sep}products${sep}*>;
197    }
198    push( @files, "$release_dir${sep}$rk.out" );
199
200    for my $file ( @files ) {
201        if ( -e $file ) {
202            my $filename = basename($file);
203            #munge
204            for my $m ( @munges ) {
205                $doit="\$filename =~ $m"; eval "$doit";
206            }
207            #upload
208            print "Will upload '" . basename($file) . "' to '$filename'\n";
209            if( $^O =~ "linux|darwin" ) {
210                system("cp \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
211            }
212            else {
213                system("copy \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
214            }
215        }
216
217    }
218
219    my $command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
220    $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
221    $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
222    #print "$command\n";
223    system("$command");
224}
Note: See TracBrowser for help on using the browser.