|
1 | | -name: Deploy Docs |
| 1 | +name: GitHub Pages |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | release: |
5 | | - types: [created] |
6 | | - pull_request: |
7 | | - branches: [main] |
8 | | - push: |
9 | | - branches: [main] |
| 5 | + types: |
| 6 | + - created |
10 | 7 |
|
11 | 8 | jobs: |
12 | | - build: |
| 9 | + job: |
| 10 | + name: GitHub Pages |
13 | 11 | runs-on: ubuntu-latest |
14 | 12 | steps: |
15 | 13 | - uses: actions/checkout@v4 |
16 | | - with: |
17 | | - fetch-depth: 0 |
18 | 14 | - uses: actions/setup-python@v5 |
19 | 15 | with: |
20 | | - python-version: "3.11" |
21 | | - - name: Install dependencies |
| 16 | + python-version: "3.13" |
| 17 | + - name: Install project dependencies |
22 | 18 | run: pip install -e ".[dev]" |
23 | | - - name: Determine version and build type |
24 | | - id: version |
25 | | - run: | |
26 | | - if [[ "${{ github.event_name }}" == "release" ]]; then |
27 | | - echo "VERSION=stable" >> $GITHUB_OUTPUT |
28 | | - echo "DIR=stable" >> $GITHUB_OUTPUT |
29 | | - echo "TAG=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
30 | | - elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then |
31 | | - echo "VERSION=latest" >> $GITHUB_OUTPUT |
32 | | - echo "DIR=latest" >> $GITHUB_OUTPUT |
33 | | - echo "TAG=main" >> $GITHUB_OUTPUT |
34 | | - else |
35 | | - echo "VERSION=preview" >> $GITHUB_OUTPUT |
36 | | - echo "DIR=preview-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT |
37 | | - echo "TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT |
38 | | - fi |
39 | | - - name: Generate versions.json |
40 | | - run: | |
41 | | - cat <<EOF > docs/versions.json |
42 | | - [ |
43 | | - { |
44 | | - "version": "latest", |
45 | | - "url": "https://xarray-contrib.github.io/xarray-dataclass/latest/", |
46 | | - "name": "latest" |
47 | | - }, |
48 | | - { |
49 | | - "version": "stable", |
50 | | - "url": "https://xarray-contrib.github.io/xarray-dataclass/stable/", |
51 | | - "name": "stable" |
52 | | - } |
53 | | - ] |
54 | | - EOF |
55 | | - - name: Build documentation |
56 | | - env: |
57 | | - DOCS_VERSION: ${{ steps.version.outputs.VERSION }} |
58 | | - run: | |
59 | | - python -m sphinx -b html docs docs/_build/${{ steps.version.outputs.DIR }} |
60 | | - - name: Copy versions.json |
61 | | - run: cp docs/versions.json docs/_build/${{ steps.version.outputs.DIR }}/ |
62 | | - - name: Create redirect index.html |
63 | | - if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} |
64 | | - run: | |
65 | | - mkdir -p docs/_build |
66 | | - cat <<EOF > docs/_build/index.html |
67 | | - <!DOCTYPE html> |
68 | | - <html> |
69 | | - <head> |
70 | | - <meta charset="UTF-8"> |
71 | | - <meta http-equiv="refresh" content="0; url=./${{ steps.version.outputs.DIR }}/"> |
72 | | - <title>Redirect to ${{ steps.version.outputs.VERSION }} documentation</title> |
73 | | - </head> |
74 | | - <body> |
75 | | - <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> |
76 | | - </body> |
77 | | - </html> |
78 | | - EOF |
79 | | - - name: Deploy to GitHub Pages |
| 19 | + - name: Build docs |
| 20 | + run: python -m sphinx -b html docs docs/_build |
| 21 | + - name: Deploy docs |
80 | 22 | uses: peaceiris/actions-gh-pages@v3 |
81 | 23 | with: |
| 24 | + force_orphan: true |
82 | 25 | github_token: ${{ secrets.GITHUB_TOKEN }} |
83 | 26 | publish_dir: ./docs/_build |
84 | | - destination_dir: . |
0 commit comments