forked from djmuhlestein/fx2lib
-
Notifications
You must be signed in to change notification settings - Fork 6
/
.travis-push-docs.sh
executable file
·103 lines (88 loc) · 3.12 KB
/
.travis-push-docs.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -e
if [ "$TRAVIS" = true -a "$TRAVIS_SECURE_ENV_VARS" = false ]; then
echo "No environment variables found, skipping (probably a pull request)."
exit 0
fi
if [ "$TRAVIS" = true -a "$TRAVIS_BRANCH" != "master" ]; then
echo "No master branch, skipping."
exit 0
fi
if [ -z "$TRAVIS_REPO_SLUG" ]; then
echo "No TRAVIS_REPO_SLUG value found."
echo "Please set this if running outside Travis."
exit 0
fi
# FIXME: Replace this with a deploy key, so you don't end up with tokens which
# potentially give people *a lot* of access to your GitHub repos.
if [ -z "$GH_TOKEN" ]; then
echo "No GH_TOKEN value found."
echo
echo "Generate a GitHub token at https://github.com/settings/tokens/new"
echo "with *only* the public_repo option."
echo "Then go to https://travis-ci.org/$TRAVIS_REPO_SLUG/settings and"
echo "add an 'Environment Variables' with the following;"
echo " * Name == GH_TOKEN"
echo " * Value == your token value from above"
echo " * Display value in build log == OFF"
echo
echo "It is important that you protect this token, as it has full push"
echo "access to your repos!"
exit 1
fi
if [ -z "$GIT_NAME" ]; then
echo "No GIT_NAME value found."
echo
echo "Then go to https://travis-ci.org/$TRAVIS_REPO_SLUG/settings and"
echo "add an 'Environment Variables' with the following;"
echo " * Name == GIT_NAME"
echo " * Value == Human readable name for the commit author."
echo " Something like \"Tim Ansell's Robot\" is a good choice."
echo " * Display value in build log == ON"
exit 1
fi
if [ -z "$GIT_EMAIL" ]; then
echo "No GIT_EMAIL value found."
echo
echo "Then go to https://travis-ci.org/$TRAVIS_REPO_SLUG/settings and"
echo "add an 'Environment Variables' with the following;"
echo " * Name == GIT_EMAIL"
echo " * Value == Email address the commit author."
echo " Set up an email address, or use your own."
echo " * Display value in build log == ON"
exit 1
fi
TMPDIR=$(mktemp --directory)
if ! git describe > /dev/null 2>&1; then
echo "- Fetching non shallow to get git version"
git fetch --unshallow && git fetch --tags
fi
ORIG_GIT_REVISION=`git describe`
ORIG_COMMITTER_NAME=$(git log -1 --pretty=%an)
ORIG_COMMITTER_EMAIL=$(git log -1 --pretty=%ae)
echo "- Setting up the output"
cp -aRf docs/html/* $TMPDIR/
cp docs/intro/intro.pdf $TMPDIR/
find $TMPDIR | sort
echo "- Switching to the gh-pages branch"
git remote set-branches --add origin gh-pages
git fetch origin gh-pages
git checkout origin/gh-pages -b gh-pages
echo "- Updating the README"
sed -e"s-github.com/[^/]\+/[^/ ]\+-github.com/$TRAVIS_REPO_SLUG-" README.md > $TMPDIR/README.md
cat $TMPDIR/README.md
echo "- Adding the newly generated content"
rm -rf *
cp -aRf $TMPDIR/* .
git add -v -A .
echo "- Committing"
export GIT_AUTHOR_EMAIL="$ORIG_COMMITTER_EMAIL"
export GIT_AUTHOR_NAME="$ORIG_COMMITTER_NAME"
export GIT_COMMITTER_EMAIL="$GIT_NAME"
export GIT_COMMITTER_NAME="$GIT_EMAIL"
unset GIT_NAME
unset GIT_EMAIL
git commit -a -m "Travis build #$TRAVIS_BUILD_NUMBER of $ORIG_GIT_REVISION"
echo "- Pushing"
git remote set-url origin https://[email protected]/$TRAVIS_REPO_SLUG.git > /dev/null 2>&1
git push origin gh-pages > /dev/null 2>&1