Track how each commit/pull request affects the size of a file in your repo
Track how each commit/pull request affects the size of a file in your repo.
The last line shows the current size of your file and how it's changed from the base of your PR (typically the
masterbranch). With this Travis script, you'll catch code bloat regressions as they happen.
I'll assume you have a GitHub repo with Travis-CIenabled.
Generate a GitHub OAuth token
First you'll need to create a GitHub OAuth token for the weigh-in script to post status messages on your behalf. To do this, go to GitHub settings → "Personal Access Tokens" → "Generate a Token":
Be sure to check the
repo:statusscope and give your token some descriptive name:
Once your token is generated, copy it (you'll never be able to see it again!).
Now go to Travis-CI and open up the Settings page for your repo. Add the token as an environment variable named
Don't forget to click the "Add" button!
Run the weigh-in script
With the token in place, you need to run the script from your
.travis.ymlfile. You can either
npm install travis-weigh-in, save a copy of the
weigh_in.pyscript into your repo, add it as a git submodule, or just
curlit into place. The script is intentionally written to have zero dependencies so, however you pull it in, it should Just Work.
.travis.ymlfile might look like this:
language: node_js node_js: - "0.12" script: > npm run build && npm run test && curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/master/weigh_in.py && python weigh_in.py dist/script-to-track.min.js
Either push this commit to your repo or send it out as a pull request. The first run will only show an absolute size (i.e. no changes), but subsequent runs should show how the commit/PR changes the size of the file.
If you don't see code sizes posted, check out the logs of your Travis-CI builds for details on what went wrong.
Setup with NPM
npm install --save-dev travis-weigh-in
.travis.ymlfile might look like:
language: node_js node_js: - "0.12" script: > npm run build && npm run test && python node_modules/travis-weigh-in/weigh_in.py dist/script-to-track.min.js
Note that you still have to go through the process of setting
GITHUB_TOKENwith this approach.
If you rename the file, the weigh-in script won't be able to track size changes through the rename. You'll get size change information for subsequent commits after the rename is merged onto
In a pull request, the "push" build pushes an absolute code size, while the "pr" build pushes a size with changes (e.g. "+10 bytes"). If the "push" build finishes first, you'll see the absolute size before you see the delta.
The code in the
masterbranch can and will change. If you'd prefer not to trust me, you should either include a copy of the script directly in your own repo, use a submodule checked out at a specific commit or download a copy with a recent git SHA, e.g.
curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/08700622d972fed7adeda13a49988e26a3e98387/weigh_in.py
git SHAs are cryptographically secure, so you can be confident that the script won't break underneath you.