|
| 1 | +#!/bin/bash |
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the Swift Distributed Tracing open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2020 Apple Inc. and the Swift Distributed Tracing project authors |
| 7 | +## Licensed under Apache License v2.0 |
| 8 | +## |
| 9 | +## See LICENSE.txt for license information |
| 10 | +## |
| 11 | +## SPDX-License-Identifier: Apache-2.0 |
| 12 | +## |
| 13 | +##===----------------------------------------------------------------------===## |
| 14 | + |
| 15 | +set -e |
| 16 | + |
| 17 | +my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 18 | +declare -r root_path="$my_path/.." |
| 19 | +version=$(git describe --abbrev=0 --tags || echo "0.0.0") |
| 20 | +declare -r modules=(Instrumentation Tracing TracingOpenTelemetrySupport) |
| 21 | +main_module="Tracing" |
| 22 | +declare -r project_xcodeproj_name="swift-distributed-tracing" |
| 23 | +declare -r project_gh_name="swift-distributed-tracing" |
| 24 | + |
| 25 | +if [[ "$(uname -s)" == "Linux" ]]; then |
| 26 | + # build code if required |
| 27 | + if [[ ! -d "$root_path/.build/x86_64-unknown-linux-gnu" ]]; then |
| 28 | + swift build |
| 29 | + fi |
| 30 | + # setup source-kitten if required |
| 31 | + source_kitten_source_path="$root_path/.build/.SourceKitten" |
| 32 | + if [[ ! -d "$source_kitten_source_path" ]]; then |
| 33 | + git clone https://github.com/jpsim/SourceKitten.git "$source_kitten_source_path" |
| 34 | + fi |
| 35 | + source_kitten_path="$source_kitten_source_path/.build/x86_64-unknown-linux-gnu/debug" |
| 36 | + if [[ ! -d "$source_kitten_path" ]]; then |
| 37 | + rm -rf "$source_kitten_source_path/.swift-version" |
| 38 | + cd "$source_kitten_source_path" && swift build && cd "$root_path" |
| 39 | + fi |
| 40 | + # generate |
| 41 | + mkdir -p "$root_path/.build/sourcekitten" |
| 42 | + for module in "${modules[@]}"; do |
| 43 | + if [[ ! -f "$root_path/.build/sourcekitten/$module.json" ]]; then |
| 44 | + "$source_kitten_path/sourcekitten" doc --spm --module-name $module > "$root_path/.build/sourcekitten/$module.json" |
| 45 | + fi |
| 46 | + done |
| 47 | +fi |
| 48 | + |
| 49 | +[[ -d docs/$version ]] || mkdir -p docs/$version |
| 50 | +[[ -d "$project_xcodeproj_name.xcodeproj" ]] || swift package generate-xcodeproj |
| 51 | + |
| 52 | +# run jazzy |
| 53 | +if ! command -v jazzy > /dev/null; then |
| 54 | + gem install jazzy --no-ri --no-rdoc |
| 55 | +fi |
| 56 | + |
| 57 | +jazzy_dir="$root_path/.build/jazzy" |
| 58 | +rm -rf "$jazzy_dir" |
| 59 | +mkdir -p "$jazzy_dir" |
| 60 | + |
| 61 | +module_switcher="$jazzy_dir/README.md" |
| 62 | +jazzy_args=(--clean |
| 63 | + --author 'Swift Distributed Tracing team' |
| 64 | + --readme "$module_switcher" |
| 65 | + --author_url https://github.com/apple/$project_gh_name |
| 66 | + --github_url https://github.com/apple/$project_gh_name |
| 67 | + --github-file-prefix https://github.com/apple/$project_gh_name/tree/$version |
| 68 | + --theme fullwidth |
| 69 | + --xcodebuild-arguments -scheme,$project_xcodeproj_name-Package) |
| 70 | +cat > "$module_switcher" <<"EOF" |
| 71 | +# Swift Distributed Tracing Baggage Docs |
| 72 | +
|
| 73 | +This project contains modules: |
| 74 | +EOF |
| 75 | + |
| 76 | +for module in "${modules[@]}"; do |
| 77 | + echo " - [$module](../$module/index.html)" >> "$module_switcher" |
| 78 | +done |
| 79 | + |
| 80 | +for module in "${modules[@]}"; do |
| 81 | + echo "processing $module" |
| 82 | + args=("${jazzy_args[@]}" --output "$jazzy_dir/docs/$version/$module" --docset-path "$jazzy_dir/docset/$version/$module" |
| 83 | + --module "$module" --module-version $version |
| 84 | + --root-url "https://apple.github.io/$project_gh_name/docs/$version/$module/") |
| 85 | + if [[ -f "$root_path/.build/sourcekitten/$module.json" ]]; then |
| 86 | + args+=(--sourcekitten-sourcefile "$root_path/.build/sourcekitten/$module.json") |
| 87 | + fi |
| 88 | + |
| 89 | + jazzy "${args[@]}" |
| 90 | + |
| 91 | + if [[ $(cat $root_path/.build/sourcekitten/$module.json) == "0" ]]; then |
| 92 | + echo "processing module $module ($root_path/.build/sourcekitten/$module.json) yielded EMPTY module json file!" |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | +done |
| 96 | + |
| 97 | +# push to github pages |
| 98 | +if [[ $PUSH == true ]]; then |
| 99 | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 100 | + GIT_AUTHOR=$(git --no-pager show -s --format='%an <%ae>' HEAD) |
| 101 | + git fetch origin +gh-pages:gh-pages |
| 102 | + git checkout gh-pages |
| 103 | + rm -rf "docs/$version" |
| 104 | + rm -rf "docs/current" |
| 105 | + cp -r "$jazzy_dir/docs/$version" docs/ |
| 106 | + cp -r "docs/$version" docs/current |
| 107 | + git add --all docs |
| 108 | + echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=\"docs/current/$main_module/index.html\" /></head></html>" > index.html |
| 109 | + git add index.html |
| 110 | + touch .nojekyll |
| 111 | + git add .nojekyll |
| 112 | + changes=$(git diff-index --name-only HEAD) |
| 113 | + if [[ -n "$changes" ]]; then |
| 114 | + echo -e "changes detected\n$changes" |
| 115 | + git commit --author="$GIT_AUTHOR" -m "publish $version docs" |
| 116 | + git push origin gh-pages |
| 117 | + else |
| 118 | + echo "no changes detected" |
| 119 | + fi |
| 120 | + git checkout -f $BRANCH_NAME |
| 121 | +fi |
0 commit comments