|
| 1 | +name: docs |
| 2 | +permissions: |
| 3 | + contents: write |
| 4 | + pull-requests: write |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + paths: |
| 11 | + - .pre-commit-config.yaml |
| 12 | + - .github/workflows/docs.yml |
| 13 | + - '**.py' |
| 14 | + - '**.ipynb' |
| 15 | + - '**.html' |
| 16 | + - '**.js' |
| 17 | + - '**.md' |
| 18 | + - uv.lock |
| 19 | + - pyproject.toml |
| 20 | + - mkdocs.yml |
| 21 | + - '**.png' |
| 22 | + - '**.svg' |
| 23 | + pull_request: |
| 24 | + branches: |
| 25 | + - main |
| 26 | + paths: |
| 27 | + - .pre-commit-config.yaml |
| 28 | + - .github/workflows/docs.yml |
| 29 | + - '**.py' |
| 30 | + - '**.ipynb' |
| 31 | + - '**.js' |
| 32 | + - '**.html' |
| 33 | + - uv.lock |
| 34 | + - pyproject.toml |
| 35 | + - '**.md' |
| 36 | + - mkdocs.yml |
| 37 | + - '**.png' |
| 38 | + - '**.svg' |
| 39 | + release: |
| 40 | + types: [published] |
| 41 | + # Allow manual trigger |
| 42 | + workflow_dispatch: |
| 43 | + inputs: |
| 44 | + version: |
| 45 | + description: 'Version to deploy (e.g., 0.5.0, latest)' |
| 46 | + required: true |
| 47 | + default: 'latest' |
| 48 | + |
| 49 | +jobs: |
| 50 | + build: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v4.2.2 |
| 55 | + with: |
| 56 | + fetch-depth: 0 # Fetch all history for proper versioning |
| 57 | + |
| 58 | + - name: Install uv |
| 59 | + uses: astral-sh/setup-uv@v5 |
| 60 | + with: |
| 61 | + version: "0.5.21" |
| 62 | + enable-cache: true |
| 63 | + |
| 64 | + - name: Set up Python |
| 65 | + uses: actions/setup-python@v5 |
| 66 | + with: |
| 67 | + python-version-file: ".python-version" |
| 68 | + |
| 69 | + - name: Install the project |
| 70 | + run: uv sync --all-extras --group docs |
| 71 | + |
| 72 | + - name: Build docs |
| 73 | + run: uv run mkdocs build |
| 74 | + |
| 75 | + - name: Create .nojekyll file |
| 76 | + run: touch site/.nojekyll |
| 77 | + |
| 78 | + - name: Upload artifact |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: docs-site |
| 82 | + path: site/ |
| 83 | + retention-days: 1 |
| 84 | + |
| 85 | + deploy: |
| 86 | + needs: build |
| 87 | + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' || github.event_name == 'release' |
| 88 | + runs-on: ubuntu-latest |
| 89 | + steps: |
| 90 | + - name: Checkout code |
| 91 | + uses: actions/checkout@v4.2.2 |
| 92 | + with: |
| 93 | + fetch-depth: 0 # Fetch all history for proper versioning |
| 94 | + |
| 95 | + - name: Install uv |
| 96 | + uses: astral-sh/setup-uv@v5 |
| 97 | + with: |
| 98 | + version: "0.5.21" |
| 99 | + enable-cache: true |
| 100 | + |
| 101 | + - name: Set up Python |
| 102 | + uses: actions/setup-python@v5 |
| 103 | + with: |
| 104 | + python-version-file: ".python-version" |
| 105 | + |
| 106 | + - name: Install the project |
| 107 | + run: uv sync --all-extras --group docs |
| 108 | + |
| 109 | + - name: Configure Git Credentials |
| 110 | + run: | |
| 111 | + git config user.name github-actions[bot] |
| 112 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 113 | +
|
| 114 | + - name: Download artifact |
| 115 | + uses: actions/download-artifact@v4 |
| 116 | + with: |
| 117 | + name: docs-site |
| 118 | + path: site |
| 119 | + |
| 120 | + - name: Ensure .nojekyll exists |
| 121 | + run: touch site/.nojekyll |
| 122 | + |
| 123 | + - name: Determine version |
| 124 | + id: version |
| 125 | + run: | |
| 126 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 127 | + # Use the version provided in the workflow dispatch |
| 128 | + echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 129 | + echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT |
| 130 | + elif [[ "${{ github.event_name }}" == "release" ]]; then |
| 131 | + # Use the tag from the release |
| 132 | + VERSION="${{ github.ref_name }}" |
| 133 | + # Remove 'v' prefix if present |
| 134 | + VERSION="${VERSION#v}" |
| 135 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 136 | + echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT |
| 137 | + elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 138 | + # For pushes to main, tag as "main" |
| 139 | + echo "VERSION=main" >> $GITHUB_OUTPUT |
| 140 | + # No alias for main |
| 141 | + echo "VERSION_ALIAS=" >> $GITHUB_OUTPUT |
| 142 | + else |
| 143 | + # Get version from pyproject.toml as fallback |
| 144 | + VERSION=$(grep -m 1 '^version = ' pyproject.toml | sed 's/^version = "\(.*\)"$/\1/') |
| 145 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 146 | + echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT |
| 147 | + fi |
| 148 | +
|
| 149 | + - name: Deploy docs with mike |
| 150 | + run: | |
| 151 | + VERSION=${{ steps.version.outputs.VERSION }} |
| 152 | + ALIAS=${{ steps.version.outputs.VERSION_ALIAS }} |
| 153 | +
|
| 154 | + # Add a temporary remote to fetch gh-pages if it exists |
| 155 | + git remote add temp https://github.com/${{ github.repository }}.git || true |
| 156 | + git fetch temp gh-pages || true |
| 157 | +
|
| 158 | + DEPLOY_ARGS="--push --update-aliases $VERSION" |
| 159 | +
|
| 160 | + if [[ ! -z "$ALIAS" ]]; then |
| 161 | + DEPLOY_ARGS="$DEPLOY_ARGS $ALIAS" |
| 162 | + fi |
| 163 | +
|
| 164 | + # Activate the virtual environment |
| 165 | + source .venv/bin/activate |
| 166 | +
|
| 167 | + echo "Running: mike deploy $DEPLOY_ARGS" |
| 168 | + mike deploy $DEPLOY_ARGS |
| 169 | +
|
| 170 | + # Set default version to latest only if we're deploying a version with the latest alias |
| 171 | + if [[ ! -z "$ALIAS" && "$ALIAS" == "latest" ]]; then |
| 172 | + mike set-default --push latest |
| 173 | + fi |
| 174 | +
|
| 175 | + # Remove the temporary remote |
| 176 | + git remote remove temp || true |
0 commit comments