|
| 1 | +name: Deploy MkDocs site to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pages: write |
| 12 | + id-token: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: pages |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + deploy: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + environment: |
| 22 | + name: github-pages |
| 23 | + url: ${{ steps.deployment.outputs.page_url }} |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: '3.11' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + if [ -f requirements.txt ]; then |
| 37 | + python -m pip install -r requirements.txt |
| 38 | + else |
| 39 | + python -m pip install mkdocs |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Build MkDocs site |
| 43 | + run: mkdocs build --strict --clean --site-dir dist |
| 44 | + |
| 45 | + - name: Configure GitHub Pages |
| 46 | + uses: actions/configure-pages@v5 |
| 47 | + with: |
| 48 | + enablement: true |
| 49 | + continue-on-error: true |
| 50 | + |
| 51 | + - name: Verify Pages is enabled |
| 52 | + env: |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + api_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/pages" |
| 57 | + status="$(curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" -o /tmp/pages-response.json -w "%{http_code}" "${api_url}")" |
| 58 | + if [ "${status}" = "404" ]; then |
| 59 | + echo "::error::Enable GitHub Pages: Settings → Pages → Source = GitHub Actions and Settings → Actions → Workflow permissions = Read and write." |
| 60 | + exit 1 |
| 61 | + elif [ "${status}" != "200" ]; then |
| 62 | + echo "::error::Failed to verify GitHub Pages (HTTP ${status})." |
| 63 | + cat /tmp/pages-response.json |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Upload Pages artifact |
| 68 | + uses: actions/upload-pages-artifact@v3 |
| 69 | + with: |
| 70 | + path: ./dist |
| 71 | + |
| 72 | + - name: Deploy to GitHub Pages |
| 73 | + id: deployment |
| 74 | + uses: actions/deploy-pages@v4 |
0 commit comments