diff --git a/.github/workflows/build_and_publish_docs.yml b/.github/workflows/build_and_publish_docs.yml index f50a2ea99..5ae6f165e 100644 --- a/.github/workflows/build_and_publish_docs.yml +++ b/.github/workflows/build_and_publish_docs.yml @@ -6,6 +6,8 @@ on: - dev - master - test/** + tags: + - v[0-9]+.[0-9]+.[0-9]+ pull_request: branches: - dev @@ -21,6 +23,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: set up python 3.9 uses: actions/setup-python@v5 @@ -36,37 +40,26 @@ jobs: python -m pip install --upgrade pip poetry python -m poetry install --with tutorials,docs --all-extras --no-ansi --no-interaction + - name: save docs version into a variable + run: | + echo "DOC_VERSION=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV + - name: build documentation env: TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} + DOC_VERSION: ${{ env.DOC_VERSION }} run: | python -m poetry run poe docs - - name: remove jekyll theming - run: touch docs/build/.nojekyll - - - name: save branch name without slashes - if: ${{ github.ref != 'refs/heads/master' }} - env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - run: | - BRANCH_NAME=${{ env.BRANCH_NAME }} - BRANCH_NAME=${BRANCH_NAME////_} - echo BRANCH_NAME=${BRANCH_NAME} >> $GITHUB_ENV - - - name: save artifact - if: ${{ github.ref != 'refs/heads/master' }} - uses: actions/upload-artifact@v4 - with: - name: ${{ format('github-pages-for-branch-{0}', env.BRANCH_NAME) }} - path: docs/build/ - retention-days: 3 - - name: deploy website - if: ${{ github.ref == 'refs/heads/master' }} - uses: JamesIves/github-pages-deploy-action@v4.6.4 + uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages folder: docs/build/ - single-commit: True + target-folder: ${{ env.DOC_VERSION }} + clean: True + + - name: print link to the documentation + run: | + echo "https://deeppavlov.github.io/chatsky/${{ github.head_ref || github.ref_name }}" diff --git a/.github/workflows/generate_version_switcher.yml b/.github/workflows/generate_version_switcher.yml new file mode 100644 index 000000000..b4148f39b --- /dev/null +++ b/.github/workflows/generate_version_switcher.yml @@ -0,0 +1,44 @@ +name: generate_version_switcher + +on: + workflow_run: + workflows: ["build_and_publish_docs"] + types: + - completed + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +jobs: + publish: + name: generate and update version switcher's json file + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: install GitPython + run: python -m pip install GitPython + + - name: generate version switcher + env: + VERSION_SWITCHER_STARTING_TAG: ${{ vars.VERSION_SWITCHER_STARTING_TAG }} + VERSION_SWITCHER_TAG_BLACKLIST: ${{ vars.VERSION_SWITCHER_TAG_BLACKLIST }} + VERSION_SWITCHER_TAG_WHITELIST: ${{ vars.VERSION_SWITCHER_TAG_WHITELIST }} + run: | + python ./scripts/switcher_gen.py + + - name: copy version switcher for updating it + run: | + mkdir docs/source/switcher/ + cp docs/source/_static/switcher.json docs/source/switcher/switcher.json + + - name: update version switcher + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: docs/source/switcher/ + clean: False diff --git a/docs/source/__init__.py b/docs/source/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/docs/source/_templates/example-links.html b/docs/source/_templates/example-links.html index 5ba1edc8f..0e2d58418 100644 --- a/docs/source/_templates/example-links.html +++ b/docs/source/_templates/example-links.html @@ -1,8 +1,9 @@ {% if meta is defined and meta is not none and 'tutorial_name' in meta %} + {% set doc_version = meta['doc_version'] %} {% set repo_path = "/".join(meta['tutorial_name'].split("/")[-1].split(".")) %} - {% set github_link = 'https://github.com/deeppavlov/chatsky/blob/master/' ~ repo_path ~ '.py' %} + {% set github_link = 'https://github.com/deeppavlov/chatsky/blob/' ~ doc_version ~ repo_path ~ '.py' %} {% set notebook_link = '../' ~ meta['tutorial_name'] ~ '.ipynb' %} - {% set colab_link = 'https://colab.research.google.com/github/deeppavlov/chatsky/blob/gh-pages/' ~ meta['tutorial_name'] ~ '.ipynb' %} + {% set colab_link = 'https://colab.research.google.com/github/deeppavlov/chatsky/blob/gh-pages/' ~ doc_version ~ meta['tutorial_name'] ~ '.ipynb' %}