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