From 999b0bd5761da386166f4e14138ae4a29747499d Mon Sep 17 00:00:00 2001 From: Michael James Date: Sat, 3 Jun 2017 14:00:56 +1000 Subject: [PATCH] chore(storybook): Added publishing of PR storybook to S3 bucket --- .gitignore | 1 - .travis.yml | 14 ++++++++++++++ build/aws-deploy.js | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 build/aws-deploy.js diff --git a/.gitignore b/.gitignore index 047e1fc..b4a5e83 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ /coverage # production -/build /dist # misc diff --git a/.travis.yml b/.travis.yml index 0f63747..107da03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/build/aws-deploy.js b/build/aws-deploy.js new file mode 100644 index 0000000..2e26488 --- /dev/null +++ b/build/aws-deploy.js @@ -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]} + ); + } +}