|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e # exit with nonzero exit code if anything fails |
| 4 | + |
| 5 | +# exit with an error if the build fails |
| 6 | +if [[ ${TRAVIS_TEST_RESULT=0} == 1 ]]; then |
| 7 | + exit 1; |
| 8 | +fi |
| 9 | + |
| 10 | +# exit if the branch is wrong |
| 11 | +if [[ ${TRAVIS_BRANCH} =~ (master$|beta$|^v?[0-9]*\.[0-9]*\.[0-9]*$) || ${TRAVIS_EVENT_TYPE} == 'cron' ]]; then |
| 12 | + npm run build |
| 13 | + cd dist |
| 14 | + |
| 15 | + #setup npm publishing |
| 16 | + npm publish |
| 17 | + |
| 18 | + if [[ ${TRAVIS_BRANCH} =~ (master$|beta$|^v?[0-9]*\.[0-9]*\.[0-9]*$) ]]; then |
| 19 | + # Move to the top level folder, and make a "deploy" directory |
| 20 | + cd ../ |
| 21 | + mkdir deploy |
| 22 | + cd deploy |
| 23 | + git init |
| 24 | + |
| 25 | + # Configure Git |
| 26 | + git config user.name "Travis CI" |
| 27 | + git config user.email "[email protected]" |
| 28 | + |
| 29 | + # pull the upstream pages |
| 30 | + git pull "[email protected]:ibm/carbon-components-angular.git" gh-pages |
| 31 | + |
| 32 | + # copy to the master/alpha folder |
| 33 | + if [[ ${TRAVIS_BRANCH} == "master" ]]; then |
| 34 | + cp -R ../demo/bundle/* ./ |
| 35 | + # copy to the beta folder |
| 36 | + elif [[ ${TRAVIS_EVENT_TYPE} == "cron" ]]; then |
| 37 | + mkdir -p beta |
| 38 | + cp -R ../demo/bundle/* beta |
| 39 | + # copy to the version folder |
| 40 | + elif [[ ${TRAVIS_BRANCH} =~ (^v?[0-9]*\.[0-9]*\.[0-9]*$) ]]; then |
| 41 | + mkdir -p $TRAVIS_BRANCH |
| 42 | + cp -R ../demo/bundle/* $TRAVIS_BRANCH |
| 43 | + fi |
| 44 | + |
| 45 | + # in this case we want the script to keep running, so we can actually check the $? (status) var |
| 46 | + set +e |
| 47 | + # Commit all the things into the repo |
| 48 | + git add . |
| 49 | + git commit -m "Deploy to GitHub Pages" |
| 50 | + |
| 51 | + # Force push to gh-pages if there was something to commit |
| 52 | + if [ $? -eq 0 ]; then |
| 53 | + git push --force "[email protected]:ibm/carbon-components-angular.git" master:gh-pages > /dev/null 2>&1 |
| 54 | + fi |
| 55 | + exit 0; |
| 56 | + fi |
| 57 | +else |
| 58 | + echo "Branch type not recognized"; |
| 59 | + echo "Skipping deploy"; |
| 60 | + exit 0; |
| 61 | +fi |
0 commit comments