-
Notifications
You must be signed in to change notification settings - Fork 49
86 lines (76 loc) · 2.92 KB
/
docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: docs
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [created]
workflow_dispatch:
jobs:
docs:
runs-on: ubuntu-latest
steps:
# Check out source.
- uses: actions/checkout@v2
with:
fetch-depth: 0 # This ensures the entire history is fetched so we can switch branches
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.10"
- name: Set up dependencies
run: |
pip install uv
uv pip install --system -e ".[dev]"
uv pip install --system -r docs/requirements.txt
# Get version from pyproject.toml.
- name: Get version + subdirectory
run: |
VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "DOCS_SUBDIR=versions/$VERSION" >> $GITHUB_ENV
# Hack to overwrite version.
- name: Set version to 'latest' for pushes (this will appear in the doc banner)
run: |
python -c "import toml; conf = toml.load('pyproject.toml'); conf['project']['version'] = 'latest'; toml.dump(conf, open('pyproject.toml', 'w'))"
if: github.event_name == 'push'
# Build documentation.
- name: Building documentation
run: |
sphinx-build docs/source docs/build -b dirhtml
# Get version from pyproject.toml.
- name: Override subdirectory to `latest/` for pushes
run: |
echo "DOCS_SUBDIR=latest" >> $GITHUB_ENV
if: github.event_name == 'push'
# Deploy to version-dependent subdirectory.
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build
destination_dir: ${{ env.DOCS_SUBDIR }}
keep_files: false # This will only erase the destination subdirectory.
cname: viser.studio
if: github.event_name != 'pull_request'
# We'll maintain an index of all versions under viser.studio/versions.
# This will be useful for dynamically generating lists of possible doc links.
- name: Update versions index.txt
run: |
git checkout . # Revert change to pyproject.toml from earlier...
git checkout gh-pages
git pull
git config --global user.email "[email protected]"
git config --global user.name "Brent Yi"
FILE="versions/index.txt" # Replace with your file path
if ! grep -qx "$VERSION" "$FILE"; then
echo "$VERSION" >> "$FILE"
git add $FILE
git commit -m "Update versions.txt with new version $VERSION"
git push origin gh-pages
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
if: github.event_name == 'release'