Skip to content

Commit

Permalink
chore(storybook): Added publishing of PR storybook to S3 bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael James committed Jun 4, 2017
1 parent 16821bc commit 999b0bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/coverage

# production
/build
/dist

# misc
Expand Down
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ node_js:
- 7
cache:
yarn: true
directories:
- node_modules

before_install:
- pip install --user awscli
- export PATH=$PATH:$HOME/.local/bin

script:
- yarn run coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- yarn run build
- yarn run build-storybook
- node ./build/aws-deploy.js

after_script:
# TODO comment on PR with link to PR storybook on S3 and notify slack room
- echo "PR storybook can be found at:"
- echo "http://react-audio-vis-prs.s3-ap-southeast-2.amazonaws.com/$TRAVIS_PULL_REQUEST_BRANCH/index.html"
24 changes: 24 additions & 0 deletions build/aws-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const execSync = require('child_process').execSync;

const isPrBuild = (prBranch) => {
return prBranch && prBranch !== "master";
};

const staticSizeNotTooLarge = (staticBookSize) => {
const tenMB = 10 * (2 << 9);
return !isNaN(staticBookSize) && staticBookSize < tenMB;
};

const {TRAVIS_PULL_REQUEST_BRANCH: prBranch} = process.env;
console.log(prBranch);
if (isPrBuild(prBranch)) {
const result = execSync(`du -sk storybook-static | sed 's/[^0-9]*//g'`);
const staticBookSize = Number.parseInt(result.toString());

if (staticSizeNotTooLarge(staticBookSize)) {
const result = execSync(
`aws s3 cp ${__dirname}/../storybook-static s3://react-audio-vis-prs/${prBranch} --recursive`,
{stdio: [0, 1, 2]}
);
}
}

0 comments on commit 999b0bd

Please sign in to comment.