Skip to content

Commit

Permalink
Serve build status images to docs site
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Aug 26, 2013
1 parent 0303b9f commit f1e7475
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
_site
.DS_Store
.DS_Store
*.pyc
9 changes: 8 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
application: polymer-project
version: 20130822
version: 20130829
runtime: python27
api_version: 1
threadsafe: yes

#default_expiration: "0s"

libraries:
- name: PIL
version: latest

handlers:

# Top-level URLs ---------------------------------------------------------------
- url: /$
static_files: _site/index.html
upload: _site/index\.html

- url: /build/(.*)
script: build.application

- url: /polymer.min.js
static_files: js/polymer.min.js
upload: js/polymer\.min\.js
Expand Down
72 changes: 72 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import urllib, urllib2
import json

from PIL import Image, ImageDraw
import StringIO

import webapp2

PLATFORMS_ALL = ['Mac', 'Linux', 'Win']


class BuildStatusHandler(webapp2.RequestHandler):

def get_last_build(self, project, platform):
url = 'http://build.chromium.org/p/client.polymer/json/builders/' + urllib.quote('%s %s' % (project, platform)) + '/builds/-1'
return json.load(urllib2.urlopen(url))

def last_build_is_successful(self, project, platform, browser):
success = True
build = self.get_last_build(project, platform)
foundTest = False
for step in build['steps']:
if foundTest:
if step['results'][0] != 0:
if browser == 'all' or step['text'][0].find(browser) != -1:
success = False
break
elif step['name'] == 'test':
if step['results'][0] != 0:
success = False
break
else:
foundTest = True
return success

def get(self, project, platform='all', browser='all'):
success = True
if platform == 'all':
for plat in PLATFORMS_ALL:
if not self.last_build_is_successful(project, plat, browser):
success = False
break
else:
success = self.last_build_is_successful(project, platform, browser)

if success:
color = 'rgb(0, 169, 92)'
status = 'passing'
else:
color = 'rgb(216, 68, 55)'
status = 'failing'
image = Image.new("RGBA", (120, 20))
draw = ImageDraw.Draw(image)
draw.polygon([(1, 1), (89, 1), (89, 19), (1, 19)], 'white', 'rgb(127, 127, 127)')
draw.polygon([(37, 3), (87, 3), (87, 18), (37, 18)], color)
draw.text((5, 5), 'build', 'rgb(127, 127, 127)')
draw.text((41, 5), status, 'white')

output = StringIO.StringIO()
image.save(output, format="png")
layer = output.getvalue()
output.close()

self.response.headers['Content-Type'] = 'image/png'
self.response.write(layer)


application = webapp2.WSGIApplication([
webapp2.Route('/build/<project>/status.png', BuildStatusHandler),
webapp2.Route('/build/<project>/<platform>/status.png', BuildStatusHandler),
webapp2.Route('/build/<project>/<platform>/<browser>/status.png', BuildStatusHandler),
], debug=False)

0 comments on commit f1e7475

Please sign in to comment.