summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rwxr-xr-xplatform/android/scripts/metrics.sh4
-rwxr-xr-xplatform/ios/scripts/metrics.sh4
-rwxr-xr-xscripts/publish_binary_size.js133
4 files changed, 142 insertions, 1 deletions
diff --git a/package.json b/package.json
index f1c8411fd0..ef23f4aa99 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
},
"devDependencies": {
"@octokit/rest": "^15.9.2",
- "aws-sdk": "^2.3.5",
+ "aws-sdk": "^2.285.1",
"csscolorparser": "^1.0.2",
"ejs": "^2.4.1",
"express": "^4.11.1",
diff --git a/platform/android/scripts/metrics.sh b/platform/android/scripts/metrics.sh
index 42b9fa4870..6c74ecced9 100755
--- a/platform/android/scripts/metrics.sh
+++ b/platform/android/scripts/metrics.sh
@@ -11,3 +11,7 @@ scripts/check_binary_size.js "platform/android/MapboxGLAndroidSDK/build/intermed
# Track overall library size
scripts/check_binary_size.js "platform/android/MapboxGLAndroidSDK/build/outputs/aar/MapboxGLAndroidSDK-release.aar" "Android AAR"
+
+if [[ $CIRCLE_BRANCH == master ]]; then
+ scripts/publish_binary_size.js
+fi
diff --git a/platform/ios/scripts/metrics.sh b/platform/ios/scripts/metrics.sh
index d099520762..3fed04d0f0 100755
--- a/platform/ios/scripts/metrics.sh
+++ b/platform/ios/scripts/metrics.sh
@@ -17,3 +17,7 @@ scripts/check_binary_size.js "build/ios/pkg/dynamic/Mapbox-stripped-x86_64" "iO
# Track overall library size
scripts/check_binary_size.js "build/ios/pkg/dynamic/Mapbox-stripped" "iOS Dynamic"
+
+if [[ $CIRCLE_BRANCH == master ]]; then
+ scripts/publish_binary_size.js
+fi
diff --git a/scripts/publish_binary_size.js b/scripts/publish_binary_size.js
new file mode 100755
index 0000000000..c7c1698436
--- /dev/null
+++ b/scripts/publish_binary_size.js
@@ -0,0 +1,133 @@
+#!/usr/bin/env node
+
+const jwt = require('jsonwebtoken');
+const github = require('@octokit/rest')();
+const zlib = require('zlib');
+const AWS = require('aws-sdk');
+
+const SIZE_CHECK_APP_ID = 14028;
+const SIZE_CHECK_APP_INSTALLATION_ID = 229425;
+
+process.on('unhandledRejection', error => {
+ console.log(error);
+ process.exit(1)
+});
+
+const pk = process.env['SIZE_CHECK_APP_PRIVATE_KEY'];
+if (!pk) {
+ console.log('Fork PR; not publishing size.');
+ process.exit(0);
+}
+
+const key = Buffer.from(pk, '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});
+
+// Must be in sync with the definition in metrics/binary-size/index.html on the gh-pages branch.
+const platforms = [
+ { 'platform': 'iOS', 'arch': 'armv7' },
+ { 'platform': 'iOS', 'arch': 'arm64' },
+ { 'platform': 'Android', 'arch': 'arm-v7' },
+ { 'platform': 'Android', 'arch': 'arm-v8' },
+ { 'platform': 'Android', 'arch': 'x86' },
+ { 'platform': 'Android', 'arch': 'x86_64' }
+];
+
+const rows = [];
+
+function query(after) {
+ return github.request({
+ method: 'POST',
+ url: '/graphql',
+ headers: {
+ // https://developer.github.com/changes/2018-07-11-graphql-checks-preview/
+ accept: 'application/vnd.github.antiope-preview'
+ },
+ query: `query {
+ repository(owner: "mapbox", name: "mapbox-gl-native") {
+ ref(qualifiedName: "master") {
+ target {
+ ... on Commit {
+ history(first: 100, since: "2018-07-01T00:00:00Z" ${after ? `, after: "${after}"` : ''}) {
+ pageInfo {
+ hasNextPage
+ endCursor
+ }
+ edges {
+ node {
+ oid
+ messageHeadline
+ checkSuites(first: 1, filterBy: {appId: ${SIZE_CHECK_APP_ID}}) {
+ nodes {
+ checkRuns(first: 10) {
+ nodes {
+ name
+ conclusion
+ title
+ summary
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }`
+ }).then((result) => {
+ const history = result.data.data.repository.ref.target.history;
+
+ for (const edge of history.edges) {
+ const commit = edge.node;
+ const suite = commit.checkSuites.nodes[0];
+
+ if (!suite)
+ continue;
+
+ const runs = commit.checkSuites.nodes[0].checkRuns.nodes;
+ const row = [`${commit.oid.slice(0, 7)} - ${commit.messageHeadline}`];
+
+ for (let i = 0; i < platforms.length; i++) {
+ const {platform, arch} = platforms[i];
+
+ const run = runs.find((run) => {
+ const [, p, a] = run.name.match(/Size - (\w+) ([\w-]+)/);
+ return platform === p && arch === a;
+ });
+
+ row[i + 1] = run ? +run.summary.match(/is (\d+) bytes/)[1] : undefined;
+ }
+
+ rows.push(row);
+ }
+
+ if (history.pageInfo.hasNextPage) {
+ return query(history.pageInfo.endCursor);
+ } else {
+ return new AWS.S3({region: 'us-east-1'}).putObject({
+ Body: zlib.gzipSync(JSON.stringify(rows.reverse())),
+ Bucket: 'mapbox',
+ Key: 'mapbox-gl-native/metrics/binary-size/data.json',
+ ACL: 'public-read',
+ CacheControl: 'max-age=300',
+ ContentEncoding: 'gzip',
+ ContentType: 'application/json'
+ }).promise();
+ }
+ });
+}
+
+github.apps.createInstallationToken({installation_id: SIZE_CHECK_APP_INSTALLATION_ID})
+ .then(({data}) => {
+ github.authenticate({type: 'token', token: data.token});
+ return query();
+ });