PodのドキュメントをJazzyで生成してGitHub Pagesに自動アップする
さて、一部をPrivate Podで管理するようにしたので、ついでにPodのAPIドキュメント管理にJazzyを使います。
#!/bin/sh
# filename: ./scripts/generate_docs.sh
# clean up
mkdir -p _site
rm _site/*
# generate docs
jazzy \
--output "_site" \
--min-acl "public" \
--podspec "CanvasToolbar/CanvasToolbar.podspec"
Jazzyで書かれたドキュメントはHTMLで生成されるのですが、これを手で設置するのは面倒なので、TravisCIやCircleCIを使ってgit push時に自動的にGitHub Pagesへアップロードされるようにします。
#!/bin/bash
# filename: ./scripts/ci_docs.sh
# load .env / It's for debug on local machine
if [ -e .env ]; then
for i in $(cat .env 2>/dev/null); do
export $i
done
fi
# enable error reporting to the console
set -e
# cleanup "_site"
rm -rf _site
# clone remote repo to "_site"
git clone --depth 1 https://${GH_TOKEN}@github.com/${REPO}.git --branch gh-pages _site
# build with Jazzy into "_site"
bundle exec sh ./scripts/generate_docs.sh
# push
cd _site
git config user.email "$USER_EMAIL"
git config user.name "$USER_NAME"
git add --all
git commit --all --message="Auto generate docs #$TRAVIS_BUILD_NUMBER"
git push --force origin gh-pages
今回はPublic repositoryで作ってるから問題ないですが、Private repoの場合でもGitHub Pagesはpublicに作られるので注意してください。
ソースコード: https://github.com/tmokita/ColorPenMemo/tree/369bba9019329b442b2184c9a46f47cee6707896/scripts