diff --git a/.github/actions/sphinx/deploy/action.yml b/.github/actions/sphinx/deploy/action.yml index c6e700a8c..e6118ee0f 100644 --- a/.github/actions/sphinx/deploy/action.yml +++ b/.github/actions/sphinx/deploy/action.yml @@ -3,6 +3,23 @@ name: Deploy sphinx documentation inputs: CONFIGURATION: required: true + ACTION: + required: false + default: sync + type: choice + options: + - copy + - sync + PROVIDER: + required: false + default: scaleway + BUCKET: + required: false + default: prod-probabl-skore + SOURCE: + required: true + DESTINATION: + required: true runs: using: composite @@ -16,6 +33,6 @@ runs: - shell: bash run: | rclone --config rclone.configuration \ - sync \ - sphinx/build/html/ \ - scaleway:prod-probabl-skore/doc/latest/ + ${{ inputs.ACTION }} \ + ${{ inputs.SOURCE }} \ + ${{ inputs.PROVIDER }}:${{ inputs.BUCKET }}/${{ inputs.DESTINATION }} diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index d815ef499..710524593 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -17,6 +17,8 @@ name: Sphinx # - 'examples/**' # - 'sphinx/**' # - 'skore/**' +# release: +# types: [released] on: [push] @@ -25,7 +27,7 @@ concurrency: cancel-in-progress: true jobs: - sphinx: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -34,7 +36,135 @@ jobs: python-version: '3.12' cache: 'pip' - uses: ./.github/actions/sphinx/build + - uses: actions/upload-artifact@v4 + with: + name: sphinx-html-artifact + path: sphinx/build/html/ + + deploy-on-release: + runs-on: ubuntu-latest + # if: ${{ github.event_name == 'release' }} + needs: build + steps: + - uses: actions/checkout@v4 + + # + - shell: bash + id: tag-cutter + run: | + export GITHUB_REF_NAME=0.3.0 + set -eu + if [[ "${GITHUB_REF_NAME}" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)?$ ]]; then + echo "MAJOR_DOT_MINOR=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}" >> "${GITHUB_OUTPUT}" + fi + + # si tag + # récupérer version X.Y + # build X.Y/ + # sync X.Y/ + # + - uses: actions/download-artifact@v4 + with: + name: sphinx-html-artifact + path: html/ - uses: ./.github/actions/sphinx/deploy with: CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} - # - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + SOURCE: html/ + DESTINATION: ${{ steps.tag-cutter.outputs.MAJOR_DOT_MINOR }}/ + + # + # si tag + # récupérer version X.Y + # build versions.json (N versions max) + # sync versions.json + # + - shell: python + run: | + import os + import requests + import operator + import json + + url = os.environ["URL"] + current = os.environ["CURRENT"] + + response = requests.get(f"{url}/versions.json") + response.raise_for_status() + + history = set(map(operator.itemgetter("version"), response.json())) - {"dev"} | {current} + new = [ + { + "name": version, + "version": version, + "url": f"{url}/{version}/", + "preferred": i == 1, + } + for i, version in enumerate(["dev"] + sorted(history, key=lambda x: float(x), reverse=True)) + if i < 10 + ] + + with open("versions.json", "w", encoding="utf-8") as file: + json.dump(new, file, ensure_ascii=False, indent=4) + + with open("index.html", "w", encoding="utf-8") as file: + file.write( + f""" + + + + """ + ) + env: + CURRENT: ${{ steps.tag-cutter.outputs.MAJOR_DOT_MINOR }} + URL: https://skore.probabl.ai + + - uses: ./.github/actions/sphinx/deploy + with: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} + ACTION: copy + SOURCE: versions.json + DESTINATION: + + # si tag + # recuperer versions.json + # build index.html + # sync index.html + # + + - uses: ./.github/actions/sphinx/deploy + with: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} + ACTION: copy + SOURCE: index.html + DESTINATION: + + + deploy-on-main-push: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + needs: build + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: sphinx-html-artifact + path: html/ + - uses: ./.github/actions/sphinx/deploy + with: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} + SOURCE: html/ + DESTINATION: dev/ + + # si main.push + # build dev/ + # sync dev/ + + clean: + runs-on: ubuntu-latest + if: always() + needs: [deploy-on-release, deploy-on-main-push] + steps: + - uses: geekyeggo/delete-artifact@v5 + with: + name: sphinx-html-artifact diff --git a/sphinx/_static/switcher.json b/sphinx/_static/switcher.json deleted file mode 100644 index 386394166..000000000 --- a/sphinx/_static/switcher.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "version": "dev", - "url": "https://skore.probabl.ai/doc/dev/" - }, - { - "version": "0.3", - "url": "https://skore.probabl.ai/doc/0.3/", - "preferred": true - }, - { - "version": "0.2", - "url": "https://skore.probabl.ai/doc/0.2/" - }, - { - "version": "0.1", - "url": "https://skore.probabl.ai/doc/0.1/" - } -] diff --git a/sphinx/conf.py b/sphinx/conf.py index c18ac6267..ce0724ab3 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -108,8 +108,12 @@ }, ], "announcement": "This code is still in development. The API is subject to change.", - "switcher": {"json_url": "_static/switcher.json", "version_match": version}, + "switcher": { + "json_url": "https://skore.probabl.ai/versions.json", + "version_match": version, + }, "check_switcher": True, + "show_version_warning_banner": True, "navbar_start": ["navbar-logo", "version-switcher"], "navbar_center": ["navbar-nav"], "navbar_end": ["theme-switcher"],