Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track generated file sizes on github using Travis-CI

I'd like to track the size of my minified JavaScript bundle as it's affected by pull requests on GitHub:

combined JS code size changes by +0.68%

I'd like to see the size changes for a generated file in a GitHub status on each commit that Travis-CI builds. This would be similar to how coveralls.io and other tools track code coverage as it changes.

How can I do this? Are there existing tools? Is it simple to write my own?

like image 645
danvk Avatar asked Oct 20 '15 18:10

danvk


1 Answers

GitHub provides a simple API for posting statuses on commits.

By putting a GitHub OAuth token in a Travis-CI environment variable, you can run a curl command to post the status:

filesize=$(wc -c < path-to-script.min.js | sed 's/ //g')
curl -H "Authorization: token $GITHUB_TOKEN" \
  --data '{"context": "file size", "description": "'$filesize' bytes", "state": "success"}' \
  https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/$TRAVIS_COMMIT

Calculating the change in file size resulting from a pull request is trickier. I wound up creating a Python script to do this, which you can find in the travis-weigh-in repo. With it, you'd just run this in your Travis build:

python weigh_in.py path-to-script.min.js

And it will produce commit statuses like the one in the question's screenshot.

like image 77
danvk Avatar answered Sep 29 '22 03:09

danvk