Giter Club home page Giter Club logo

travis-weigh-in's Introduction

NPM version

travis-weigh-in

Track how each commit/pull request affects the size of a file in your repo.

You are what you measure! This script lets you track the size of a generated file (e.g. your minified JavaScript bundle) as it's changed by each Pull Request and commit in your GitHub repo. Here's what the Pull Request Statuses section looks like after you've set it up:

status with weigh-in

The last line shows the current size of your file and how it's changed from the base of your PR (typically the master branch). With this Travis script, you'll catch code bloat regressions as they happen.

Setup

I'll assume you have a GitHub repo with Travis-CI enabled.

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":

generate new token

Be sure to check the repo:status scope and give your token some descriptive name:

granting repo status on github

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 GITHUB_TOKEN:

github_token set

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.yml file. You can either npm install travis-weigh-in, save a copy of the weigh_in.py script into your repo, add it as a git submodule, or just curl it into place. The script is intentionally written to have zero dependencies so, however you pull it in, it should Just Work.

For example, for a JavaScript project, your .travis.yml file 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

This script is most useful for JavaScript projects, which often use NPM to pull in dependencies. If this is convenient for you, you can set up travis-weigh-in by running:

npm install --save-dev travis-weigh-in

Then your .travis.yml file 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_TOKEN with this approach.

Notes

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 master, though.

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 master branch 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.

travis-weigh-in's People

Contributors

danvk avatar

Stargazers

Kyle Gerard Felker avatar Mihai Maruseac avatar Oromion avatar Geno Roupsky avatar Riccardo Bellingeri avatar Bater.Makhabel avatar Travis Arnold avatar Sibelius Seraphini avatar Jake Jarrett avatar Mark Dalgleish avatar Michele Bertoli avatar Henry Heath avatar Jordan Eldredge avatar Bruno Bonamin avatar Tobias Bieniek avatar James Baxley avatar  avatar Nikhil Mittal avatar Izaak "Zaak" Beekman avatar Cameron Chamberlain avatar Tyll Weiß avatar David da Silva avatar Cheng Gu avatar Hector Leiva avatar Dave Bauman avatar Daniel Nilsson avatar Michael Warkentin avatar Nick Presta avatar Kostas Manionis avatar Greg Smith avatar B. Arman Aksoy avatar  avatar

Watchers

 avatar Mihai Maruseac avatar James Cloos avatar Oromion avatar  avatar

travis-weigh-in's Issues

getting 401 errors

Hello, and thanks for this tool.
I have started to get 401 errors from this script.
I'm not sure what may be wrong, as I'm using the same token and the setup that worked before.
Can you please give me some advise about how to test it to find the root problem ?

Thanks and regards

Rewrite in JavaScript

Given that this is mostly useful for JS projects, it would make more sense for it to be written in JS and distributed via NPM/Node.

Generalize to track any number

Tracking numbers other than code size can be helpful.

For example, you can track code coverage percentage. Usually this is done by full services like Coveralls.

For less common numbers, though, travis-weigh-in could do the trick. When Flow adds a flow coverage command, for example, it could be used to start tracking what fraction of expressions are successfully typed.

It might look something like:

weigh_in.py flow-coverage 0.89123

Weird numeric format

Hello,

Thanks for this tool and its documentation.
I just start using it, but I noticed a weird behavior: the numbers have two commas . here is an image example

image

While this may be a visual clue, it is a bit weird. I would prefer the units to collapse (to KB, or to MB) when possible.

Thanks a regards

Add thresholds for failure

This should be a command-line flag, e.g.

python weigh_in.py --size_increase_for_failure=50000 path/to/file.js

or

python weigh_in.py --percent_size_increase_for_failure=25 path/to/file.js

Would you mind outline how it works?

Hello.
By reading the GH API and your code it's not immediately obvious how it works.
My understanding is that you push statuses for each file to the github API on every CI run. Then you just pull the previous status and push a new one computing the difference.
The part that is not easy to understand is how do you get the previous value? The github APIs you are consulting are always tied to the current SHA of the current commit, so statuses will be just the ones created on this very same PR.
But that shouldn't be the case, so I'm obviously missing some information here.
Thanks and regards

Add a --gzip flag

This would track the size of the file after gzip compression.

Or maybe this is a bad idea, you can always do:

gzip -c foo.min.js > foo.min.js.gz
python weigh_in.py foo.min.js.gz

Fails for "untrusted" Travis users

If someone who is not a repo owner sends you a PR, Travis-CI won't set the GITHUB_TOKEN environment variable (for security reasons).

This causes travis-weigh-in to fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.