Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / build / scripts / publish-api-docs.sh
1 #!/bin/bash
2
3 # Test for master branch, or other branches matching 0.x, 1.x, etc.
4 BRANCH_REGEX='^\(master\|9\.[0-9x.]*\)$'
5
6 # Check to make sure that our build environment is right. Skip with no error otherwise.
7 test -n "$TRAVIS"                             || { echo "This script is only designed to be run on Travis."; exit 0; }
8 echo "$TRAVIS_BRANCH" | grep -q $BRANCH_REGEX || { echo "Skipping docs update for branch $TRAVIS_BRANCH - docs only updated for master branch and tagged builds."; exit 0; }
9 test "$TRAVIS_PULL_REQUEST" == "false"        || { echo "Skipping docs update -- not done on pull requests. (PR #$TRAVIS_PULL_REQUEST)"; exit 0; }
10 test "${TRAVIS_PHP_VERSION:0:1}" == "7"     || { echo "Skipping docs update for PHP $TRAVIS_PHP_VERSION -- only update for PHP 7 builds."; exit 0; }
11 test "$TRAVIS_REPO_SLUG" == "drush-ops/drush"   || { echo "Skipping docs update for repository $TRAVIS_REPO_SLUG -- do not build docs for forks."; exit 0; }
12
13 # Check our requirements for running this script have been met.
14 test -n "$GITHUB_TOKEN"                       || { echo "GITHUB_TOKEN environment variable must be set to run this script."; exit 1; }
15 test -n "$(git config --global user.email)"   || { echo 'Git user email not set. Use `git config --global user.email EMAIL`.'; exit 1; }
16 test -n "$(git config --global user.name)"    || { echo 'Git user name not set. Use `git config --global user.name NAME`.'; exit 1; }
17
18 # Ensure that we exit on failure, and echo lines as they are executed.
19 # We don't need to see our sanity-checks get echoed, so we turn this on after they are done.
20 set -ev
21
22 # Install Sami using the install script in composer.json
23 composer sami-install
24
25 # Build the API documentation using the api script in composer.json
26 # We have Sami parse errors so ignore return value: https://stackoverflow.com/questions/35452147/allow-non-zero-return-codes-in-travis-ci-yml
27 composer -v api || true
28
29 echo "Create build $API_BUID_DIR dir if needed."
30
31 # Check out the gh-pages branch using our Github token (defined at https://travis-ci.org/lcache/lcache/settings)
32 API_BUILD_DIR="$HOME/.drush-build/gh-pages"
33 if [ ! -d "$API_BUILD_DIR" ]
34 then
35   mkdir -p "$(dirname $API_BUILD_DIR)"
36   git clone --quiet --branch=gh-pages https://${GITHUB_TOKEN}@github.com/drush-ops/drush "$API_BUILD_DIR" > /dev/null
37 fi
38
39 # Replace the old 'api' folder with the newly-built API documentation
40 rm -rf "$API_BUILD_DIR/api"
41 cp -R api "$API_BUILD_DIR"
42
43 echo "Commit new API docs."
44
45 # Commit any changes to the documentation
46 cd "$API_BUILD_DIR"
47 git add -A api
48 git commit -m "Update API documentation from Travis build $TRAVIS_BUILD_NUMBER, '$TRAVIS_COMMIT'."
49 git push