]> git.lizzy.rs Git - rust.git/blob - .github/deploy.sh
added changelog entry
[rust.git] / .github / deploy.sh
1 #!/bin/bash
2 # Automatically deploy on gh-pages
3
4 set -e
5
6 SOURCE_BRANCH="master"
7 TARGET_BRANCH="gh-pages"
8
9 # Save some useful information
10 REPO=$(git config remote.origin.url)
11 SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
12 SHA=$(git rev-parse --verify HEAD)
13
14 # Clone the existing gh-pages for this repo into out/
15 (
16     git clone "$REPO" out
17     cd out
18     git checkout $TARGET_BRANCH
19 )
20
21 # Remove the current doc for master
22 rm -rf out/master/ || exit 0
23
24 # Make the doc for master
25 mkdir out/master/
26 cp util/gh-pages/index.html out/master
27 python ./util/export.py out/master/lints.json
28
29 # Save the doc for the current tag and point current/ to it
30 if [ -n "$TRAVIS_TAG" ]; then
31     cp -r out/master "out/$TRAVIS_TAG"
32     rm -f out/current
33     ln -s "$TRAVIS_TAG" out/current
34 fi
35
36 # Pull requests and commits to other branches shouldn't try to deploy, just build to verify
37 if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
38     # Tags should deploy
39     if [ -z "$TRAVIS_TAG" ]; then
40         echo "Generated, won't push"
41         exit 0
42     fi
43 fi
44
45 # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
46 ENCRYPTION_LABEL=e3a2d77100be
47 ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
48 ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
49 ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
50 ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
51 openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
52 chmod 600 .github/deploy_key
53 eval $(ssh-agent -s)
54 ssh-add .github/deploy_key
55
56 # Now let's go have some fun with the cloned repo
57 cd out
58 git config user.name "Travis CI"
59 git config user.email "travis@ci.invalid"
60
61 if [ -z "$(git diff --exit-code)" ]; then
62     echo "No changes to the output on this push; exiting."
63     exit 0
64 fi
65
66 git add .
67 git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
68
69 # Now that we're all set up, we can push.
70 git push "$SSH_REPO" "$TARGET_BRANCH"