blob: a04e49258d8d2e1fdec48f134aab4711afb00a25 [file] [log] [blame]
Roman Elizarov9fcb24f2018-03-06 11:25:09 +03001#!/usr/bin/env bash
2
Vsevolod Tolstopyatovf19ae192021-04-21 18:18:18 +03003#
4# Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
5#
6
Roman Elizarov9fcb24f2018-03-06 11:25:09 +03007# Abort on first error
8set -e
9
10# Directories
11SITE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12ROOT_DIR="$SITE_DIR/.."
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030013BUILD_DIR="$ROOT_DIR/build"
14DIST_DIR="$BUILD_DIR/dokka/htmlMultiModule"
Roman Elizarov9fcb24f2018-03-06 11:25:09 +030015PAGES_DIR="$BUILD_DIR/pages"
16
17# Init options
18GRADLE_OPT=
19PUSH_OPT=
20
21# Set dry run if needed
22if [ "$2" == "push" ] ; then
23 echo "--- Doing LIVE site deployment, so do clean build"
24 GRADLE_OPT=clean
25else
26 echo "--- Doing dry-run. To commit do 'deploy.sh <version> push'"
27 PUSH_OPT=--dry-run
28fi
29
30# Makes sure that site is built
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030031"$ROOT_DIR/gradlew" $GRADLE_OPT dokkaHtmlMultiModule
Roman Elizarov9fcb24f2018-03-06 11:25:09 +030032
33# Cleanup dist directory (and ignore errors)
34rm -rf "$PAGES_DIR" || true
35
36# Prune worktrees to avoid errors from previous attempts
37git --work-tree "$ROOT_DIR" worktree prune
38
39# Create git worktree for gh-pages branch
40git --work-tree "$ROOT_DIR" worktree add -B gh-pages "$PAGES_DIR" origin/gh-pages
41
42# Now work in newly created workspace
43cd "$PAGES_DIR"
44
Roman Elizarov3ed9e382018-10-16 12:33:12 +030045# Fixup all the old documentation files
46# Remove non-.html files
47git rm `find . -type f -not -name '*.html' -not -name '.git'` > /dev/null
48
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030049# Remove all the old documentation
50git rm -r * > /dev/null
Roman Elizarov9fcb24f2018-03-06 11:25:09 +030051
52# Copy new documentation from dist
53cp -r "$DIST_DIR"/* "$PAGES_DIR"
54
55# Add it all to git
56git add *
57
58# Commit docs for the new version
59if [ -z "$1" ] ; then
60 echo "No argument with version supplied -- skipping commit"
61else
62 git commit -m "Version $1 docs"
63 git push $PUSH_OPT origin gh-pages:gh-pages
64fi