From bcfd24fa74be4fe6da6c5dd1168ef800ef73dd69 Mon Sep 17 00:00:00 2001 From: Ismail Syed Date: Thu, 5 Dec 2019 10:43:20 -0500 Subject: [PATCH] Use @shopify/shrink-ray --- package.json | 1 + scripts/build-shrink-ray.js | 74 ++++++++++--------------------------- yarn.lock | 21 +++++++++++ 3 files changed, 41 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index edfce8e28f9..17038c982c6 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "@shopify/jest-dom-mocks": "^2.1.1", "@shopify/react-testing": "^1.8.0", "@shopify/sewing-kit": "^0.112.0", + "@shopify/shrink-ray": "^1.0.0", "@shopify/splash": "^0.0.8", "@storybook/addon-a11y": "^5.2.4", "@storybook/addon-actions": "^5.2.4", diff --git a/scripts/build-shrink-ray.js b/scripts/build-shrink-ray.js index 0f7f7bbbd70..c28eb2c83e5 100644 --- a/scripts/build-shrink-ray.js +++ b/scripts/build-shrink-ray.js @@ -4,14 +4,12 @@ require('isomorphic-fetch'); const {resolve} = require('path'); const {execSync} = require('child_process'); -const {existsSync, readFileSync} = require('fs-extra'); +const {postReport, sendCommitStatus} = require('@shopify/shrink-ray'); const BASE_BRANCH = 'master'; const repo = 'polaris-react'; const sha = process.env.CIRCLE_SHA1; -const postWebpackReportURL = `https://shrink-ray.shopifycloud.com/repos/${repo}/commits/${sha}/reports`; - const report = resolve( __dirname, '../build/storybook/bundle-analysis/report.html', @@ -38,29 +36,31 @@ function buildPackages() { function setupShrinkRay() { console.log('[shrink-ray] Running shrink-ray prebuild script...'); - sendCommitStatus('pending') - .then((response) => { - console.log(`[shrink-ray] status: ${response.status}`); - console.log(`[shrink-ray] statusText: ${response.statusText}`); + + // fetch latest in BuildKite pipeline + execSync('git fetch origin master'); + + const masterSha = execSync(`git merge-base HEAD origin/${BASE_BRANCH}`, { + encoding: 'utf8', + }).trim(); + + sendCommitStatus({repo, sha, state: 'pending'}) + .then(() => { console.log('[shrink-ray] shrink-ray prebuild script completed.'); buildPackages(); - return postReportToShrinkRay(); - }) - .then((response) => { - console.log(`[shrink-ray] Status: ${response.status}`); - console.log(`[shrink-ray] Status text: ${response.statusText}`); - return response.text(); - }) - .then((responseText) => { - console.log(`[shrink-ray] Response text: ${responseText}`); - console.log('[shrink-ray] Postbuild script completed.'); - return true; + + return postReport({ + repo, + sha, + baselineSha: masterSha, + reportPath: report, + }); }) .catch((error) => { console.log('ERROR: ', error); // eslint-disable-next-line promise/no-nesting - sendCommitStatus('error') + sendCommitStatus({repo, sha, state: 'error'}) .then(() => { throw error; }) @@ -69,39 +69,3 @@ function setupShrinkRay() { }); }); } - -function sendCommitStatus(state) { - const statusUrl = `https://shrink-ray.shopifycloud.com/repos/${repo}/commits/${sha}/status/${state}`; - console.log(`[shrink-ray] POST ${statusUrl}`); - return fetch(statusUrl, {method: 'POST'}); -} - -function postReportToShrinkRay() { - console.log('[shrink-ray] Running shrink-ray postbuild script...'); - console.log(`[shrink-ray] POST ${postWebpackReportURL}`); - - if (!existsSync(report)) { - sendCommitStatus('error'); - throw new Error('webpack-bundle-analyzer report not found.'); - } - - // fetch latest in BuildKite pipeline - execSync('git fetch origin master'); - - const masterSha = execSync(`git merge-base HEAD origin/${BASE_BRANCH}`, { - encoding: 'utf8', - }).trim(); - - console.log('[shrink-ray] masterSha: ', masterSha); - - return fetch(postWebpackReportURL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - report: readFileSync(report, 'utf8'), - masterSha, - }), - }); -} diff --git a/yarn.lock b/yarn.lock index d2bae111639..d3cf9f225bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1669,6 +1669,13 @@ fetch-mock "^6.3.0" lolex "^2.7.5" +"@shopify/network@^1.4.2": + version "1.4.4" + resolved "https://registry.yarnpkg.com/@shopify/network/-/network-1.4.4.tgz#82d57986c97bed4e1701109c62dc98ef21f96f8c" + integrity sha512-EmIQOG/1goB7PLRUO12tj6NWgwqxI5Uz/AE2NC5ygrDHtGhR/1mjMB0GG56PKxoSPlNuQo/P1Le0CKR5bruo4w== + dependencies: + tslib "^1.9.3" + "@shopify/polaris-icons@^3.3.0": version "3.3.0" resolved "https://registry.yarnpkg.com/@shopify/polaris-icons/-/polaris-icons-3.3.0.tgz#7031791d44bfe60e2f999c8fbf0ea67ab7a047c8" @@ -1826,6 +1833,15 @@ whatwg-url "^6.1.0" yargs "^12.0.2" +"@shopify/shrink-ray@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@shopify/shrink-ray/-/shrink-ray-1.0.0.tgz#30d6ac0ef6c57257058877afa9c468f667e5e4f1" + integrity sha512-v6GP+7f/YezQ5cQy0nasjKN15PFfroQtE22aW9EGfzbt+8pdMbpNLqQ6Da9CW6/rY1ec/4Pa79uZgzdyCyqYxw== + dependencies: + "@shopify/network" "^1.4.2" + async "^3.1.0" + isomorphic-fetch "^2.2.1" + "@shopify/splash@^0.0.5": version "0.0.5" resolved "https://registry.yarnpkg.com/@shopify/splash/-/splash-0.0.5.tgz#a6539ca9eaf689725a58b226920a8ccd537242df" @@ -3678,6 +3694,11 @@ async@^2.1.4: dependencies: lodash "^4.17.14" +async@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/async/-/async-3.1.0.tgz#42b3b12ae1b74927b5217d8c0016baaf62463772" + integrity sha512-4vx/aaY6j/j3Lw3fbCHNWP0pPaTCew3F6F3hYyl/tHs/ndmV1q7NW9T5yuJ2XAGwdQrP+6Wu20x06U4APo/iQQ== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"