Skip to content

Adjust docs build

Adjust docs build #10

Workflow file for this run

name: Deploy Docs
on:
release:
types: [created]
pull_request:
branches: [main]
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Determine version and build type
id: version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "VERSION=stable" >> $GITHUB_OUTPUT
echo "DIR=stable" >> $GITHUB_OUTPUT
echo "TAG=${{ github.ref_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "VERSION=latest" >> $GITHUB_OUTPUT
echo "DIR=latest" >> $GITHUB_OUTPUT
echo "TAG=main" >> $GITHUB_OUTPUT
else
echo "VERSION=preview" >> $GITHUB_OUTPUT
echo "DIR=preview-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
fi
- name: Generate versions.json
run: |
cat <<EOF > docs/versions.json
[
{
"version": "latest",
"url": "https://xarray-contrib.github.io/xarray-dataclass/latest/",
"name": "latest"
},
{
"version": "stable",
"url": "https://xarray-contrib.github.io/xarray-dataclass/stable/",
"name": "stable"
}
]
EOF
- name: Build documentation
env:
DOCS_VERSION: ${{ steps.version.outputs.VERSION }}
run: |
python -m sphinx -b html docs docs/_build/${{ steps.version.outputs.DIR }}
- name: Copy versions.json
run: cp docs/versions.json docs/_build/${{ steps.version.outputs.DIR }}/
- name: Create redirect index.html
if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
run: |
mkdir -p docs/_build
cat <<EOF > docs/_build/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=./${{ steps.version.outputs.DIR }}/">
<title>Redirect to ${{ steps.version.outputs.VERSION }} documentation</title>
</head>
<body>
<p>If you are not redirected automatically, follow this <a href="./${{ steps.version.outputs.DIR }}/">link to the ${{ steps.version.outputs.VERSION }} documentation</a>.</p>
</body>
</html>
EOF
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build
destination_dir: .