diff --git a/.github/deploy_doc.sh b/.github/deploy_doc.sh new file mode 100755 index 00000000..e8acf588 --- /dev/null +++ b/.github/deploy_doc.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -ex + +LANGUAGES=('rust' 'python' 'node') + +function deploy_doc(){ + echo "Creating doc at commit $1 for language $3 and pushing to folder $2" + git checkout $1 + cd "$GITHUB_WORKSPACE/docs" + if [ "$2" == "master" ]; then + echo "Pushing master" + for LANG in "${LANGUAGES[@]}"; do + make clean + make html O="-t $LANG" + ssh "$HOST_NAME" "mkdir -p $DOC_PATH/$LANG" + scp -r build/html "$HOST_NAME:$DOC_PATH/$LANG/$2" + cp -r build/html/_static . + done + elif [ "$2" == "latest" ]; then + echo "Pushing latest for" $3 + make clean + make html O="-t $3" + ssh "$HOST_NAME" "mkdir -p $DOC_PATH/$3" + scp -r build/html "$HOST_NAME:$DOC_PATH/$3/$2" + elif ssh "$HOST_NAME" "[ -d $DOC_PATH/$3/$2 ]"; then + echo "Directory" $2 "already exists" + scp -r _static/* "$HOST_NAME:$DOC_PATH/$3/$2/_static/" + else + echo "Pushing version" $2 "for" $3 + make clean + make html O="-t $3" + rm -rf build/html/_static + cp -r _static build/html + scp -r build/html "$HOST_NAME:$DOC_PATH/$3/$2" + fi +} + +# `master` for all languages +deploy_doc "$GITHUB_SHA" master + +# Rust versions +deploy_doc "$GITHUB_SHA" latest rust + +# Node versions +deploy_doc "$GITHUB_SHA" latest node + +# Python versions +deploy_doc "$GITHUB_SHA" v0.9.0 python +deploy_doc "$GITHUB_SHA" latest python diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml new file mode 100644 index 00000000..ed1f59be --- /dev/null +++ b/.github/workflows/docs-deploy.yml @@ -0,0 +1,36 @@ +name: Deploy Documentation + +on: + push: +# branches: +# - master + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v1 + with: + fetch-depth: 0 + + - name: Install SSH Key + uses: shimataro/ssh-key-action@v2 + with: + key: ${{ secrets.DOC_SSH_KEY }} + name: id_rsa + known_hosts: ${{ secrets.DOC_KNOWN_HOST }} + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: 3.6 + + - name: Install dependencies + run: pip install sphinx sphinx_rtd_theme + + - name: Deploy documentation + env: + HOST_NAME: ${{ secrets.DOC_HOST }} + DOC_PATH: ${{ secrets.DOC_PATH }} + run: ./.github/deploy_doc.sh diff --git a/docs/Makefile b/docs/Makefile index 0d95c058..764d1bb0 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -2,26 +2,24 @@ # # You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build +# from the environment for those with `?=` +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +BUILDDIR ?= build SOURCEDIR = source -RUSTBUILDDIR = build/rust -PYTHONBUILDDIR = build/python -NODEBUILDDIR = build/node -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(RUSTBUILDDIR)" $(SPHINXOPTS) $(O) +# Put it first so that "make" without argument is like "make html_all". +html_all: + @echo "Generating doc for Rust" + @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)/rust" $(SPHINXOPTS) $(O) -t rust + @echo "Generating doc for Python" + @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)/python" $(SPHINXOPTS) $(O) -t python + @echo "Generating doc for Node.js" + @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)/node" $(SPHINXOPTS) $(O) -t node -.PHONY: help Makefile +.PHONY: html_all Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @echo "Generating doc for Rust" - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(RUSTBUILDDIR)" $(SPHINXOPTS) $(O) -t Rust - @echo "Generating doc for Python" - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(PYTHONBUILDDIR)" $(SPHINXOPTS) $(O) -t Python - @echo "Generating doc for Node.js" - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(NODEBUILDDIR)" $(SPHINXOPTS) $(O) -t Node + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/source/_static/js/custom.js b/docs/source/_static/js/custom.js index c4159a80..75259f70 100644 --- a/docs/source/_static/js/custom.js +++ b/docs/source/_static/js/custom.js @@ -114,9 +114,12 @@ function addVersionControl() { // If a version is specified, update it if (parts[versionIndex] != "" && !parts[versionIndex].endsWith(".html")) { version = parts[versionIndex]; - // Otherwise redirect to the latest - } else { + // Otherwise redirect to the latest (if not opening locally) + } else if (!parts[parts.length - 1].endsWith(".html")) { return window.location.pathname = [language, version, parts.splice(versionIndex)].join("/"); + // Opening locally, just don't show the version/language selector + } else { + return } // Language Menu diff --git a/docs/source/index.rst b/docs/source/index.rst index a219dfc9..5919d934 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -40,7 +40,7 @@ Load an existing tokenizer: Loading a previously saved tokenizer is extremely simple and requires a single line of code: -.. only:: Rust +.. only:: rust .. literalinclude:: ../../tokenizers/tests/documentation.rs :language: rust @@ -48,7 +48,7 @@ Loading a previously saved tokenizer is extremely simple and requires a single l :end-before: END load_tokenizer :dedent: 4 -.. only:: Python +.. only:: python .. literalinclude:: ../../bindings/python/tests/documentation/test_load.py :language: python @@ -56,7 +56,7 @@ Loading a previously saved tokenizer is extremely simple and requires a single l :end-before: END load_tokenizer :dedent: 4 -.. only:: Node +.. only:: node .. literalinclude:: ../../bindings/node/examples/load.test.js :language: javascript @@ -70,7 +70,7 @@ Train a tokenizer: Small guide of :ref:`how to create a Tokenizer options`. -.. only:: Rust +.. only:: rust .. literalinclude:: ../../tokenizers/tests/documentation.rs :language: rust @@ -78,7 +78,7 @@ Small guide of :ref:`how to create a Tokenizer options`. :end-before: END train_tokenizer :dedent: 4 -.. only:: Python +.. only:: python .. literalinclude:: ../../bindings/python/tests/documentation/test_train.py :language: python @@ -86,7 +86,7 @@ Small guide of :ref:`how to create a Tokenizer options`. :end-before: END train_tokenizer :dedent: 4 -.. only:: Node +.. only:: node .. literalinclude:: ../../bindings/node/examples/train.test.js :language: javascript