]> git.lizzy.rs Git - rust.git/blob - .github/deploy.sh
Auto merge of #3645 - phansch:remove_copyright_headers, r=oli-obk
[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 (
17     git clone "$REPO" out
18     cd out
19     git checkout $TARGET_BRANCH
20 )
21
22 echo "Removing the current docs for master"
23 rm -rf out/master/ || exit 0
24
25 echo "Making the docs for master"
26 mkdir out/master/
27 cp util/gh-pages/index.html out/master
28 python ./util/export.py out/master/lints.json
29
30 if [ -n "$TRAVIS_TAG" ]; then
31     echo "Save the doc for the current tag ($TRAVIS_TAG) and point current/ to it"
32     cp -r out/master "out/$TRAVIS_TAG"
33     rm -f out/current
34     ln -s "$TRAVIS_TAG" out/current
35 fi
36
37 # Generate version index that is shown as root index page
38 (
39     cp util/gh-pages/versions.html out/index.html
40
41     cd out
42     python -c '\
43         import os, json;\
44         print json.dumps([\
45             dir for dir in os.listdir(".")\
46             if not dir.startswith(".") and os.path.isdir(dir)\
47         ])' > versions.json
48 )
49
50 # Pull requests and commits to other branches shouldn't try to deploy, just build to verify
51 if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
52     # Tags should deploy
53     if [ -z "$TRAVIS_TAG" ]; then
54         echo "Generated, won't push"
55         exit 0
56     fi
57 fi
58
59 # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
60 ENCRYPTION_LABEL=e3a2d77100be
61 ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
62 ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
63 ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
64 ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
65 openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
66 chmod 600 .github/deploy_key
67 eval $(ssh-agent -s)
68 ssh-add .github/deploy_key
69
70 # Now let's go have some fun with the cloned repo
71 cd out
72 git config user.name "Travis CI"
73 git config user.email "travis@ci.invalid"
74
75 if [ -z "$(git diff --exit-code)" ]; then
76     echo "No changes to the output on this push; exiting."
77     exit 0
78 fi
79
80 git add .
81 git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
82
83 # Now that we're all set up, we can push.
84 git push "$SSH_REPO" "$TARGET_BRANCH"