summaryrefslogtreecommitdiff
path: root/scripts/check_binary_size.js
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-07-02 14:09:58 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-07-03 14:03:32 -0700
commit840a5cf1207ed78df3302211a23d369dd3c12b89 (patch)
tree9bd84a680e2b79b9aaff5406164e8af237503a5b /scripts/check_binary_size.js
parent6fc0eb908bb2de2c0da9725470b46bd05c13fed6 (diff)
downloadqtlocation-mapboxgl-840a5cf1207ed78df3302211a23d369dd3c12b89.tar.gz
[build] Record binary size via GitHub check
Diffstat (limited to 'scripts/check_binary_size.js')
-rwxr-xr-xscripts/check_binary_size.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/check_binary_size.js b/scripts/check_binary_size.js
new file mode 100755
index 0000000000..70ddbc7e0e
--- /dev/null
+++ b/scripts/check_binary_size.js
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+
+const jwt = require('jsonwebtoken');
+const github = require('@octokit/rest')();
+const prettyBytes = require('pretty-bytes');
+const fs = require('fs');
+
+const SIZE_CHECK_APP_ID = 14028;
+const SIZE_CHECK_APP_INSTALLATION_ID = 229425;
+
+const file = process.argv[2];
+const label = process.argv[3];
+const {size} = fs.statSync(file);
+
+process.on('unhandledRejection', error => {
+ console.log(error);
+ process.exit(1)
+});
+
+const key = Buffer.from(process.env['SIZE_CHECK_APP_PRIVATE_KEY'], 'base64').toString('binary');
+const payload = {
+ exp: Math.floor(Date.now() / 1000) + 60,
+ iat: Math.floor(Date.now() / 1000),
+ iss: SIZE_CHECK_APP_ID
+};
+
+const token = jwt.sign(payload, key, {algorithm: 'RS256'});
+github.authenticate({type: 'app', token});
+
+github.apps.createInstallationToken({installation_id: SIZE_CHECK_APP_INSTALLATION_ID})
+ .then(({data}) => {
+ github.authenticate({type: 'token', token: data.token});
+ return github.checks.create({
+ owner: 'mapbox',
+ repo: 'mapbox-gl-native',
+ name: `Size - ${label}`,
+ head_branch: process.env['CIRCLE_BRANCH'],
+ head_sha: process.env['CIRCLE_SHA1'],
+ status: 'completed',
+ conclusion: 'success',
+ completed_at: new Date().toISOString(),
+ output: {
+ title: prettyBytes(size),
+ summary: `\`${file}\` is ${size} bytes (${prettyBytes(size)})`
+ }
+ });
+ });