|
| 1 | +#!/bin/bash |
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the SwiftServiceLauncher open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2020 Apple Inc. and the SwiftServiceLauncher project authors |
| 7 | +## Licensed under Apache License v2.0 |
| 8 | +## |
| 9 | +## See LICENSE.txt for license information |
| 10 | +## See CONTRIBUTORS.txt for the list of SwiftServiceLauncher project authors |
| 11 | +## |
| 12 | +## SPDX-License-Identifier: Apache-2.0 |
| 13 | +## |
| 14 | +##===----------------------------------------------------------------------===## |
| 15 | + |
| 16 | +set -e |
| 17 | + |
| 18 | +my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 19 | +root_path="$my_path/.." |
| 20 | +version=$(git describe --abbrev=0 --tags || echo "0.0.0") |
| 21 | +modules=(ServiceLauncher) |
| 22 | + |
| 23 | +if [[ "$(uname -s)" == "Linux" ]]; then |
| 24 | + # build code if required |
| 25 | + if [[ ! -d "$root_path/.build/x86_64-unknown-linux" ]]; then |
| 26 | + swift build |
| 27 | + fi |
| 28 | + # setup source-kitten if required |
| 29 | + mkdir -p "$root_path/.build/sourcekitten" |
| 30 | + source_kitten_source_path="$root_path/.build/sourcekitten/source" |
| 31 | + if [[ ! -d "$source_kitten_source_path" ]]; then |
| 32 | + git clone https://github.com/jpsim/SourceKitten.git "$source_kitten_source_path" |
| 33 | + fi |
| 34 | + source_kitten_path="$source_kitten_source_path/.build/x86_64-unknown-linux/debug" |
| 35 | + if [[ ! -d "$source_kitten_path" ]]; then |
| 36 | + rm -rf "$source_kitten_source_path/.swift-version" |
| 37 | + cd "$source_kitten_source_path" && swift build && cd "$root_path" |
| 38 | + fi |
| 39 | + # generate |
| 40 | + for module in "${modules[@]}"; do |
| 41 | + if [[ ! -f "$root_path/.build/sourcekitten/$module.json" ]]; then |
| 42 | + "$source_kitten_path/sourcekitten" doc --spm-module $module > "$root_path/.build/sourcekitten/$module.json" |
| 43 | + fi |
| 44 | + done |
| 45 | +fi |
| 46 | + |
| 47 | +jazzy_dir="$root_path/.build/jazzy" |
| 48 | +rm -rf "$jazzy_dir" |
| 49 | +mkdir -p "$jazzy_dir" |
| 50 | + |
| 51 | +# prep index |
| 52 | +module_switcher="$jazzy_dir/README.md" |
| 53 | +cat > "$module_switcher" <<"EOF" |
| 54 | +# SwiftServiceLauncher Docs |
| 55 | +
|
| 56 | +SwiftServiceLauncher provides a basic mechanism to cleanly start up and shut down the application, freeing resources in order before exiting. |
| 57 | +It also provides a Signal based shutdown hook, to shutdown on signals like TERM or INT. |
| 58 | +
|
| 59 | +SwiftServiceLauncher is non-framework specific, designed to be integrated with any server framework or directly in an application. |
| 60 | +
|
| 61 | +To get started with SwiftCrypto, [`import ServiceLauncher`](../ServiceLauncher/index.html). |
| 62 | +EOF |
| 63 | + |
| 64 | +# run jazzy |
| 65 | +if ! command -v jazzy > /dev/null; then |
| 66 | + gem install jazzy --no-ri --no-rdoc |
| 67 | +fi |
| 68 | + |
| 69 | +jazzy_args=(--clean |
| 70 | + --author 'ServiceLauncher team' |
| 71 | + --readme "$module_switcher" |
| 72 | + --author_url https://github.com/swift-server/swift-service-launcher |
| 73 | + --github_url https://github.com/swift-server/swift-service-launcher |
| 74 | + --github-file-prefix https://github.com/swift-server/swift-service-launcher/tree/$version |
| 75 | + --theme fullwidth |
| 76 | + --swift-build-tool spm) |
| 77 | + |
| 78 | +for module in "${modules[@]}"; do |
| 79 | + args=("${jazzy_args[@]}" --output "$jazzy_dir/docs/$version/$module" --docset-path "$jazzy_dir/docset/$version/$module" |
| 80 | + --module "$module" --module-version $version |
| 81 | + --root-url "https://swift-server.github.io/swift-service-launcher/docs/$version/$module/") |
| 82 | + if [[ "$(uname -s)" == "Linux" ]]; then |
| 83 | + args+=(--sourcekitten-sourcefile "$root_path/.build/sourcekitten/$module.json") |
| 84 | + fi |
| 85 | + jazzy "${args[@]}" |
| 86 | +done |
| 87 | + |
| 88 | +# push to github pages |
| 89 | +if [[ $PUSH == true ]]; then |
| 90 | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 91 | + GIT_AUTHOR=$(git --no-pager show -s --format='%an <%ae>' HEAD) |
| 92 | + git fetch origin +gh-pages:gh-pages |
| 93 | + git checkout gh-pages |
| 94 | + rm -rf "docs/$version" |
| 95 | + rm -rf "docs/current" |
| 96 | + cp -r "$jazzy_dir/docs/$version" docs/ |
| 97 | + cp -r "docs/$version" docs/current |
| 98 | + git add --all docs |
| 99 | + echo '<html><head><meta http-equiv="refresh" content="0; url=docs/current/ServiceLauncher/index.html" /></head></html>' > index.html |
| 100 | + git add index.html |
| 101 | + touch .nojekyll |
| 102 | + git add .nojekyll |
| 103 | + changes=$(git diff-index --name-only HEAD) |
| 104 | + if [[ -n "$changes" ]]; then |
| 105 | + echo -e "changes detected\n$changes" |
| 106 | + git commit --author="$GIT_AUTHOR" -m "publish $version docs" |
| 107 | + git push origin gh-pages |
| 108 | + else |
| 109 | + echo "no changes detected" |
| 110 | + fi |
| 111 | + git checkout -f $BRANCH_NAME |
| 112 | +fi |
0 commit comments