doc generation

motivation: publish api docs via gh-pages

changes:
* update generate_docs script to install required dependencies, perform sourcekitten index and commit the docs when running in CI
* create a rio pipeline to run docs generation script
This commit is contained in:
Tom Doron committed 2018-01-18 19:21:54 +00:00
1 parent 1535c2f5fc
commit cf790be04f
4 files changed
+92 -46

No files matched your search

+1 -1
View File
@@ -4,4 +4,4 @@
/*.xcodeproj
Package.pins
*.pem
docs/NIO*
/docs
-8
View File
@@ -1,8 +0,0 @@
# SwiftNIO Docs
SwiftNIO contains multiple modules:
- [NIO](../NIO/index.html)
- [NIOHTTP1](../NIOHTTP1/index.html)
- [NIOTLS](../NIOTLS/index.html)
- [NIOOpenSSL](../NIOOpenSSL/index.html)
-14
View File
@@ -1,14 +0,0 @@
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1; url=NIO/index.html">
<script type="text/javascript">
window.location.href = "NIO/index.html"
</script>
<title>Page Redirection</title>
</head>
<body>
If you are not redirected automatically, follow this <a href='NIO/index.html'>SwiftNIO Docs</a>.
</body>
</html>
+91 -23
View File
@@ -1,10 +1,52 @@
#!/bin/bash
set -eu
set -e
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ "$(uname -s)" != Darwin ]]; then
swift_version=${swift_version:-4.0.2}
version=$(git describe --abbrev=0 --tags)
modules=(SwiftNIO NIOHTTP1 NIOTLS NIOOpenSSL)
if [[ $CI == true ]]; then
# CI setup, assume this is running in an ubuntu docker container:
# to test locally:
# docker run -v `pwd`:/code -w /code -e CI=true ubuntu:14.04 /bin/bash /code/generate_docs.sh
# setup swift
rm -rf "$HOME/.swiftenv"
git clone https://github.com/kylef/swiftenv.git "$HOME/.swiftenv"
export SWIFTENV_ROOT="$HOME/.swiftenv"
export PATH="$SWIFTENV_ROOT/bin:$HOME/scripts:$PATH"
eval "$(swiftenv init -)"
swiftenv install $swift_version
# set path swift libs
export LINUX_SOURCEKIT_LIB_PATH="/root/.swiftenv/versions/$swift_version/usr/lib"
# setup ruby
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm requirements
rvm install 2.4
# setup jazzy
gem install jazzy --no-ri --no-rdoc
# setup source kitten
source_kitten_source_path=~/.SourceKitten
source_kitten_path="$source_kitten_source_path/.build/x86_64-unknown-linux/debug"
git clone https://github.com/jpsim/SourceKitten.git "$source_kitten_source_path"
rm -rf "$source_kitten_source_path/.swift-version"
cd "$source_kitten_source_path" && swift build && cd -
# generate
for module in "${modules[@]}"; do
if [[ ! -f "$my_path/$module.json" ]]; then
"$source_kitten_path/sourcekitten" doc --spm-module $module > "$my_path/$module.json"
fi
done
elif [[ "$(uname -s)" != Darwin ]]; then
echo >&2 "Sorry, at this point in time documentation can only be generated on macOS."
exit 1
fi
@@ -13,32 +55,58 @@ if ! command -v jazzy > /dev/null; then
echo >&2 "ERROR: jazzy not installed, install with"
echo >&2
echo >&2 " gem install jazzy"
exit 1
fi
cd "$my_path"
# build swift-nio if required
if [[ ! -d "$my_path/.build/x86_64-unknown-linux" ]]; then
swift build
fi
[[ -d docs/$version ]] || mkdir -p docs/$version
[[ -d swift-nio.xcodeproj ]] || swift package generate-xcodeproj
cd "$here"
# run jazzy
jazzy_args=(--clean
--readme docs/$version/README.md
--author 'SwiftNIO Team'
--author_url https://github.com/apple/nio
--github_url https://github.com/apple/nio
--xcodebuild-arguments -scheme,swift-nio-Package)
tmp="$(mktemp /tmp/.swift-nio-jazzy_XXXXXX)"
cat >> "$tmp" <<EOF
# SwiftNIO Docs
SwiftNIO contains multiple modules:
for module in "${modules[@]}"; do
args=("${jazzy_args[@]}" --output "docs/$version/$module" --module "$module")
if [[ -f $module.json ]]; then
args+=(--sourcekitten-sourcefile $module.json)
fi
jazzy "${args[@]}"
done
# create index
cat >> "docs/$version/index.html" <<EOF
<b>SwiftNIO Docs</b>
<br>
<ul>SwiftNIO contains multiple modules:
EOF
modules=(SwiftNIO NIOHTTP1 NIOTLS NIOOpenSSL)
for module in "${modules[@]}"; do
echo " - [$module](../$module/index.html)" >> "$tmp"
done
mv "$tmp" docs/README.md
for module in "${modules[@]}"; do
jazzy \
--clean \
--readme docs/README.md \
--author 'SwiftNIO Team' \
--author_url https://github.com/apple/nio \
--github_url https://github.com/apple/nio \
--xcodebuild-arguments -scheme,swift-nio-Package \
--output "docs/$module" \
--module "$module"
echo "<li><a href="$module/index.html">$module</a>" >> "docs/$version/index.html"
done
# push to github pages
if [[ $CI == true ]]; then
BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
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 docs
echo '<html><head><meta http-equiv="refresh" content="0; url=docs/current" /></head></html>' > index.html
git add index.html
git commit --author="$GIT_AUTHOR" -m "publish $version docs"
git push origin gh-pages
git checkout -f $BRANCH_NAME
fi