Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 7f02ebc

Browse files
committed
Upload apidoc to gh-pages
1 parent dd446e0 commit 7f02ebc

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ git:
1414

1515
jobs:
1616
include:
17+
- name: "Upload API documentation"
18+
env: TARGET=doc
19+
if: repo = "tarantool/graphql" AND branch = master AND type = push
1720
- name: "CentOS 6: test, deploy RPM"
1821
env: TARGET=pack OS=el DIST=6
1922
- name: "CentOS 7: test, deploy RPM"
@@ -47,6 +50,9 @@ script:
4750
elif [ "${TARGET}" = test ]; then
4851
./tools/ubuntu.trusty.prepare.sh
4952
make test
53+
elif [ "${TARGET}" = doc ]; then
54+
./tools/ubuntu.trusty.prepare.sh
55+
./tools/upload_apidoc.sh
5056
else
5157
exit 1
5258
fi

.travis/deploy_apidoc.enc

3.33 KB
Binary file not shown.

tools/upload_apidoc.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
3+
# Based on https://github.com/tarantool/tarantool-c/blob/463a244e7cbee1ec4b7a9682fa46705cbf5a49f2/documentation.sh
4+
5+
set -exuo pipefail # Strict shell
6+
7+
SOURCE_BRANCH="master"
8+
TARGET_BRANCH="gh-pages"
9+
OUTPUT_PATH="$TRAVIS_BUILD_DIR/doc/apidoc"
10+
COMMIT_AUTHOR_NAME="Travis CI"
11+
COMMIT_AUTHOR_EMAIL="[email protected]"
12+
DEPLOY_KEY_ENC=".travis/deploy_apidoc.enc"
13+
14+
function do_compile {
15+
make apidoc
16+
}
17+
18+
# 'git checkout --orphan' leaves a new branch w/o a commit, the next one will
19+
# be the first
20+
function has_commit {
21+
git rev-parse --verify --quiet HEAD
22+
return $?
23+
}
24+
25+
# 'git diff --quiet' replacement with 'Last update' changes ignoring
26+
function no_modified {
27+
set +x
28+
tmpdir=$(mktemp -d)
29+
echo -e '#!/bin/sh\n\ndiff -r -U 1 -I "Last updated" "$@"\nexit 0' \
30+
> "$tmpdir/diff_cmd.sh"
31+
chmod a+x "$tmpdir/diff_cmd.sh"
32+
res="$(git difftool --dir-diff --extcmd "$tmpdir/diff_cmd.sh" 2>/dev/null)"
33+
rm "$tmpdir/diff_cmd.sh"
34+
rmdir $tmpdir
35+
[ -z "$res" ]
36+
rc=$?
37+
set -x
38+
return $rc
39+
}
40+
41+
function no_untracked {
42+
set +x
43+
res="$(git ls-files -o --exclude-standard)"
44+
[ -z "$res" ]
45+
rc=$?
46+
set -x
47+
return $rc
48+
}
49+
50+
# Pull requests and commits to other branches shouldn't try to deploy, just
51+
# build to verify
52+
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || \
53+
[ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ] || \
54+
[ "$TRAVIS_EVENT_TYPE" != "push" ]; then
55+
echo "upload_apidoc.sh: Skipping deploy; just doing a build."
56+
do_compile
57+
exit 0
58+
fi
59+
60+
# Save some useful information
61+
REPO=$(git config remote.origin.url)
62+
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
63+
MSG="$(git log --oneline --no-decorate -1)"
64+
65+
# Clone the existing gh-pages for this repo into $OUTPUT_PATH
66+
# Create a new empty branch if gh-pages doesn't exist yet (should only happen
67+
# on first deploy)
68+
git clone $REPO $OUTPUT_PATH
69+
cd $OUTPUT_PATH
70+
if ! git checkout $TARGET_BRANCH; then
71+
git checkout --orphan $TARGET_BRANCH
72+
git rm -rf .
73+
fi
74+
cd $TRAVIS_BUILD_DIR
75+
76+
# Clean out existing contents
77+
tmpdir=$(mktemp -d)
78+
mv $OUTPUT_PATH/.git $tmpdir/.git
79+
rm -rf $OUTPUT_PATH && mkdir $OUTPUT_PATH
80+
mv $tmpdir/.git $OUTPUT_PATH/.git
81+
rmdir $tmpdir
82+
83+
# Run our compile script
84+
do_compile
85+
86+
# Now let's go have some fun with the cloned repo
87+
cd $OUTPUT_PATH
88+
git config user.name "$COMMIT_AUTHOR_NAME"
89+
git config user.email "$COMMIT_AUTHOR_EMAIL"
90+
91+
# If there are no changes to the compiled out (e.g. this is a README update)
92+
# then just bail. Commit unconditionally if there are no commits on the branch
93+
# (after git checkout --orphan).
94+
if has_commit && no_modified && no_untracked; then
95+
echo "upload_apidoc.sh: No changes to the output on this push; exiting."
96+
exit 0
97+
fi
98+
99+
# Commit the "changes", i.e. the new version.
100+
# The delta will show diffs between new and old versions.
101+
git add --all .
102+
git status
103+
git commit -m "apidoc build: ${MSG}"
104+
105+
# Get the deploy key by using Travis's stored variables to decrypt deploy_apidoc.enc
106+
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
107+
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
108+
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
109+
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
110+
DEPLOY_KEY="${DEPLOY_KEY_ENC%.enc}"
111+
ENCRYPTED_KEY_PATH="${TRAVIS_BUILD_DIR}/${DEPLOY_KEY_ENC}"
112+
DECRYPTED_KEY_PATH="${TRAVIS_BUILD_DIR}/${DEPLOY_KEY}"
113+
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in "$ENCRYPTED_KEY_PATH" -out "$DECRYPTED_KEY_PATH" -d
114+
chmod 600 "${DECRYPTED_KEY_PATH}"
115+
eval $(ssh-agent -s)
116+
ssh-add "${DECRYPTED_KEY_PATH}"
117+
118+
# Now that we're all set up, we can push.
119+
git push $SSH_REPO $TARGET_BRANCH

0 commit comments

Comments
 (0)