source: other-projects/nightly-tasks/snapshot/trunk/lib.pl@ 28299

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

The changes needed to have the nightly snapshot task uploading successfully to the caveat from the Mountain Lion mac

File size: 3.2 KB
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 {
30
31 die "release_dir not set, cant create\n" unless $release_dir;
32
33 print "about to clean up old snapshots (Ctrl-C to cancel)";
34 local $| = 1;
35 for ( my $i=0; $i<5; $i++ ) {
36 print ".";
37 sleep 1;
38 }
39 $| = 0;
40
41 print "cleaning up previous snapshot\n";
42 local $release_parent = dirname($release_dir);
43 if ( $^O eq "MSWin32" ) {
44 system("rd /q /s \"$release_parent\"");
45 } else {
46 system("rm -rf \"$release_parent\"");
47 }
48
49 print "creating the release dir\n";
50 mkdir $release_parent or die "couldn't create release parent directory\n";
51 mkdir $release_dir or die "couldn't create release directory\n";
52
53 print "changing to the release dir\n";
54 chdir $release_dir;
55
56 #version property
57 print "setting up todays properties\n";
58 `echo version:$snapshot_id> $rk-build.properties`;
59
60 #processor propertylocal $| = 1;
61 if ( $^O eq "darwin" ) {
62 print "setting processor\n";
63 if ( `uname -p` eq "i386" ) {
64 `echo processor:intel>> $rk-build.properties`;
65 } elsif ( `uname -p` eq "powerpc" ) {
66 `echo processor:ppc>> $rk-build.properties`;
67 } else {
68 print "unable to determine processor type, using intel\n";
69 `echo processor:intel>> $rk-build.properties`;
70 }
71 }
72
73 #branch path property
74 if ( $ENV{'branch_path'} ) {
75 `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
76 }
77
78 #server.exe.location
79 if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
80 `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
81 }
82
83 print "creating the snapshot using $rk\n";
84 system( $rk );
85
86}
87
88sub upload {
89 print "uploading files\n";
90
91 my @munges = ();
92 if ( exists $ENV{'munges'} ) {
93 @munges = split(' ', $ENV{'munges'});
94 }
95
96 #copy products to a temporary folder, giving them their new names
97 if ( -d "$release_dir${sep}uploads" ) {
98 system( "rm -rf '$release_dir${sep}uploads'" );
99 }
100 mkdir "$release_dir${sep}uploads";
101
102 my @files;
103 if ( -d "$release_dir${sep}products" ) {
104 @files = <$release_dir${sep}products${sep}*>;
105 }
106 push( @files, "$release_dir${sep}$rk.out" );
107
108 for my $file ( @files ) {
109 if ( -e $file ) {
110 my $filename = basename($file);
111 #munge
112 for my $m ( @munges ) {
113 $doit="\$filename =~ $m"; eval "$doit";
114 }
115 #upload
116 print "Will upload '" . basename($file) . "' to '$filename'\n";
117 if( $^O =~ "linux|darwin" ) {
118 system("cp \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
119 }
120 else {
121 system("copy \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
122 }
123 }
124
125 }
126
127 my $command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
128 $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
129 $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
130 #print "$command\n";
131 system("$command");
132}
Note: See TracBrowser for help on using the repository browser.