I'd like to track the size of my minified JavaScript bundle as it's affected by pull requests on GitHub:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With