Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,17 @@ jobs:
fi
- store_artifacts:
path: app/build/reports
destination: reports
destination: reports
- restore_cache: # special step to restore the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
- run:
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: Check & Publish Binary Size
command: |
./scripts/check_binary_size.sh ./scripts/paths_file.txt ./scripts/labels_file.txt 'mapbox-navigation-android' 'android' ./scripts/platforms_file.txt
61 changes: 61 additions & 0 deletions cloudformation/ci.template.js
Original file line number Diff line number Diff line change
@@ -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') }
}
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@mapbox/mapbox-navigation-android",
"version": "0.23.0",
"description": "Navigation Services",
"keywords": [
"mapbox",
"navigation",
"location"
],
"repository": {
"type": "git",
"url": "git://github.com/mapbox/mapbox-navigation-android.git"
},
"devDependencies": {
"express": "^4.11.1",
"@octokit/rest": "^15.15.1",
"jsonwebtoken": "^8.3.0",
"pretty-bytes": "^5.1.0"
},
"engines": {
"node": ">=6"
},
"dependencies": {
"@mapbox/cloudfriend": "^2.5.0"
}
}
57 changes: 57 additions & 0 deletions scripts/check_binary_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

set -e
set -o pipefail

# Argument 1 is a file including file paths (one per line)
paths_file=$1
# Argument 2 is a file including labels (one per line) - Must match paths_file number of lines / size
labels_file=$2
# Argument 3 is the repo name
repo_name=$3
# Argument 4 is the SDK
sdk=$4
# Argument 5 is a file including the platforms (one per line) - Must match paths_file number of lines / size
platforms_file=$5

source=mobile.binarysize
scripts_path="scripts"
json_name="$scripts_path/${sdk}-binarysize.json"
json_gz="$scripts_path/${sdk}-binarysize.json.gz"

date=`date '+%Y-%m-%d'`
utc_iso_date=`date -u +'%Y-%m-%dT%H:%M:%SZ'`

while read label
do
labels+=("$label")
done <"$labels_file"

# Publish to github
i=0
while read path
do
file_size=$(wc -c <"$path" | sed -e 's/^[[:space:]]*//')
"$scripts_path"/publish_to_sizechecker.js "${file_size}" "${labels[${i}]}" "$repo_name"
i=$(($i + 1))
done <"$paths_file"

while read platform
do
platforms+=("$platform")
done <"$platforms_file"

# Write binary size to json file
i=0
while read path
do
file_size=$(wc -c <"$path" | sed -e 's/^[[:space:]]*//')
echo "{"sdk": ${sdk}, "platform": ${platforms[${i}]}, "size": ${file_size}, "created_at": "${utc_iso_date}"}" >> "$json_name"
i=$(($i + 1))
done <"$paths_file"

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

# Publish to aws
"$scripts_path"/publish_to_aws.sh $source $date $json_gz
2 changes: 2 additions & 0 deletions scripts/labels_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Navigation AAR
Navigation UI AAR
2 changes: 2 additions & 0 deletions scripts/paths_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
libandroid-navigation/build/outputs/aar/libandroid-navigation-release.aar
libandroid-navigation-ui/build/outputs/aar/libandroid-navigation-ui-release.aar
2 changes: 2 additions & 0 deletions scripts/platforms_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
navigation
navigation-ui
13 changes: 13 additions & 0 deletions scripts/publish_to_aws.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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
47 changes: 47 additions & 0 deletions scripts/publish_to_sizechecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node

const jwt = require('jsonwebtoken');
const github = require('@octokit/rest')();
const prettyBytes = require('pretty-bytes');

const SIZE_CHECK_APP_ID = 14028;
const SIZE_CHECK_APP_INSTALLATION_ID = 229425;

const size_str = process.argv[2];
const label = process.argv[3];
const size = parseInt(size_str, 10);
const repo_name = process.argv[4];

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: `${repo_name}`,
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: `\`${label}\` is ${size} bytes (${prettyBytes(size)})`
}
});
});
Loading