Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 114 additions & 19 deletions .github/workflows/build-gh-pages.yml
Comment thread
AR21SM marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -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) }}
Comment thread
AR21SM marked this conversation as resolved.
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'
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DISCOVER Cookbook - Redirecting...</title>
<link rel="canonical" href="./en/">
<meta http-equiv="refresh" content="0; url=./en/">
</head>
<body>
<a href="./en/">Redirecting to English...</a>
</body>
</html>
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
9 changes: 5 additions & 4 deletions DISCOVER/conf.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand Down
20 changes: 9 additions & 11 deletions ci/build_website.sh
Original file line number Diff line number Diff line change
@@ -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"
echo "Building $LANGUAGE version..."
WEBSITE_VERSION="$VERSION" WEBSITE_LANGUAGE="$LANGUAGE" sphinx-build -b html DISCOVER/ DISCOVER/_build/html