diff --git a/.github/workflows/build-old-docs.yml b/.github/workflows/build-old-docs.yml new file mode 100644 index 00000000000..8b7d36fef6e --- /dev/null +++ b/.github/workflows/build-old-docs.yml @@ -0,0 +1,126 @@ +name: Build old docs + +on: + workflow_dispatch: + inputs: + release_token: + description: 'Your release token' + required: true + triggered_by: + description: 'CD | TAG | MANUAL' + required: false + default: MANUAL + package: + description: The name of the repo to build documentation for. + type: string + default: docarray + repo_owner: + description: The owner of the repo to build documentation for. Defaults to 'jina-ai'. + type: string + default: jina-ai + pages_branch: + description: Branch that Github Pages observes + type: string + default: gh-pages + git_config_name: + type: string + default: Jina Dev Bot + git_config_email: + type: string + default: dev-bot@jina.ai + +jobs: + token-check: + runs-on: ubuntu-latest + steps: + - run: echo "Success!" + if: "${{ github.event.inputs.release_token }} == ${{ env.release_token }}" + env: + release_token: ${{ secrets.DOCARRAY_RELEASE_TOKEN }} + - id: get_versions + run: | + printf "versions=" >> $GITHUB_OUTPUT + curl https://raw.githubusercontent.com/${{ inputs.repo_owner }}/${{ inputs.package }}/main/docs/_versions.json >> $GITHUB_OUTPUT + outputs: + versions: ${{ steps.get_versions.outputs.versions }} + + build-doc: + needs: token-check + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{ fromJson(needs.token-check.outputs.versions) }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + ref: ${{ matrix.version }} + - uses: actions/setup-python@v4 + with: + python-version: '3.7' + - name: Get latest templates + run: | + git show --summary + echo "Get latest sidebar brand template" + wget https://raw.githubusercontent.com/${{ inputs.repo_owner }}/${{ inputs.package }}/main/docs/_templates/sidebar/brand.html + mv ./brand.html ./docs/_templates/sidebar/brand.html + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install wheel + # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" + pip install --no-cache-dir ".[test]" + pip install --no-cache-dir ".[full]" + pip install --no-cache-dir ".[qdrant]" + pip install --no-cache-dir ".[annlite]" + pip install --no-cache-dir ".[weaviate]" + pip install --no-cache-dir ".[elasticsearch]" + pip install --no-cache-dir ".[redis]" + cd docs + pip install -r requirements.txt + pip install --pre -U furo + pip install sphinx-markdown-tables==0.0.17 + - name: Sphinx Build + run: | + cd docs + bash makedoc.sh + - name: Package build into artifact + run: | + mv ./docs/_build/dirhtml ./${{ matrix.version }} + zip -r /tmp/build.zip ./${{ matrix.version }}/* + - name: Upload built html + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.version }} + path: /tmp/build.zip + retention-days: 1 + + push-docs: + runs-on: ubuntu-latest + needs: build-doc + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + ref: ${{ inputs.pages_branch }} + - uses: actions/download-artifact@v3 + with: + path: /tmp/artifacts + - name: Clear old builds + run: | + cd docs + for i in $(ls /tmp/artifacts); do git rm -rf "$i" || true; done + - name: In with new builds + run: | + cd docs + for i in $(ls /tmp/artifacts); do unzip "/tmp/artifacts/$i/build.zip"; done + rm _versions.json + wget https://raw.githubusercontent.com/${{ inputs.repo_owner }}/${{ inputs.package }}/main/docs/_versions.json + - name: Push it up! + run: | + git config --local user.email "${{ inputs.git_config_email }}" + git config --local user.name "${{ inputs.git_config_name }}" + git show --summary + git add . && git commit -m "chore(docs): update old docs due to ${{github.event_name}} on ${{github.repository}}" + git push origin diff --git a/.github/workflows/force-docs-build.yml b/.github/workflows/force-docs-build.yml index 48f86048faa..c95e1cde1ce 100644 --- a/.github/workflows/force-docs-build.yml +++ b/.github/workflows/force-docs-build.yml @@ -10,6 +10,28 @@ on: description: 'CD | TAG | MANUAL' required: false default: MANUAL + build_old_docs: + description: 'Whether to build old docs (TRUE | FALSE)' + type: string + default: 'FALSE' + package: + description: The name of the repo to build documentation for. + type: string + default: docarray + repo_owner: + description: The owner of the repo to build documentation for. Defaults to 'jina-ai'. + type: string + default: jina-ai + pages_branch: + description: Branch that Github Pages observes + type: string + default: gh-pages + git_config_name: + type: string + default: Jina Dev Bot + git_config_email: + type: string + default: dev-bot@jina.ai jobs: token-check: @@ -20,20 +42,18 @@ jobs: env: release_token: ${{ secrets.DOCARRAY_RELEASE_TOKEN }} - release-docs: + build-and-push-latest-docs: needs: token-check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.5.0 + - uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 1 - uses: actions/setup-python@v4 with: - python-version: 3.7 - - name: Build doc and push to gh-pages + python-version: '3.7' + - name: Install Dependencies run: | - git config --local user.email "dev-bot@jina.ai" - git config --local user.name "Jina Dev Bot" python -m pip install --upgrade pip python -m pip install wheel # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" @@ -44,28 +64,52 @@ jobs: pip install --no-cache-dir ".[weaviate]" pip install --no-cache-dir ".[elasticsearch]" pip install --no-cache-dir ".[redis]" - mkdir gen-html cd docs pip install -r requirements.txt pip install --pre -U furo + pip install sphinx-markdown-tables==0.0.17 + - name: Sphinx Build + run: | + cd docs bash makedoc.sh - cd ./_build/dirhtml/ - cp -r ./ ../../../gen-html - cd - # back to ./docs - cd .. - git checkout -f gh-pages - git rm -rf ./docs - mkdir -p docs - cd gen-html - cp -r ./ ../docs - cd ../docs - ls -la - touch .nojekyll - cp 404/index.html 404.html - sed -i 's/href="\.\./href="/' 404.html # fix asset urls that needs to be updated in 404.html - echo docarray.jina.ai > CNAME - cd .. - git add docs - git status - git commit -m "chore(docs): update docs due to ${{github.event_name}} on ${{github.repository}}" - git push --force origin gh-pages + mv ./_build/dirhtml /tmp/gen-html + - name: Checkout to GH pages branch (${{ inputs.pages_branch }}) + run: | + git fetch origin ${{ inputs.pages_branch }}:${{ inputs.pages_branch }} --depth 1 + git checkout -f ${{ inputs.pages_branch }} + git reset --hard HEAD + - name: Small config stuff + run: | + touch /tmp/gen-html/.nojekyll + cp ./docs/CNAME /tmp/gen-html/CNAME + cp ./docs/_versions.json /tmp/gen-html/_versions.json + cp /tmp/gen-html/404/index.html /tmp/gen-html/404.html + sed -i 's/href="\.\./href="/' /tmp/gen-html/404.html # fix asset urls that needs to be updated in 404.html + - name: Moving old doc versions + run: | + cd docs + for i in $(cat _versions.json | jq '.[].version' | tr -d '"'); do mv "$i" /tmp/gen-html; done + - name: Swap in new docs + run: | + rm -rf ./docs + mv /tmp/gen-html ./docs + - name: Push it up! + run: | + git config --local user.email "${{ inputs.git_config_email }}" + git config --local user.name "${{ inputs.git_config_name }}" + git show --summary + git add ./docs && git commit -m "chore(docs): update docs due to ${{github.event_name}} on ${{github.repository}}" + git push origin ${{ inputs.pages_branch }} + + build-old-docs: + needs: build-and-push-latest-docs + runs-on: ubuntu-latest + if: inputs.build_old_docs == 'TRUE' + steps: + - uses: benc-uk/workflow-dispatch@v1 + with: + workflow: Build old docs + token: ${{ secrets.JINA_DEV_BOT }} + inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "TAG"}' + env: + release_token: ${{ secrets.DOCARRAY_RELEASE_TOKEN }} diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index d6a270e6463..cd658781be6 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -18,7 +18,7 @@ jobs: with: workflow: Manual Docs Build token: ${{ secrets.JINA_DEV_BOT }} - inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "TAG"}' + inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "TAG", "build_old_docs": "TRUE"}' env: release_token: ${{ secrets.DOCARRAY_RELEASE_TOKEN }} diff --git a/docs/_templates/sidebar/brand.html b/docs/_templates/sidebar/brand.html index 1531f31b10f..48e37ed9643 100644 --- a/docs/_templates/sidebar/brand.html +++ b/docs/_templates/sidebar/brand.html @@ -16,26 +16,33 @@ {%- endif %} {% endblock brand_content %} + +
Star - {% if versions %} - + - {% endif %} -
+ \ No newline at end of file diff --git a/docs/_versions.json b/docs/_versions.json new file mode 100644 index 00000000000..88b3e650252 --- /dev/null +++ b/docs/_versions.json @@ -0,0 +1 @@ +[{"version": "v0.18.1"}, {"version": "v0.18.0"}, {"version": "v0.17.0"}, {"version": "v0.16.5"}, {"version": "v0.16.0"}, {"version": "v0.15.4"}, {"version": "v0.15.0"}, {"version": "v0.14.11"}, {"version": "v0.14.0"}, {"version": "v0.13.33"}, {"version": "v0.13.0"}, {"version": "v0.12.9"}, {"version": "v0.12.0"}, {"version": "v0.11.3"}, {"version": "v0.11.0"}, {"version": "v0.10.5"}, {"version": "v0.10.0"}, {"version": "v0.9.18"}, {"version": "v0.9.0"}, {"version": "v0.8.11"}, {"version": "v0.8.0"}, {"version": "v0.7.3"}, {"version": "v0.7.0"}, {"version": "v0.6.3"}, {"version": "v0.6.0"}, {"version": "v0.5.3"}, {"version": "v0.5.0"}, {"version": "v0.4.3"}, {"version": "v0.4.0"}, {"version": "v0.3.3"}, {"version": "v0.3.0"}, {"version": "v0.2.0"}, {"version": "v0.1.7"}, {"version": "v0.1.1"}, {"version": "v0.0.0"}] \ No newline at end of file diff --git a/scripts/prepend_version_json.py b/scripts/prepend_version_json.py new file mode 100644 index 00000000000..2036fbfa305 --- /dev/null +++ b/scripts/prepend_version_json.py @@ -0,0 +1,21 @@ +from typing import List +import argparse +import json + +parser = argparse.ArgumentParser(prog="Prepender docs/_versions.json") +parser.add_argument( + "--version", + type=str, + help="The version we wish to prepend (e.g. v0.18.0)", + required=True, +) +args = parser.parse_args() + +with open("./docs/_versions.json") as f: + versions: List[dict] = json.load(f) + element = {k: v for k, v in args._get_kwargs()} + if element != versions[0]: + versions.insert(0, element) + +with open("./docs/_versions.json", "w") as f: + json.dump(versions, f) diff --git a/scripts/release.sh b/scripts/release.sh index 0a00cb7bda8..bddea6b78f3 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -72,6 +72,10 @@ export RELEASE_VER=$(sed -n '/^__version__/p' $INIT_FILE | cut -d \' -f2) LAST_VER=$(git tag -l | sort -V | tail -n1) printf "last version: \e[1;32m$LAST_VER\e[0m\n" +# Update new _versions.json if necessary +python ./scripts/prepend_version_json.py --version "v$RELEASE_VER" +git add ./docs/_versions.json + if [[ $1 == "final" ]]; then printf "this will be a final release: \e[1;33m$RELEASE_VER\e[0m\n"