diff --git a/.circleci/config.yml b/.circleci/config.yml index 3c1944929c..0d6c068b82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -74,7 +74,15 @@ jobs: command: yarn test:projects - run: name: Bundle Statistics - command: yarn build:stats + command: yarn stats:build + - 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: | @@ -84,7 +92,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 d5f6a7acc1..a7c52cf242 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 requestHttp from 'request-promise-native' import config from '../../../config' @@ -101,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 @@ -118,6 +120,39 @@ task( 'stats', series( parallel(series('clean:dist:es', 'build:dist:es'), 'build:docs:component-info'), - 'build:stats:bundle', + 'stats:build:bundle', ), ) + +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: statsPayload, + json: true, + } + + const response = await requestHttp(options) + console.log(response) +}) diff --git a/package.json b/package.json index ffb808bc53..92dfd96fdb 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,8 @@ "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", "test": "gulp test", @@ -147,6 +148,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",