Skip to content

Commit f1e7475

Browse files
committed
Serve build status images to docs site
1 parent 0303b9f commit f1e7475

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
_site
3-
.DS_Store
3+
.DS_Store
4+
*.pyc

Diff for: app.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
application: polymer-project
2-
version: 20130822
2+
version: 20130829
33
runtime: python27
44
api_version: 1
55
threadsafe: yes
66

77
#default_expiration: "0s"
88

9+
libraries:
10+
- name: PIL
11+
version: latest
12+
913
handlers:
1014

1115
# Top-level URLs ---------------------------------------------------------------
1216
- url: /$
1317
static_files: _site/index.html
1418
upload: _site/index\.html
1519

20+
- url: /build/(.*)
21+
script: build.application
22+
1623
- url: /polymer.min.js
1724
static_files: js/polymer.min.js
1825
upload: js/polymer\.min\.js

Diff for: build.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import urllib, urllib2
2+
import json
3+
4+
from PIL import Image, ImageDraw
5+
import StringIO
6+
7+
import webapp2
8+
9+
PLATFORMS_ALL = ['Mac', 'Linux', 'Win']
10+
11+
12+
class BuildStatusHandler(webapp2.RequestHandler):
13+
14+
def get_last_build(self, project, platform):
15+
url = 'http://build.chromium.org/p/client.polymer/json/builders/' + urllib.quote('%s %s' % (project, platform)) + '/builds/-1'
16+
return json.load(urllib2.urlopen(url))
17+
18+
def last_build_is_successful(self, project, platform, browser):
19+
success = True
20+
build = self.get_last_build(project, platform)
21+
foundTest = False
22+
for step in build['steps']:
23+
if foundTest:
24+
if step['results'][0] != 0:
25+
if browser == 'all' or step['text'][0].find(browser) != -1:
26+
success = False
27+
break
28+
elif step['name'] == 'test':
29+
if step['results'][0] != 0:
30+
success = False
31+
break
32+
else:
33+
foundTest = True
34+
return success
35+
36+
def get(self, project, platform='all', browser='all'):
37+
success = True
38+
if platform == 'all':
39+
for plat in PLATFORMS_ALL:
40+
if not self.last_build_is_successful(project, plat, browser):
41+
success = False
42+
break
43+
else:
44+
success = self.last_build_is_successful(project, platform, browser)
45+
46+
if success:
47+
color = 'rgb(0, 169, 92)'
48+
status = 'passing'
49+
else:
50+
color = 'rgb(216, 68, 55)'
51+
status = 'failing'
52+
image = Image.new("RGBA", (120, 20))
53+
draw = ImageDraw.Draw(image)
54+
draw.polygon([(1, 1), (89, 1), (89, 19), (1, 19)], 'white', 'rgb(127, 127, 127)')
55+
draw.polygon([(37, 3), (87, 3), (87, 18), (37, 18)], color)
56+
draw.text((5, 5), 'build', 'rgb(127, 127, 127)')
57+
draw.text((41, 5), status, 'white')
58+
59+
output = StringIO.StringIO()
60+
image.save(output, format="png")
61+
layer = output.getvalue()
62+
output.close()
63+
64+
self.response.headers['Content-Type'] = 'image/png'
65+
self.response.write(layer)
66+
67+
68+
application = webapp2.WSGIApplication([
69+
webapp2.Route('/build/<project>/status.png', BuildStatusHandler),
70+
webapp2.Route('/build/<project>/<platform>/status.png', BuildStatusHandler),
71+
webapp2.Route('/build/<project>/<platform>/<browser>/status.png', BuildStatusHandler),
72+
], debug=False)

0 commit comments

Comments
 (0)