Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

chore: Save package statistics to DB #821

Merged
merged 7 commits into from
Feb 8, 2019
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
12 changes: 10 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this should throw, no? Do we want silent passes when stats aren't being saved for some reason?

fi
- run:
name: Danger JS
command: |
Expand All @@ -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
Expand Down
39 changes: 37 additions & 2 deletions build/gulp/tasks/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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

Expand All @@ -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)
})
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down