Skip to content

Commit

Permalink
add doc generation script (#77)
Browse files Browse the repository at this point in the history
motivation: publish API docs

changes:
* amend docker file to include jazzy
* add doc generation script based on what we have in swift-nio and swift-log
  • Loading branch information
tomerd authored and Lukasa committed Mar 27, 2019
1 parent 7adcb49 commit 13d9b48
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ RUN [ -z $install_curl_from_source ] || tar xzf $HOME/curl.tar.gz --directory $H
RUN [ -z $install_curl_from_source ] || ( cd $HOME/.curl && ./configure --with-ssl && make && make install && cd - )
RUN [ -z $install_curl_from_source ] || ldconfig

# ruby
RUN apt-get update && apt-get install -y ruby
# ruby and jazzy for docs generation
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev
RUN gem install jazzy --no-ri --no-rdoc

# nghttp2
ARG install_nghttp2_from_source
Expand All @@ -60,7 +61,6 @@ RUN [ -z $h2spec_version ] || wget -q https://github.com/summerwind/h2spec/relea
RUN [ -z $h2spec_version ] || tar xzf $HOME/h2spec.tar.gz --directory $HOME/.h2spec
RUN [ -z $h2spec_version ] || mv $HOME/.h2spec/h2spec /usr/local/bin/h2spec


# swift
ARG swift_version=4.0.3
ARG swift_flavour=RELEASE
Expand Down
105 changes: 105 additions & 0 deletions scripts/generate_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/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=(NIOHTTP2 NIOHPACK)

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-http2.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 'swift-nio team'
--readme "$module_switcher"
--author_url https://github.com/apple/swift-nio-http2
--github_url https://github.com/apple/swift-nio-http2
--theme fullwidth
--xcodebuild-arguments -scheme,swift-nio-http2-Package)
cat > "$module_switcher" <<EOF
# swift-nio-http2 Docs
swift-nio-http2 contains multiple modules:
EOF

for module in "${modules[@]}"; do
echo " - [$module](../$module/index.html)" >> "$module_switcher"
done

tmp=`mktemp -d`
for module in "${modules[@]}"; do
args=("${jazzy_args[@]}" --output "$tmp/docs/$version/$module" --docset-path "$tmp/docset/$version/$module" --module "$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"
cp -r "$tmp/docs" .
cp -r "docs/$version" docs/current
git add --all docs
echo '<html><head><meta http-equiv="refresh" content="0; url=docs/current/NIOHTTP2/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
echo -e "changes detected\n$changes"
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

0 comments on commit 13d9b48

Please sign in to comment.