Skip to content

Commit

Permalink
Merge pull request #2518 from Shopify/use-shrink-ray-package
Browse files Browse the repository at this point in the history
Use @shopify/shrink-ray package
  • Loading branch information
ismail-syed authored Dec 6, 2019
2 parents 42cb5a4 + bcfd24f commit 21603b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 55 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
74 changes: 19 additions & 55 deletions scripts/build-shrink-ray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
})
Expand All @@ -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,
}),
});
}
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 21603b8

Please sign in to comment.