]> git.lizzy.rs Git - rust.git/blob - .github/deploy.sh
Fix master deployment
[rust.git] / .github / deploy.sh
1 #!/bin/bash
2
3 # Automatically deploy on gh-pages
4
5 set -ex
6
7 SOURCE_BRANCH="master"
8 TARGET_BRANCH="gh-pages"
9
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)
14
15 # Clone the existing gh-pages for this repo into out/
16 git clone --quiet --single-branch --branch "$TARGET_BRANCH" "$REPO" out
17
18 echo "Removing the current docs for master"
19 rm -rf out/master/ || exit 0
20
21 echo "Making the docs for master"
22 mkdir out/master/
23 cp util/gh-pages/index.html out/master
24 python ./util/export.py out/master/lints.json
25
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"
29     rm -f out/current
30     ln -s "$TRAVIS_TAG" out/current
31 fi
32
33 # Generate version index that is shown as root index page
34 cp util/gh-pages/versions.html out/index.html
35 pushd out
36
37 cat <<-EOF | python - > versions.json
38 import os, json
39 print json.dumps([
40     dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir)
41 ])
42 EOF
43 popd
44
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
47     # Tags should deploy
48     if [[ -z "$TRAVIS_TAG" ]]; then
49         echo "Generated, won't push"
50         exit 0
51     fi
52 fi
53
54 # Now let's go have some fun with the cloned repo
55 cd out
56 git config user.name "Travis CI"
57 git config user.email "travis@ci.invalid"
58
59 if git diff --exit-code --quiet; then
60     echo "No changes to the output on this push; exiting."
61     exit 0
62 fi
63 cd -
64
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
75
76 git add .
77 git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
78
79 # Now that we're all set up, we can push.
80 git push "$SSH_REPO" "$TARGET_BRANCH"