|
| 1 | +#!/bin/bash |
| 2 | +set -e # Exit with nonzero exit code if anything fails |
| 3 | + |
| 4 | +# Settings |
| 5 | +SOURCE_BRANCH="master" |
| 6 | +TARGET_BRANCH="gh-pages" |
| 7 | +SHA=$(git rev-parse --verify HEAD) |
| 8 | +COMMIT_USER_NAME="linksplatform-docs" |
| 9 | +COMMIT_USER_EMAIL="konard@yandex.ru" |
| 10 | +REPOSITORY="github.com/linksplatform/${TRAVIS_REPO_NAME}" |
| 11 | + |
| 12 | +# Pull requests and commits to other branches shouldn't try to deploy, just build to verify |
| 13 | +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then |
| 14 | + echo "Skipping deploy." |
| 15 | + exit 0 |
| 16 | +fi |
| 17 | + |
| 18 | +# Insert repository name into DocFX's configuration files |
| 19 | +sed -i "s/\$TRAVIS_REPO_NAME/${TRAVIS_REPO_NAME}/g" toc.yml |
| 20 | +sed -i "s/\$TRAVIS_REPO_NAME/${TRAVIS_REPO_NAME}/g" docfx.json |
| 21 | + |
| 22 | +# DocFX installation |
| 23 | +nuget install docfx.console |
| 24 | +mono $(ls | grep "docfx.console.")/tools/docfx.exe docfx.json |
| 25 | + |
| 26 | +# Clone the existing gh-pages for this repo into out/ |
| 27 | +# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) |
| 28 | +git clone https://$REPOSITORY out |
| 29 | +cd out |
| 30 | +git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH |
| 31 | +cd .. |
| 32 | + |
| 33 | +# Clean out existing contents |
| 34 | +rm -rf out/**/* || exit 0 |
| 35 | + |
| 36 | +# Copy genereted docs site |
| 37 | +cp -r _site/* out |
| 38 | + |
| 39 | +cd out |
| 40 | + |
| 41 | +# Do not use index.md |
| 42 | +cp README.html index.html |
| 43 | + |
| 44 | +# Now let's go have some fun with the cloned repo |
| 45 | +git config user.name "$COMMIT_USER_NAME" |
| 46 | +git config user.email "$COMMIT_USER_EMAIL" |
| 47 | +git remote rm origin |
| 48 | +git remote add origin https://$COMMIT_USER_NAME:$TOKEN@$REPOSITORY.git |
| 49 | + |
| 50 | +# Commit the "changes", i.e. the new version. |
| 51 | +# The delta will show diffs between new and old versions. |
| 52 | +git add --all |
| 53 | +git commit -m "Deploy to GitHub Pages: ${SHA}" |
| 54 | + |
| 55 | +# Now that we're all set up, we can push. |
| 56 | +git push https://$COMMIT_USER_NAME:$TOKEN@$REPOSITORY.git $TARGET_BRANCH |
0 commit comments