Test 1 #50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | | |
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 | |
- 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 | |
- 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 | |
- 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 | |
# If on gh-pages branch, get list of version directories and update the index.html | |
if [ -d "temp_root" ]; 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 index.html with the versions list | |
sed -i "s|// This array will be populated by the GitHub Action|$VERSIONS_JSON|g" temp_root/index.html | |
# Clean up | |
rm -rf gh-pages-clone | |
fi | |
- 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 |