diff --git a/.travis.yml b/.travis.yml index 8feabeb1..e65c528b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,9 @@ language: node_js script: "./scripts/test" branches: only: - - master + - master + +matrix: + include: + - name: "[Documentation] Deploy" + script: "./scripts/travis/deploy" diff --git a/docs/scripts/deploy b/docs/scripts/deploy index 9b4fef5f..7c401b9f 100755 --- a/docs/scripts/deploy +++ b/docs/scripts/deploy @@ -1,13 +1,7 @@ #!/usr/bin/env sh set -e -yarn run lint - rm -rf ./dist yarn run build -# Add the date of last deploy, so the automatic deployment know if it needs to -# override it or not (check ./scripts/netflify-master) -date +%s > ./dist/last_update - gh-pages -d dist diff --git a/scripts/travis/changes-in-docs-since-master b/scripts/travis/changes-in-docs-since-master new file mode 100755 index 00000000..7edb5a33 --- /dev/null +++ b/scripts/travis/changes-in-docs-since-master @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Check if the current git repo has changes done in the ./docs folder since last +# push to master +CHANGES_IN_DOCS="$(git diff --name-only master | grep '^docs/')" +if [ "$CHANGES_IN_DOCS" = "" ]; then + exit 1 +fi +exit 0 diff --git a/scripts/travis/deploy b/scripts/travis/deploy new file mode 100755 index 00000000..3c2f6657 --- /dev/null +++ b/scripts/travis/deploy @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Will deploy the documentation website on gh-pages when new commits on master +# Only if it detects changes in ./docs folder +# Note that this will be triggered even for PR targeting master +set -x + +if ./scripts/travis/is-pr; then + echo "✘ Documentation is not deployed for pull requests"; + exit 0 +fi + +if ! ./scripts/travis/on-master; then + echo "✘ Documentation is only deployed on the master branch"; + exit 0 +fi + +if ! ./scripts/travis/changes-in-docs-since-master; then + echo "✘ Documentation is not deployed if their are no changes in ./docs"; + exit 0 +fi + +cd ./docs || exit 1 +yarn install +yarn run deploy diff --git a/scripts/travis/is-pr b/scripts/travis/is-pr new file mode 100755 index 00000000..5baa2b99 --- /dev/null +++ b/scripts/travis/is-pr @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# Check if in a Pull Request +if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then + exit 0 +fi +exit 1 diff --git a/scripts/travis/on-master b/scripts/travis/on-master new file mode 100755 index 00000000..2d93085c --- /dev/null +++ b/scripts/travis/on-master @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Check if on master +if [ "$TRAVIS_BRANCH" = "master" ]; then + exit 0 +fi + +exit 1