forked from Kotlin/kotlinx.serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_docs.sh
executable file
·63 lines (48 loc) · 1.58 KB
/
update_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
#!/usr/bin/env bash
# Abort on first error
set -e
# Directories
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIST_DIR="$ROOT_DIR/build/dokka/htmlMultiModule"
PAGES_DIR="$ROOT_DIR/build/pages"
# Init options
GRADLE_OPT=
PUSH_OPT=
# Set dry run if needed
if [ "$2" == "push" ] ; then
echo "--- Doing LIVE site deployment, so do clean build"
GRADLE_OPT=clean
else
echo "--- Doing dry-run. To commit do 'update_docs.sh <version> push'"
PUSH_OPT=--dry-run
fi
# Makes sure that site is built
"$ROOT_DIR/gradlew" $GRADLE_OPT dokkaHtmlMultiModule
# Cleanup dist directory (and ignore errors)
rm -rf "$PAGES_DIR" || true
# Prune worktrees to avoid errors from previous attempts
git --work-tree "$ROOT_DIR" worktree prune
# Create git worktree for gh-pages branch
git --work-tree "$ROOT_DIR" worktree add -B gh-pages "$PAGES_DIR" origin/gh-pages
# Now work in newly created workspace
cd "$PAGES_DIR"
# Fixup all the old documentation files
# Remove non-.html files
REMOVE_FILES=$(find . -type f -not -name '.git')
if [ "$REMOVE_FILES" != "" ] ; then
git rm $REMOVE_FILES > /dev/null
fi
# Copy manually new documentation and flat out kotlinx-serialization
cp -r "$DIST_DIR"/* "$PAGES_DIR"
# Hack for the GH pages
cp $PAGES_DIR/-modules.html $PAGES_DIR/index.html
# Add it all to git
# git add *
for file in $(find $PAGES_DIR -type f -name '*'); do git add $file; done
# Commit docs for the new version
if [ -z "$1" ] ; then
echo "No argument with version supplied -- skipping commit"
else
git commit -m "Version $1 docs"
git push $PUSH_OPT origin gh-pages:gh-pages
fi