Skip to content

Test 7

Test 7 #56

Workflow file for this run

name: Documentation
on: [push, pull_request, workflow_dispatch]
permissions:
contents: write
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install sphinx sphinx-book-theme myst_parser
- name: Install XTL
run: |
pip install -e .[dev]
- name: Get package version
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# For tag pushes, use the tag name (without 'refs/tags/' prefix)
PACKAGE_VERSION=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
PACKAGE_VERSION=${PACKAGE_VERSION#v}
else
# For non-tag pushes (like dev branch), use the package version
# Use tail -n 1 to get only the last line with the version number
PACKAGE_VERSION=$(python -c "import xtl; print(xtl.__version__)" | tail -n 1)
fi
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
- name: Sphinx build
run: |
# Check if we're on a branch or tag push
if [[ "${{ github.event_name }}" == "push" && ("${{ github.ref }}" == "refs/heads/dev" || "${{ github.ref }}" =~ ^refs/tags/) ]]; then
# Clone the gh-pages branch to get version information
git clone --quiet --branch=gh-pages --depth=1 https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git gh-pages-clone
# Find version directories
VERSION_DIRS=$(find gh-pages-clone -maxdepth 1 -type d | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -r)
# Create JSON array of versions
VERSIONS_JSON="["
for dir in $VERSION_DIRS; do
VERSION=$(basename $dir)
# Extract numeric version without 'v' prefix
NUM_VERSION=${VERSION#v}
if [ "$VERSIONS_JSON" != "[" ]; then
VERSIONS_JSON="$VERSIONS_JSON,"
fi
VERSIONS_JSON="$VERSIONS_JSON{\"version\":\"$NUM_VERSION\",\"path\":\"$VERSION/\"}"
done
VERSIONS_JSON="$VERSIONS_JSON]"
# Update the layout template with the versions JSON
sed -i "s|__VERSIONS_JSON__|$VERSIONS_JSON|g" docs/source/_templates/layout.html
# Clean up
rm -rf gh-pages-clone
else
# For local development or PR builds, use an empty array
sed -i "s|__VERSIONS_JSON__|[]|g" docs/source/_templates/layout.html
fi
# Build the documentation
sphinx-build docs/source docs/build
- name: Deploy to GitHub Pages (dev branch)
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/dev' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/
destination_dir: dev
force_orphan: false
keep_files: true
- name: Deploy to GitHub Pages (version specific)
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/
destination_dir: v${{ env.PACKAGE_VERSION }}
force_orphan: false
keep_files: true
- name: Deploy to GitHub Pages (latest stable)
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/
destination_dir: latest
force_orphan: false
keep_files: true
- name: Generate root index page
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) }}
run: |
# Create a temporary directory for the root content
mkdir -p temp_root
# Copy the root index template
cp docs/source/_static/root_index.html temp_root/index.html
# Clone the gh-pages branch to get version information
git clone --quiet --branch=gh-pages --depth=1 https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git gh-pages-clone
# Find version directories
VERSION_DIRS=$(find gh-pages-clone -maxdepth 1 -type d | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -r)
# Create JSON array of versions
VERSIONS_JSON="["
for dir in $VERSION_DIRS; do
VERSION=$(basename $dir)
# Extract numeric version without 'v' prefix
NUM_VERSION=${VERSION#v}
if [ "$VERSIONS_JSON" != "[" ]; then
VERSIONS_JSON="$VERSIONS_JSON,"
fi
VERSIONS_JSON="$VERSIONS_JSON{\"version\":\"$NUM_VERSION\",\"path\":\"$VERSION/\"}"
done
VERSIONS_JSON="$VERSIONS_JSON]"
# Update the index.html with the versions JSON - using a different approach
sed -i "s|__VERSIONS_JSON__|$VERSIONS_JSON|g" temp_root/index.html
# Clean up
rm -rf gh-pages-clone
- name: Deploy root index
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: temp_root/
destination_dir: ./
force_orphan: false
keep_files: true