diff --git a/.github/workflows/build-gh-pages.yml b/.github/workflows/build-gh-pages.yml index a37018f73..4fb1f5f11 100644 --- a/.github/workflows/build-gh-pages.yml +++ b/.github/workflows/build-gh-pages.yml @@ -1,33 +1,128 @@ name: deploy-book -# Only run this when the main branch changes on: push: branches: - - main - - next + - main + - '*-translations' + - '!1.0-translations' + +concurrency: + group: "gh-pages" + cancel-in-progress: true -# This job installs dependencies, build the book, and pushes it to `gh-pages` jobs: + get-info: + runs-on: ubuntu-latest + outputs: + languages: ${{ steps.get-languages.outputs.languages }} + version: ${{ steps.version-info.outputs.version }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get languages directly with jq + id: get-languages + run: | + languages=$(jq -c '[.[] | .code]' DISCOVER/_static/languages.json) + echo "languages=${languages}" >> "$GITHUB_OUTPUT" + + - name: Determine version from GitHub context + id: version-info + env: + REF_NAME: ${{ github.ref_name }} + REF_TYPE: ${{ github.ref_type }} + run: | + version="dev" + if [[ "$REF_TYPE" == "tag" ]]; then + version="${REF_NAME#v}" + elif [[ "$REF_NAME" == *-translations ]]; then + version="${REF_NAME%-translations}" + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + deploy-book: + needs: get-info runs-on: ubuntu-latest + strategy: + matrix: + language: ${{ fromJSON(needs.get-info.outputs.languages) }} steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Build documentation with script + env: + VERSION: ${{ needs.get-info.outputs.version }} + LANGUAGE: ${{ matrix.language }} + run: | + bash ci/build_website.sh - - name: Set up Python 3.13 - uses: actions/setup-python@v1 - with: - python-version: 3.13 + - name: Deploy language to GitHub Pages + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./DISCOVER/_build/html + destination_dir: ${{ needs.get-info.outputs.version }}/${{ matrix.language }} + keep_files: true - - name: Build the book - run: | - bash ci/build_website.sh + create-redirect: + needs: [get-info, deploy-book] + runs-on: ubuntu-latest + steps: + - name: Create version redirect + run: | + mkdir -p temp_redirect + cat > temp_redirect/index.html << 'EOF' + + + + + + DISCOVER Cookbook - Redirecting... + + + + + Redirecting to English... + + + EOF + + - name: Deploy version redirect + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./temp_redirect + destination_dir: ${{ needs.get-info.outputs.version }} + keep_files: true + + deploy-root-files: + needs: [get-info, deploy-book] + runs-on: ubuntu-latest + if: github.ref_name == 'main' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Create root files directory + run: | + mkdir -p root_files + cp DISCOVER/404.html root_files/ + cp index.html root_files/ + cp DISCOVER/_static/versions.json root_files/ - - name: Push book HTML to gh-pages - uses: peaceiris/actions-gh-pages@v3.9.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./DISCOVER/_build/html - destination_dir: dev/ - keep_files: true + - name: Deploy root files to GitHub Pages + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./root_files + destination_dir: . + keep_files: true \ No newline at end of file diff --git a/DISCOVER/conf.py b/DISCOVER/conf.py index 366ea2e68..d7a68c581 100644 --- a/DISCOVER/conf.py +++ b/DISCOVER/conf.py @@ -1,10 +1,11 @@ -version = 'dev' -language = 'en' -baseurl = 'https://discover-cookbook.numfocus.org' - import json import os +version = os.environ.get("WEBSITE_VERSION", "dev") +language = os.environ.get("WEBSITE_LANGUAGE", "en") + +baseurl = 'https://discover-cookbook.numfocus.org' + # Load language data from languages.json language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json') language_data = [] diff --git a/ci/build_website.sh b/ci/build_website.sh index 07b753de8..e72f1266b 100644 --- a/ci/build_website.sh +++ b/ci/build_website.sh @@ -1,20 +1,18 @@ - +#!/usr/bin/env bash echo "Starting build process..." +# Get parameters with defaults +VERSION=${VERSION:-${1:-"dev"}} +LANGUAGE=${LANGUAGE:-${2:-"en"}} + +echo "Building version: $VERSION, language: $LANGUAGE" + # Install dependencies pip install -r requirements.txt # Clean tags directory rm -rf DISCOVER/_tags/* -echo "Building English version..." -sphinx-build -b html DISCOVER/ DISCOVER/_build/html - - -# Copy root level files if they exist -if [ -f "DISCOVER/_static/404.html" ]; then - cp DISCOVER/_static/404.html DISCOVER/_build/html/ -fi - -echo "Build completed successfully" \ No newline at end of file +echo "Building $LANGUAGE version..." +WEBSITE_VERSION="$VERSION" WEBSITE_LANGUAGE="$LANGUAGE" sphinx-build -b html DISCOVER/ DISCOVER/_build/html