Remove "More..." from info modal. Add current window location to OL problem contact...
[bookreader.git] / BookReaderIA / sendtoswarm.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 # CONFIGURE
7
8 # The location of the TestSwarm that you're going to run against.
9
10 my $SWARM = "http://dev01.sf.archive.org:8080";
11 my $SWARM_INJECT = "/js/inject.js";
12
13 # Your TestSwarm username.
14
15 my $USER = "testflip";
16
17 # Your authorization token.
18
19 # my $AUTH_TOKEN = "";
20 open(AUTHFILE, "/home/testflip/.testswarm");
21 my $AUTH_TOKEN = <AUTHFILE>;
22 chomp($AUTH_TOKEN);
23
24 # The maximum number of times you want the tests to be run.
25
26 my $MAX_RUNS = 5;
27
28 # The type of revision control system being used.
29 # Currently "svn" or "git" are supported.
30
31 my $RCS_TYPE = "git";
32
33 # The URL from which a copy will be checked out.
34
35 my $RCS_URL = "/home/testflip/bookreader/.git";
36
37 # The directory in which the checkouts will occur.
38
39 my $BASE_DIR = "/home/testflip/public_html/changeset";
40
41 # A script tag loading in the TestSwarm injection script will
42 # be added at the bottom of the <head> in the following file.
43
44 my $INJECT_FILE = "BookReaderIA/test/index.html";
45
46 # Any build commands that need to happen.
47
48 my $BUILD = "(cd BookReaderIA; make test)";
49
50 # The name of the job that will be submitted
51 # (pick a descriptive, but short, name to make it easy to search)
52
53 # Note: The string {REV} will be replaced with the current
54 #       commit number/hash.
55
56 my $JOB_NAME = "BookReader www-testflip #{REV}";
57
58 # The browsers you wish to run against. Options include:
59 #  - "all" all available browsers.
60 #  - "popular" the most popular browser (99%+ of all browsers in use)
61 #  - "current" the current release of all the major browsers
62 #  - "gbs" the browsers currently supported in Yahoo's Graded Browser Support
63 #  - "beta" upcoming alpha/beta of popular browsers
64 #  - "popularbeta" the most popular browser and their upcoming releases
65
66 my $BROWSERS = "popularbeta";
67
68 # All the suites that you wish to run within this job
69 # (can be any number of suites)
70
71 #my %SUITES = ('first' => 'http://test.archive.org/changeset/{REV}/test/index.html');
72 my %SUITES = ();
73
74 # Comment these out if you wish to define a custom set of SUITES above
75 #my $SUITE = "http://dev.jquery.com/~john/changeset/{REV}";
76 my $SUITE = "http://home.us.archive.org/~testflip/changeset/{REV}/BookReaderIA";
77 sub BUILD_SUITES {
78         %SUITES = map { /(\w+).js$/; $1 => "$SUITE/test/?$1%20module"; } glob("BookReaderIA/test/unit/*.js");
79 }
80
81 ########### NO NEED TO CONFIGURE BELOW HERE ############
82
83 my $DEBUG = 1;
84 my $curdate = time;
85 my $co_dir = "tmp-$curdate";
86
87 print "chdir $BASE_DIR\n" if ( $DEBUG );
88 chdir( $BASE_DIR );
89
90 # Check out a specific revision
91 if ( $RCS_TYPE eq "svn" ) {
92         print "svn co $RCS_URL $co_dir\n" if ( $DEBUG );
93         `svn co $RCS_URL $co_dir`;
94 } elsif ( $RCS_TYPE eq "git" ) {
95         print "git clone $RCS_URL $co_dir\n" if ( $DEBUG );
96         `git clone $RCS_URL $co_dir`;
97 }
98
99 if ( ! -e $co_dir ) {
100         die "Problem checking out source.";
101 }
102
103 print "chdir $co_dir\n" if ( $DEBUG );
104 chdir( $co_dir );
105
106 my $rev;
107
108 # Figure out the revision of the checkout
109 if ( $RCS_TYPE eq "svn" ) {
110         print "svn info | grep Revision\n" if ( $DEBUG );
111         $rev = `svn info | grep Revision`;
112         $rev =~ s/Revision: //;
113 } elsif ( $RCS_TYPE eq "git" ) {
114     my $cmd = "git rev-parse --short HEAD";
115     print "$cmd\n" if ( $DEBUG );
116     $rev = `$cmd`;
117 }
118
119 $rev =~ s/\s*//g;
120
121 print "Revision: $rev\n" if ( $DEBUG );
122
123 if ( ! $rev ) {
124         remove_tmp();
125         die "Revision information not found.";
126
127 } elsif ( ! -e "../$rev" ) {
128         print "chdir $BASE_DIR\n" if ( $DEBUG );
129         chdir( $BASE_DIR );
130
131         print "rename $co_dir $rev\n" if ( $DEBUG );
132         rename( $co_dir, $rev );
133
134         print "chdir $rev\n" if ( $DEBUG );
135         chdir ( $rev );
136
137         if ( $BUILD ) {
138                 print "$BUILD\n" if ( $DEBUG );
139                 `$BUILD`;
140         }
141
142         if ( exists &BUILD_SUITES ) {
143                 &BUILD_SUITES();
144         }
145
146         foreach my $file ( glob($INJECT_FILE) ) {
147                 my $inject_file = `cat $file`;
148
149                 # Inject the TestSwarm injection script into the test suite
150                 $inject_file =~ s/<\/head>/<script>document.write("<scr" + "ipt src='$SWARM$SWARM_INJECT?" + (new Date).getTime() + "'><\/scr" + "ipt>");<\/script><\/head>/;
151
152                 open( my $fh, '>', $file ) or die "$file : $!";
153                 print $fh $inject_file;
154                 close( $fh );
155         }
156
157         my %props = (
158                 "state" => "addjob",
159                 "output" => "dump",
160                 "user" => $USER,
161                 "max" => $MAX_RUNS,
162                 "job_name" => $JOB_NAME,
163                 "browsers" => $BROWSERS,
164                 "auth" => $AUTH_TOKEN
165         );
166
167         my $query = "";
168
169         foreach my $prop ( keys %props ) {
170                 $query .= ($query ? "&" : "") . $prop . "=" . clean($props{$prop});
171         }
172
173         foreach my $suite ( sort keys %SUITES ) {
174                 $query .= "&suites[]=" . clean($suite) .
175                           "&urls[]=" . clean($SUITES{$suite});
176         }
177
178         print "curl -d \"$query\" $SWARM\n" if ( $DEBUG );
179         my $results = `curl -d "$query" $SWARM`;
180
181         print "Results: $results\n" if ( $DEBUG );
182
183         if ( $results ) {
184                 open( my $fh, '>', "results.txt" ) or die "$rev/results.txt : $!";
185                 print $fh "$SWARM$results";
186                 close( $fh );
187
188         } else {
189                 die "Job not submitted properly.";
190         }
191
192 # Otherwise, give up and clean up
193 } else {
194         remove_tmp();
195 }
196
197 sub remove_tmp {
198         chdir( $BASE_DIR );
199         `rm -rf $co_dir`;
200 }
201
202 sub clean {
203   my $str = shift;
204         $str =~ s/{REV}/$rev/g;
205         $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
206         $str;
207 }