3 # Automatically deploy on gh-pages
8 TARGET_BRANCH="gh-pages"
10 # Save some useful information
11 REPO=$(git config remote.origin.url)
12 SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
13 SHA=$(git rev-parse --verify HEAD)
15 # Clone the existing gh-pages for this repo into out/
16 git clone --quiet --single-branch --branch "$TARGET_BRANCH" "$REPO" out
18 echo "Removing the current docs for master"
19 rm -rf out/master/ || exit 0
21 echo "Making the docs for master"
23 cp util/gh-pages/index.html out/master
24 python ./util/export.py out/master/lints.json
26 if [[ -n "$TRAVIS_TAG" ]]; then
27 echo "Save the doc for the current tag ($TRAVIS_TAG) and point current/ to it"
28 cp -r out/master "out/$TRAVIS_TAG"
30 ln -s "$TRAVIS_TAG" out/current
33 # Generate version index that is shown as root index page
34 cp util/gh-pages/versions.html out/index.html
37 cat <<-EOF | python - > versions.json
40 dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir)
45 # Pull requests and commits to other branches shouldn't try to deploy, just build to verify
46 if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] || [[ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]]; then
48 if [[ -z "$TRAVIS_TAG" ]]; then
49 echo "Generated, won't push"
54 # Now let's go have some fun with the cloned repo
56 git config user.name "Travis CI"
57 git config user.email "travis@ci.invalid"
59 if git diff --exit-code --quiet; then
60 echo "No changes to the output on this push; exiting."
65 # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
66 ENCRYPTION_LABEL=e3a2d77100be
67 ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
68 ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
69 ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
70 ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
71 openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
72 chmod 600 .github/deploy_key
73 eval "$(ssh-agent -s)"
74 ssh-add .github/deploy_key
78 git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
80 # Now that we're all set up, we can push.
81 git push "$SSH_REPO" "$TARGET_BRANCH"