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