summaryrefslogtreecommitdiff
path: root/scripts
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
parent6fc0eb908bb2de2c0da9725470b46bd05c13fed6 (diff)
downloadqtlocation-mapboxgl-840a5cf1207ed78df3302211a23d369dd3c12b89.tar.gz
[build] Record binary size via GitHub check
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check_binary_size.js47
-rwxr-xr-xscripts/log_binary_size.sh43
-rwxr-xr-xscripts/publish_binary_size.sh74
3 files changed, 47 insertions, 117 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)})`
+ }
+ });
+ });
diff --git a/scripts/log_binary_size.sh b/scripts/log_binary_size.sh
deleted file mode 100755
index 1147a8c479..0000000000
--- a/scripts/log_binary_size.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-set -u
-
-# Logs metrics on binary size to CloudWatch
-
-FILE=$1
-DIMENSIONS=$2
-
-if [ -z "${DIMENSIONS}" ]; then
- echo "* No dimensions specified for '${FILE}'"
- exit 1
-fi
-
-function filesize {
- if [ `uname -s` = 'Darwin' ]; then
- stat -f%z $1
- else
- stat --printf=%s $1
- fi
-}
-
-if [ -f "${FILE}" ]; then
- SIZE=`filesize ${FILE}`
- if [ ${CLOUDWATCH:-} ]; then
- echo "* Reporting `LC_NUMERIC=en_US printf "%'10.f\n" ${SIZE}` bytes for '${DIMENSIONS}' (${FILE})"
- aws --region us-east-1 cloudwatch put-metric-data \
- --namespace "Mapbox/GL" \
- --metric-name "BinarySize" \
- --unit "Bytes" \
- --value ${SIZE} \
- --dimensions "${DIMENSIONS}"
-
- ./scripts/publish_binary_size.sh "${DIMENSIONS}"
- else
- echo "* Measured `LC_NUMERIC=en_US printf "%'10.f\n" ${SIZE}` bytes for '${DIMENSIONS}' (${FILE})"
- fi
-else
- echo "* File '${FILE}' does not exist"
- exit 1
-fi
diff --git a/scripts/publish_binary_size.sh b/scripts/publish_binary_size.sh
deleted file mode 100755
index 08dfb88287..0000000000
--- a/scripts/publish_binary_size.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-set -u
-
-# Downloads log data from AWS CloudWatch and uploads it as a JSON file to S3 for public access.
-
-function publish_binary_size {
- local DIMENSIONS=$1
-
- if [ -z "${DIMENSIONS}" ]; then
- echo "* No dimensions specified"
- exit 1
- fi
-
- function print_dimensions {
- for ITEM in ${DIMENSIONS//,/ } ; do
- echo -n "Name=${ITEM//=/,Value=} "
- done
- }
-
- local DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ"
- local DATE_END=$(date -u +${DATE_FORMAT})
-
- if [ `uname -s` = 'Darwin' ]; then # BSD date
- local DATE_BEGIN=$(date -jf "${DATE_FORMAT}" -v-60d "${DATE_END}" +"${DATE_FORMAT}")
- else # GNU date
- local DATE_BEGIN=$(date --date="${DATE_END} - 60 days" +"${DATE_FORMAT}")
- fi
-
- # Download the metrics, gzip, and upload to S3.
- aws --region us-east-1 cloudwatch get-metric-statistics \
- --namespace "Mapbox/GL" \
- --metric-name "BinarySize" \
- --unit "Bytes" \
- --start-time "${DATE_BEGIN}" \
- --end-time "${DATE_END}" \
- --period 3600 \
- --statistics Maximum \
- --dimensions `print_dimensions` \
- | gzip | aws s3 cp \
- --acl public-read \
- --cache-control "max-age=300" \
- --content-encoding gzip \
- --content-type application/json \
- - "s3://mapbox/mapbox-gl-native/metrics/binary-size/${DIMENSIONS}.json"
-
- echo "* Uploaded data to 's3://mapbox/mapbox-gl-native/metrics/binary-size/${DIMENSIONS}.json'"
-}
-
-if [ $# -gt 0 ]; then
- # Upload the specified dimension only
- publish_binary_size "$1"
-else
- # Upload all dimensions that we are tracking
- publish_binary_size "Platform=iOS,Arch=armv7"
- publish_binary_size "Platform=iOS,Arch=arm64"
- publish_binary_size "Platform=iOS,Arch=x86_64"
- publish_binary_size "Platform=iOS,Arch=Dynamic"
-
- publish_binary_size "Platform=macOS,Arch=x86_64"
-
- publish_binary_size "Platform=Linux,Compiler=clang-3.8,Arch=x86_64"
- publish_binary_size "Platform=Linux,Compiler=gcc-5,Arch=x86_64"
-
- publish_binary_size "Platform=Android,Arch=arm-v5"
- publish_binary_size "Platform=Android,Arch=arm-v7"
- publish_binary_size "Platform=Android,Arch=arm-v8"
- publish_binary_size "Platform=Android,Arch=x86"
- publish_binary_size "Platform=Android,Arch=x86_64"
- publish_binary_size "Platform=Android,Arch=mips"
- publish_binary_size "Platform=Android,Arch=Archive"
-fi