Skip to content

Commit

Permalink
WIP - Add GHA to deploy documentation on release/main.push
Browse files Browse the repository at this point in the history
  • Loading branch information
thomass-dev committed Nov 19, 2024
1 parent 42a197e commit 7c4e95a
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 25 deletions.
23 changes: 20 additions & 3 deletions .github/actions/sphinx/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
134 changes: 132 additions & 2 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ name: Sphinx
# - 'examples/**'
# - 'sphinx/**'
# - 'skore/**'
# release:
# types: [released]

on: [push]

Expand All @@ -25,7 +27,7 @@ concurrency:
cancel-in-progress: true

jobs:
sphinx:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -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"""
<head>
<meta http-equiv=\"refresh\" content=\"0; url={url}/{new[1]["version"]}\"/>
</head>
"""
)
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
19 changes: 0 additions & 19 deletions sphinx/_static/switcher.json

This file was deleted.

6 changes: 5 additions & 1 deletion sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@
},
],
"announcement": "This code is still in development. <strong>The API is subject to change.</strong>",
"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"],
Expand Down

0 comments on commit 7c4e95a

Please sign in to comment.