From 4ace711712271282975716f2b71cfb5c74de24f8 Mon Sep 17 00:00:00 2001 From: Miroslav Stastny Date: Fri, 1 Feb 2019 11:29:45 +0100 Subject: [PATCH 1/3] Add stats:save task --- build/gulp/tasks/stats.ts | 19 +++++++++++++++++++ package.json | 2 ++ 2 files changed, 21 insertions(+) diff --git a/build/gulp/tasks/stats.ts b/build/gulp/tasks/stats.ts index d5f6a7acc1..0540df6aad 100644 --- a/build/gulp/tasks/stats.ts +++ b/build/gulp/tasks/stats.ts @@ -3,6 +3,8 @@ import { task, parallel, series } from 'gulp' import * as _ from 'lodash' import * as webpack from 'webpack' import * as stableStringify from 'json-stable-stringify-without-jsonify' +import { argv } from 'yargs' +import * as rp from 'request-promise-native' import config from '../../../config' @@ -121,3 +123,20 @@ task( 'build:stats:bundle', ), ) + +task('stats:save', async () => { + const data = _.pick(argv, ['name']) + const bundleStats = require(paths.docsSrc('bundleStats.json'))[UNRELEASED_VERSION_STRING] + + const options = { + method: 'POST', + uri: process.env.STATS_URI, + body: { + ...data, + bundleSize: bundleStats, + }, + json: true, + } + const ret = await rp(options) + console.log(ret) +}) diff --git a/package.json b/package.json index 058d212dcb..d74d7a8542 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "release:patch": "yarn prerelease && ta-script npm/release patch && yarn postrelease", "prestart": "yarn satisfied --fix yarn", "start": "gulp --series dll docs", + "stats:save": "gulp stats:save", "satisfied": "satisfied --skip-invalid", "pretest": "yarn satisfied", "test": "gulp test", @@ -152,6 +153,7 @@ "react-router-dom": "^4.1.2", "react-source-render": "^2.0.0-beta.4", "react-test-renderer": "^16.0.0", + "request-promise-native": "^1.0.5", "rimraf": "^2.6.1", "satisfied": "^1.1.1", "screener-runner": "^0.10.7", From d6b311c0a440e3c4b77fcc286d55996a341323ca Mon Sep 17 00:00:00 2001 From: Miroslav Stastny Date: Fri, 1 Feb 2019 14:10:10 +0100 Subject: [PATCH 2/3] Save stats in CI --- .circleci/config.yml | 10 +++++++++- build/gulp/tasks/stats.ts | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 179d320faf..711bc9021e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,6 +80,14 @@ jobs: - run: name: Bundle Statistics command: yarn build:stats + - run: + name: Save Statistics to DB + command: | + if [ -n "${STATS_URI}" ]; then + yarn stats:save + else + echo "STATS_URI not set, skipping" + fi - run: name: Danger JS command: | @@ -89,7 +97,7 @@ jobs: - run: name: Publish npm package command: | - if [ -n "${npm_TOKEN+x}" ] && [ "${CIRCLE_BRANCH}" == "master" ]; then + if [ -n "${npm_TOKEN}" ] && [ "${CIRCLE_BRANCH}" == "master" ]; then echo "//registry.npmjs.org/:_authToken=${npm_TOKEN}" > ~/project/.npmrc npm version prerelease --preid="${CIRCLE_BUILD_NUM}.${CIRCLE_BRANCH}.`git rev-parse --short HEAD`" --no-git-tag-version npm publish --tag current diff --git a/build/gulp/tasks/stats.ts b/build/gulp/tasks/stats.ts index 0540df6aad..5b5510a2b2 100644 --- a/build/gulp/tasks/stats.ts +++ b/build/gulp/tasks/stats.ts @@ -125,18 +125,25 @@ task( ) task('stats:save', async () => { - const data = _.pick(argv, ['name']) + const commandLineArgs = _.pick(argv, ['sha', 'branch', 'tag', 'pr', 'build']) const bundleStats = require(paths.docsSrc('bundleStats.json'))[UNRELEASED_VERSION_STRING] const options = { method: 'POST', uri: process.env.STATS_URI, body: { - ...data, + sha: process.env.CIRCLE_SHA1, + branch: process.env.CIRCLE_BRANCH, + tag: process.env.CIRCLE_TAG, // optional + pr: process.env.CIRCLE_PULL_REQUEST, // optional + build: process.env.CIRCLE_BUILD_NUM, + ...commandLineArgs, // allow command line overwrites bundleSize: bundleStats, + ts: new Date(), }, json: true, } + const ret = await rp(options) console.log(ret) }) From 8bf190352510ee380f572d676968579fb03a7a17 Mon Sep 17 00:00:00 2001 From: Miroslav Stastny Date: Wed, 6 Feb 2019 10:07:57 +0100 Subject: [PATCH 3/3] Address PR comments --- .circleci/config.yml | 2 +- build/gulp/tasks/stats.ts | 39 ++++++++++++++++++++++++--------------- package.json | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 711bc9021e..dd733213d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -79,7 +79,7 @@ jobs: command: yarn test:projects - run: name: Bundle Statistics - command: yarn build:stats + command: yarn stats:build - run: name: Save Statistics to DB command: | diff --git a/build/gulp/tasks/stats.ts b/build/gulp/tasks/stats.ts index 5b5510a2b2..a7c52cf242 100644 --- a/build/gulp/tasks/stats.ts +++ b/build/gulp/tasks/stats.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash' import * as webpack from 'webpack' import * as stableStringify from 'json-stable-stringify-without-jsonify' import { argv } from 'yargs' -import * as rp from 'request-promise-native' +import * as requestHttp from 'request-promise-native' import config from '../../../config' @@ -103,7 +103,7 @@ function updateStatsFile(filePath: string, currentBundleStats: any) { ) } -task('build:stats:bundle', async () => { +task('stats:build:bundle', async () => { process.env.NODE_ENV = 'build' const webpackStatsConfig = require('../../webpack.config.stats').default @@ -120,7 +120,7 @@ task( 'stats', series( parallel(series('clean:dist:es', 'build:dist:es'), 'build:docs:component-info'), - 'build:stats:bundle', + 'stats:build:bundle', ), ) @@ -128,22 +128,31 @@ task('stats:save', async () => { const commandLineArgs = _.pick(argv, ['sha', 'branch', 'tag', 'pr', 'build']) const bundleStats = require(paths.docsSrc('bundleStats.json'))[UNRELEASED_VERSION_STRING] + const statsPayload = { + sha: process.env.CIRCLE_SHA1, + branch: process.env.CIRCLE_BRANCH, + tag: process.env.CIRCLE_TAG, // optional + pr: process.env.CIRCLE_PULL_REQUEST, // optional + build: process.env.CIRCLE_BUILD_NUM, + ...commandLineArgs, // allow command line overwrites + bundleSize: bundleStats, + ts: new Date(), + } + + // payload sanity check + _.forEach(['sha', 'branch', 'build', 'bundleSize'], fieldName => { + if (statsPayload[fieldName] === undefined) { + throw `Required field '${fieldName}' not set in stats payload` + } + }) + const options = { method: 'POST', uri: process.env.STATS_URI, - body: { - sha: process.env.CIRCLE_SHA1, - branch: process.env.CIRCLE_BRANCH, - tag: process.env.CIRCLE_TAG, // optional - pr: process.env.CIRCLE_PULL_REQUEST, // optional - build: process.env.CIRCLE_BUILD_NUM, - ...commandLineArgs, // allow command line overwrites - bundleSize: bundleStats, - ts: new Date(), - }, + body: statsPayload, json: true, } - const ret = await rp(options) - console.log(ret) + const response = await requestHttp(options) + console.log(response) }) diff --git a/package.json b/package.json index c2ba17a713..7b1ac37ef0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ ], "scripts": { "build": "gulp build", - "build:stats": "gulp stats", "build:docs": "gulp --series dll build:docs", "build:dist": "gulp --series build:dist", "ci": "yarn lint && yarn prettier && yarn test --strict", @@ -34,6 +33,7 @@ "release:patch": "yarn prerelease && ta-script npm/release patch && yarn postrelease", "prestart": "yarn satisfied --fix yarn", "start": "gulp --series dll docs", + "stats:build": "gulp stats", "stats:save": "gulp stats:save", "satisfied": "satisfied --skip-invalid", "pretest": "yarn satisfied",