简体   繁体   English

使用Travis-CI跟踪github上生成的文件大小

[英]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: 我想跟踪我的缩小JavaScript包的大小,因为它受到GitHub上的pull请求的影响:

合并JS代码大小变化+ 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. 我想看看Travis-CI构建的每次提交中GitHub状态的生成文件的大小更改。 This would be similar to how coveralls.io and other tools track code coverage as it changes. 这类似于coveralls.io和其他工具在更改时跟踪代码覆盖率的方式。

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. GitHub提供了一个简单的API,用于在提交时发布状态。

By putting a GitHub OAuth token in a Travis-CI environment variable , you can run a curl command to post the status: 通过在Travis-CI环境变量中放置GitHub OAuth令牌,您可以运行curl命令来发布状态:

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. 我最终创建了一个Python脚本来执行此操作,您可以在travis-weigh-in repo中找到它。 With it, you'd just run this in your Travis build: 有了它,你只需在你的Travis构建中运行它:

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

And it will produce commit statuses like the one in the question's screenshot. 它会产生提交状态,如问题截图中的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM