]> git.lizzy.rs Git - rust.git/blob - .github/deploy.sh
Merge pull request #3265 from mikerite/fix-export
[rust.git] / .github / deploy.sh
1 #!/bin/bash
2
3 # Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13
14 # Automatically deploy on gh-pages
15
16 set -ex
17
18 SOURCE_BRANCH="master"
19 TARGET_BRANCH="gh-pages"
20
21 # Save some useful information
22 REPO=$(git config remote.origin.url)
23 SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
24 SHA=$(git rev-parse --verify HEAD)
25
26 # Clone the existing gh-pages for this repo into out/
27 (
28     git clone "$REPO" out
29     cd out
30     git checkout $TARGET_BRANCH
31 )
32
33 echo "Removing the current docs for master"
34 rm -rf out/master/ || exit 0
35
36 echo "Making the docs for master"
37 mkdir out/master/
38 cp util/gh-pages/index.html out/master
39 python ./util/export.py out/master/lints.json
40
41 if [ -n "$TRAVIS_TAG" ]; then
42     echo "Save the doc for the current tag ($TRAVIS_TAG) and point current/ to it"
43     cp -r out/master "out/$TRAVIS_TAG"
44     rm -f out/current
45     ln -s "$TRAVIS_TAG" out/current
46 fi
47
48 # Generate version index that is shown as root index page
49 (
50     cp util/gh-pages/versions.html out/index.html
51
52     cd out
53     python -c '\
54         import os, json;\
55         print json.dumps([\
56             dir for dir in os.listdir(".")\
57             if not dir.startswith(".") and os.path.isdir(dir)\
58         ])' > versions.json
59 )
60
61 # Pull requests and commits to other branches shouldn't try to deploy, just build to verify
62 if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
63     # Tags should deploy
64     if [ -z "$TRAVIS_TAG" ]; then
65         echo "Generated, won't push"
66         exit 0
67     fi
68 fi
69
70 # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
71 ENCRYPTION_LABEL=e3a2d77100be
72 ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
73 ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
74 ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
75 ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
76 openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in .github/deploy_key.enc -out .github/deploy_key -d
77 chmod 600 .github/deploy_key
78 eval $(ssh-agent -s)
79 ssh-add .github/deploy_key
80
81 # Now let's go have some fun with the cloned repo
82 cd out
83 git config user.name "Travis CI"
84 git config user.email "travis@ci.invalid"
85
86 if [ -z "$(git diff --exit-code)" ]; then
87     echo "No changes to the output on this push; exiting."
88     exit 0
89 fi
90
91 git add .
92 git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
93
94 # Now that we're all set up, we can push.
95 git push "$SSH_REPO" "$TARGET_BRANCH"