Skip to content

Commit

Permalink
Push mobile metrics to loading dock (#288)
Browse files Browse the repository at this point in the history
Pushing binary size with every PR to AWS.
  • Loading branch information
andrlee committed Nov 13, 2018
1 parent a556da0 commit e7b05b1
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 63 deletions.
7 changes: 3 additions & 4 deletions .circleci/config.yml
Expand Up @@ -117,13 +117,12 @@ jobs:
- restore_cache: # special step to restore the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: setup environment
name: Setup Environment
command: npm install
- save_cache: # special step to save the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: Record size
command: ./scripts/metrics.sh

name: Check & Publish Binary Size
command: ./scripts/check_binary_size.sh
47 changes: 0 additions & 47 deletions ci.template

This file was deleted.

61 changes: 61 additions & 0 deletions cloudformation/ci.template.js
@@ -0,0 +1,61 @@
var cf = require('@mapbox/cloudfriend');

module.exports = {
AWSTemplateFormatVersion: '2010-09-09',
Resources: {
User: {
Type: 'AWS::IAM::User',
Properties: {
Policies: [
{
PolicyName: 'devicefarm',
PolicyDocument: {
Statement: [
{
Action: ['devicefarm:*'],
Effect: 'Allow',
Resource: '*'
}
]
}
},
{
PolicyName: 'publish-metrics',
PolicyDocument: {
Statement: [
{
Action: ['s3:PutObject'],
Effect: 'Allow',
Resource: ['arn:aws:s3:::mapbox-loading-dock/raw/mobile.binarysize/*',
'arn:aws:s3:::mapbox-loading-dock/raw/mobile.codecoverage/*']
}
]
}
},
{
PolicyName: 'get-signing-key',
PolicyDocument: {
Statement: [
{
Action: ['s3:GetObject'],
Effect: 'Allow',
Resource: ['arn:aws:s3:::mapbox/android/signing-credentials/secring.gpg']
}
]
}
}
]
}
},
AccessKey: {
Type: 'AWS::IAM::AccessKey',
Properties: {
UserName: cf.ref('User')
}
}
},
Outputs: {
AccessKeyId: { Value: cf.ref('AccessKey') },
SecretAccessKey: { Value: cf.getAtt('AccessKey', 'SecretAccessKey') }
}
};
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -21,5 +21,8 @@
},
"engines": {
"node": ">=6"
},
"dependencies": {
"@mapbox/cloudfriend": "^2.5.0"
}
}
}
28 changes: 28 additions & 0 deletions scripts/check_binary_size.sh
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e
set -o pipefail

file_path="libtelemetry/build/outputs/aar/libtelemetry-release.aar"
file_size=$(wc -c <"$file_path" | sed -e 's/^[[:space:]]*//')
date=`date '+%Y-%m-%d'`
utc_iso_date=`date -u +'%Y-%m-%dT%H:%M:%SZ'`
label="Telemetry AAR"
source="mobile.binarysize"
scripts_path="scripts"
json_name="$scripts_path/android-binarysize.json"
json_gz="$scripts_path/android-binarysize.json.gz"

# Publish to github
"$scripts_path"/publish_to_sizechecker.js "$file_size" "$label"

# Write binary size to json file
cat >"$json_name" <<EOL
{"sdk": "telemetry", "platform": "android", "size": ${file_size}, "created_at": "${utc_iso_date}"}
EOL

# Compress json file
gzip -f "$json_name" > "$json_gz"

# Publish to aws
"$scripts_path"/publish_to_aws.sh $source $date $json_gz
7 changes: 0 additions & 7 deletions scripts/metrics.sh

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/publish_to_aws.sh
@@ -0,0 +1,14 @@
#!/bin/bash

source="$1"
date="$2"
file_path="$3"
if [ -z "$file_path" ] || [ -z "$source" ] || [ -z "$date" ]; then
>&2 echo "Usage: publish.sh source date filepath"
>&2 echo ""
>&2 echo "Example: publish.sh mobile_binarysize 2018-11-01 android-binarysize.json.gz"
exit 1
fi

filename="${file_path##*/}"
aws s3 cp $file_path s3://mapbox-loading-dock/raw/$source/$date/$filename
Expand Up @@ -3,14 +3,13 @@
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 size_str = process.argv[2];
const label = process.argv[3];
const {size} = fs.statSync(file);
const size = parseInt(size_str, 10);

process.on('unhandledRejection', error => {
console.log(error);
Expand Down Expand Up @@ -41,7 +40,7 @@ github.apps.createInstallationToken({installation_id: SIZE_CHECK_APP_INSTALLATIO
completed_at: new Date().toISOString(),
output: {
title: prettyBytes(size),
summary: `\`${file}\` is ${size} bytes (${prettyBytes(size)})`
summary: `\`${label}\` is ${size} bytes (${prettyBytes(size)})`
}
});
});

0 comments on commit e7b05b1

Please sign in to comment.