forked from rust-lang-nursery/rust-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·65 lines (52 loc) · 1.88 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
set -o errexit -o nounset
if [ -z "${TRAVIS_BRANCH:-}" ]; then
echo "This script may only be run from Travis!"
exit 1
fi
if [[ "$TRAVIS_BRANCH" != "master" || "$TRAVIS_RUST_VERSION" != "stable" || "$TRAVIS_OS_NAME" != "linux" ]]; then
echo "This commit was made against '$TRAVIS_BRANCH' with '$TRAVIS_RUST_VERSION' on '$TRAVIS_OS_NAME'."
echo "Instead of 'master' branch with 'stable' on 'linux'!"
echo "Not deploying!"
exit 0
fi
# check for outdated dependencies on nightly builds
if [ "${TRAVIS_EVENT_TYPE:-}" == "cron" ]; then
echo "This is cron build. Checking for outdated dependencies!"
rm ./Cargo.lock
cargo clean
# replace all [dependencies] versions with "*"
sed -i -e "/^\[dependencies\]/,/^\[.*\]/ s|^\(.*=[ \t]*\).*$|\1\"\*\"|" ./Cargo.toml
cargo test || { echo "Cron build failed! Dependencies outdated!"; exit 1; }
echo "Cron build success! Dependencies are up to date!"
exit 0
fi
# Returns 1 if program is installed and 0 otherwise
program_installed() {
local return_=1
type $1 >/dev/null 2>&1 || { local return_=0; }
echo "$return_"
}
# Ensure required programs are installed
if [ $(program_installed git) == 0 ]; then
echo "Please install Git."
exit 1
elif [ $(program_installed mdbook) == 0 ]; then
echo "Please install mdbook: cargo install mdbook."
exit 1
fi
echo "Building site to book/"
mdbook build
echo "Copying assets/* to book/"
cp -r assets/ book/
echo "Committing book directory to gh-pages branch"
REV=$(git rev-parse --short HEAD)
cd book
git init
git remote add upstream "https://[email protected]/rust-lang-nursery/rust-cookbook.git"
git config user.name "Rust Cookbook"
git config user.email "[email protected]"
git add -A .
git commit -qm "Build cookbook at ${TRAVIS_REPO_SLUG}@${REV}"
echo "Pushing gh-pages to GitHub"
git push -q upstream HEAD:refs/heads/gh-pages --force