From 2abd6792fde0b703cc305865142fbdde00f683df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 7 Aug 2017 12:01:12 +0200 Subject: [PATCH] chore(deploy): Setup auto deployment to gh-pages (#128) --- .travis.yml | 11 ++++----- deploy_key.enc | Bin 0 -> 3248 bytes docs/deploy.sh | 63 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 deploy_key.enc diff --git a/.travis.yml b/.travis.yml index a55a176..c52fb41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: node_js cache: yarn +env: + global: + - ENCRYPTION_LABEL "efa09eced906" + - COMMIT_AUTHOR_EMAIL "gh-bot@callstack.io" node_js: - 'stable' before_install: @@ -12,9 +16,4 @@ install: script: - yarn run flow -- check - yarn run lint -deploy: - provider: script - script: docs/deploy.sh - skip_cleanup: true - on: - branch: master + - cd docs && bash ./deploy.sh diff --git a/deploy_key.enc b/deploy_key.enc new file mode 100644 index 0000000000000000000000000000000000000000..4e5dad4f51e1a891395968bd1f968a383430dacc GIT binary patch literal 3248 zcmV;h3{Ufo7u-78lfsRQH4pmrb7 zGrIDDWVk=Wtc0wy3yh-Dz;8#PuYT8=dU<2c!;Zy$m=jn~4-JK{cS|#F_U~qgAp4k1LPPD)_3zFWZB0q0u z#3t9Q5H3r@9cmj17ubu`Y}>&2Cw(?uJDiQ0bO$=D1G0O$tKbe9OH$RYR=6k?9H^)` z)A$;Q47S1l@+FkR*b9G=gXC+rB|2IMW-S|TkDit=(gF&Wv!!MxF#G4ZAr%(j+u;kS zm?eEuyLQ~N2@0}0Sh3RNUZ2LkCN-4 z;)`*e^HVa$@438d7yU2}!KW^zj2(!jk-LaICZ3Zc;J+~`rFLx5b6mr6eQNQzxrsB3 z9h|G>Vi-L@+S?2L=0~Yynitmh36$v(!ly-DG%^uiVCRWuY`iQs6$cu7D#xK)6t1Z& zzuMcSpxY>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s`5u5lw^~_?|7>!u6!o-Sj61vGbkg3MY$?O69~w7Dt7@h*#GQ z1L@|oKb2j&l$f|4xYneYDg)OuRX@#vIiq}rd{WVLe!F;Z zC2jfec^-EC4{2G@me#13rz=G*%9!>>z3f><{4q`U<5Dk^ zyA&eP-i^7#YegFdPyq*b4rbz=JX~^dUD-}x270yPcSNNwuS%aMtv)eYF$Yl+wIDym zfZwk2Oh_M&!s|vAY$^2lcxH~C`9X9Pk55=0Iu#G5bqOI~IZr1r>H$UAM6iC(qj#cw zk*=xhpZGNa|3_2auPg4YN@vD$D3+=`j@GLq@lgbo$E)Qfuf9xrG~Uzqowk4zSB)Vm zLif!91WF|JV=JOA0I?n}%fnkckInlpBZ59U1MG1~8J5=;;wRh6QJjj5(ht2J9W{+5 z>Mv*r;!U@9Rd1*E(oi)5EHCqRZ{fiRM*?}MP#LdRh&0$3sb5u!+)KTfuHw{-#rFTCD$WZ; zYv@rv(r@>T5~%bm@`SwO^F#|CDDsWIqieSeFb{A(Uf9#x!4@^~+NJdBi literal 0 HcmV?d00001 diff --git a/docs/deploy.sh b/docs/deploy.sh index e2b7209..6857fdf 100755 --- a/docs/deploy.sh +++ b/docs/deploy.sh @@ -1,25 +1,64 @@ #!/bin/bash +# Based on domenic's tutorial: https://gist.github.com/domenic/ec8b0fc8ab45f39403dd +set -e # Exit with nonzero exit code if anything fails -set -e +SOURCE_BRANCH="master" +TARGET_BRANCH="gh-pages" -git clone https://${GITHUB_TOKEN}@github.com/callstack-io/react-native-paper.git docs/dist +function doCompile { + npm run build +} -cd docs/dist +# Pull requests and commits to other branches shouldn't try to deploy, just build to verify +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then + echo "Skipping deploy; just doing a build." + doCompile + exit 0 +fi -git checkout gh-pages -rm -rf ** +# Save some useful information +REPO=`git config remote.origin.url` +SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} +SHA=`git rev-parse --verify HEAD` -cd .. && npm run build && cd dist +# Clone the existing gh-pages for this repo into dist/ +# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) +git clone $REPO dist +cd dist +git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH +cd .. -if [ -z "$(git diff --exit-code)" ]; then +# Clean dist existing contents +rm -rf dist/**/* || exit 0 + +# Run our compile script +doCompile + +# Now let's go have some fun with the cloned repo +cd dist +git config user.name "Travis CI" +git config user.email "$COMMIT_AUTHOR_EMAIL" + +# If there are no changes to the compiled dist (e.g. this is a README update) then just bail. +if git diff --quiet; then echo "No changes to the output on this push; exiting." exit 0 fi -git config user.name "Travis CI" -git config user.email "bot@travis-ci.org" - +# Commit the "changes", i.e. the new version. +# The delta will show diffs between new and old versions. git add -A . -git commit -m "Deploy documentation: $(git rev-parse --verify HEAD)" +git commit -m "Deploy to GitHub Pages: ${SHA}" -git push -f -u origin gh-pages +# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc +ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" +ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" +ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} +ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} +openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d +chmod 600 ../deploy_key +eval `ssh-agent -s` +ssh-add deploy_key + +# Now that we're all set up, we can push. +git push $SSH_REPO $TARGET_BRANCH