mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: Jazzy generates Dash docsets for us, but currently they don't work. This is because the URLs they generate aren't matching the URL scheme we have. That makes them next to useless. Modifications: Add a trailing '/' to the root URL. Result: Calls to Ruby's URI.join won't blow away the final path component in the root URL, which means that the docsets will have correct URLs going forward.
119 lines
4.0 KiB
Bash
Executable File
119 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
##===----------------------------------------------------------------------===##
|
|
##
|
|
## This source file is part of the SwiftNIO open source project
|
|
##
|
|
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
|
## Licensed under Apache License v2.0
|
|
##
|
|
## See LICENSE.txt for license information
|
|
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
##
|
|
## SPDX-License-Identifier: Apache-2.0
|
|
##
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
set -e
|
|
|
|
my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
root_path="$my_path/.."
|
|
version=$(git describe --abbrev=0 --tags || echo "0.0.0")
|
|
modules=( NIO NIOHTTP1 NIOFoundationCompat NIOWebSocket NIOConcurrencyHelpers NIOTLS NIOTestUtils )
|
|
|
|
|
|
if [[ "$(uname -s)" == "Linux" ]]; then
|
|
# build code if required
|
|
if [[ ! -d "$root_path/.build/x86_64-unknown-linux" ]]; then
|
|
swift build
|
|
fi
|
|
# setup source-kitten if required
|
|
source_kitten_source_path="$root_path/.SourceKitten"
|
|
if [[ ! -d "$source_kitten_source_path" ]]; then
|
|
git clone https://github.com/jpsim/SourceKitten.git "$source_kitten_source_path"
|
|
fi
|
|
source_kitten_path="$source_kitten_source_path/.build/x86_64-unknown-linux/debug"
|
|
if [[ ! -d "$source_kitten_path" ]]; then
|
|
rm -rf "$source_kitten_source_path/.swift-version"
|
|
cd "$source_kitten_source_path" && swift build && cd "$root_path"
|
|
fi
|
|
# generate
|
|
mkdir -p "$root_path/.build/sourcekitten"
|
|
for module in "${modules[@]}"; do
|
|
if [[ ! -f "$root_path/.build/sourcekitten/$module.json" ]]; then
|
|
"$source_kitten_path/sourcekitten" doc --spm-module $module > "$root_path/.build/sourcekitten/$module.json"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
[[ -d docs/$version ]] || mkdir -p docs/$version
|
|
[[ -d swift-nio.xcodeproj ]] || swift package generate-xcodeproj
|
|
|
|
# run jazzy
|
|
if ! command -v jazzy > /dev/null; then
|
|
gem install jazzy --no-ri --no-rdoc
|
|
fi
|
|
module_switcher="docs/$version/README.md"
|
|
jazzy_args=(--clean
|
|
--author 'SwiftNIO Team'
|
|
--readme "$module_switcher"
|
|
--author_url https://github.com/apple/swift-nio
|
|
--github_url https://github.com/apple/swift-nio
|
|
--theme fullwidth
|
|
--github-file-prefix https://github.com/apple/swift-nio/tree/$version
|
|
--xcodebuild-arguments -scheme,swift-nio-Package)
|
|
cat > "$module_switcher" <<"EOF"
|
|
# SwiftNIO Docs
|
|
|
|
SwiftNIO contains multiple modules:
|
|
|
|
EOF
|
|
|
|
for module in "${modules[@]}"; do
|
|
echo " - [$module](../$module/index.html)" >> "$module_switcher"
|
|
done
|
|
|
|
cat >> "$module_switcher" <<"EOF"
|
|
|
|
---
|
|
|
|
For the API documentation of the other repositories in the SwiftNIO family check:
|
|
|
|
- [`swift-nio` API docs](https://apple.github.io/swift-nio/docs/current/NIO/index.html)
|
|
- [`swift-nio-ssl` API docs](https://apple.github.io/swift-nio-ssl/docs/current/NIOSSL/index.html)
|
|
- [`swift-nio-http2` API docs](https://apple.github.io/swift-nio-http2/docs/current/NIOHTTP2/index.html)
|
|
|
|
EOF
|
|
|
|
for module in "${modules[@]}"; do
|
|
args=("${jazzy_args[@]}" --output "$root_path/docs/$version/$module" --module "$module"
|
|
--module-version $version
|
|
--root-url "https://apple.github.io/swift-nio/docs/$version/$module/")
|
|
if [[ -f "$root_path/.build/sourcekitten/$module.json" ]]; then
|
|
args+=(--sourcekitten-sourcefile "$root_path/.build/sourcekitten/$module.json")
|
|
fi
|
|
jazzy "${args[@]}"
|
|
done
|
|
|
|
# push to github pages
|
|
if [[ $CI == true ]]; then
|
|
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
|
|
GIT_AUTHOR=$(git --no-pager show -s --format='%an <%ae>' HEAD)
|
|
git fetch origin +gh-pages:gh-pages
|
|
git checkout gh-pages
|
|
rm -rf docs/current
|
|
cp -r docs/$version docs/current
|
|
git add --all docs
|
|
echo '<html><head><meta http-equiv="refresh" content="0; url=docs/current/NIO/index.html" /></head></html>' > index.html
|
|
git add index.html
|
|
touch .nojekyll
|
|
git add .nojekyll
|
|
changes=$(git diff-index --name-only HEAD)
|
|
if [[ -n "$changes" ]]; then
|
|
git commit --author="$GIT_AUTHOR" -m "publish $version docs"
|
|
git push origin gh-pages
|
|
else
|
|
echo "no changes detected"
|
|
fi
|
|
git checkout -f $BRANCH_NAME
|
|
fi
|