From cf790be04f3af0e02da7bb153cf2ea0ade485adc Mon Sep 17 00:00:00 2001 From: Tom Doron Date: Thu, 18 Jan 2018 19:21:54 +0000 Subject: [PATCH] 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 --- .gitignore | 2 +- docs/README.md | 8 ---- docs/index.html | 14 ------ generate_docs.sh | 114 +++++++++++++++++++++++++++++++++++++---------- 4 files changed, 92 insertions(+), 46 deletions(-) delete mode 100644 docs/README.md delete mode 100644 docs/index.html diff --git a/.gitignore b/.gitignore index 94586bd2f..3dbee1e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /*.xcodeproj Package.pins *.pem -docs/NIO* +/docs diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 0b8523af7..000000000 --- a/docs/README.md +++ /dev/null @@ -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) diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 85120385d..000000000 --- a/docs/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - Page Redirection - - - If you are not redirected automatically, follow this SwiftNIO Docs. - - diff --git a/generate_docs.sh b/generate_docs.sh index 8128b2ef4..b1bf9ff3c 100755 --- a/generate_docs.sh +++ b/generate_docs.sh @@ -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" <> "docs/$version/index.html" <SwiftNIO Docs +
+
    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 "
  • $module" >> "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 '' > 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