-
Notifications
You must be signed in to change notification settings - Fork 13
176 lines (152 loc) · 4.98 KB
/
docs.yml
File metadata and controls
176 lines (152 loc) · 4.98 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: docs
permissions:
contents: write
pull-requests: write
on:
push:
branches:
- main
paths:
- .pre-commit-config.yaml
- .github/workflows/docs.yml
- '**.py'
- '**.ipynb'
- '**.html'
- '**.js'
- '**.md'
- uv.lock
- pyproject.toml
- mkdocs.yml
- '**.png'
- '**.svg'
pull_request:
branches:
- main
paths:
- .pre-commit-config.yaml
- .github/workflows/docs.yml
- '**.py'
- '**.ipynb'
- '**.js'
- '**.html'
- uv.lock
- pyproject.toml
- '**.md'
- mkdocs.yml
- '**.png'
- '**.svg'
release:
types: [published]
# Allow manual trigger
workflow_dispatch:
inputs:
version:
description: 'Version to deploy (e.g., 0.5.0, latest)'
required: true
default: 'latest'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0 # Fetch all history for proper versioning
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "0.5.21"
enable-cache: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Install the project
run: uv sync --group docs --prerelease=allow
- name: Build docs
run: uv run --frozen mkdocs build
- name: Create .nojekyll file
run: touch site/.nojekyll
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: docs-site
path: site/
retention-days: 1
deploy:
needs: build
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' || github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0 # Fetch all history for proper versioning
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "0.5.21"
enable-cache: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Install the project
run: uv sync --group docs --frozen
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Download artifact
uses: actions/download-artifact@v8
with:
name: docs-site
path: site
- name: Ensure .nojekyll exists
run: touch site/.nojekyll
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Use the version provided in the workflow dispatch
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "release" ]]; then
# Use the tag from the release
VERSION="${{ github.ref_name }}"
# Remove 'v' prefix if present
VERSION="${VERSION#v}"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
# For pushes to main, tag as "main"
echo "VERSION=main" >> $GITHUB_OUTPUT
# No alias for main
echo "VERSION_ALIAS=" >> $GITHUB_OUTPUT
else
# Get version from pyproject.toml as fallback
VERSION=$(grep -m 1 '^version = ' pyproject.toml | sed 's/^version = "\(.*\)"$/\1/')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION_ALIAS=latest" >> $GITHUB_OUTPUT
fi
- name: Deploy docs with mike
run: |
VERSION=${{ steps.version.outputs.VERSION }}
ALIAS=${{ steps.version.outputs.VERSION_ALIAS }}
# Add a temporary remote to fetch gh-pages if it exists
git remote add temp https://github.com/${{ github.repository }}.git || true
git fetch temp gh-pages || true
DEPLOY_ARGS="--push --update-aliases $VERSION"
if [[ ! -z "$ALIAS" ]]; then
DEPLOY_ARGS="$DEPLOY_ARGS $ALIAS"
fi
# Activate the virtual environment
source .venv/bin/activate
echo "Running: mike deploy $DEPLOY_ARGS"
mike deploy $DEPLOY_ARGS
# Set default version to latest only if we're deploying a version with the latest alias
if [[ ! -z "$ALIAS" && "$ALIAS" == "latest" ]]; then
mike set-default --push latest
fi
# Remove the temporary remote
git remote remove temp || true