Repository navigation
235 lines (207 loc) · 8.62 KB
/
Copy pathdocs.yml
File metadata and controls
235 lines (207 loc) · 8.62 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Deploy Documentation
on:
push:
branches: [ "main" ]
paths:
- 'docs/**'
- '.github/workflows/docs.yml'
pull_request:
branches: [ "main" ]
paths:
- 'docs/**'
- '.github/workflows/docs.yml'
workflow_dispatch:
inputs:
tag_name:
description: 'The release tag to publish (e.g., v0.4.0).'
required: true
type: string
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch' || !contains(github.event.inputs.tag_name, '-')
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.inputs.tag_name || github.ref }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # stable
with:
toolchain: stable
- name: Install mdBook
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.52/mdbook-v0.4.52-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Install mdBook Tabs
run: |
# Pinned to the last 0.4-compatible release; mdbook-tabs 0.3+ requires mdBook 0.5.
cargo install mdbook-tabs --version 0.2.3
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install mdbook-mermaid
run: |
curl -sSL https://github.com/badboy/mdbook-mermaid/releases/download/v0.14.0/mdbook-mermaid-v0.14.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Setup Pages
id: pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Determine version
id: version
env:
INPUT_TAG: ${{ github.event.inputs.tag_name }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="$INPUT_TAG"
else
VERSION="latest"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Building documentation for version: $VERSION"
- name: Build with mdBook
run: |
cd docs
mdbook build
- name: Download existing GitHub Pages content
run: |
# IMPORTANT: GitHub Pages deployments completely replace the entire site with
# the uploaded artifact. Without this preservation step, deploying a new version
# (e.g., v0.4.0) would delete all previously published versions (e.g., v0.3.0, latest).
# We fetch content from the gh-pages branch and merge it with the new version
# to maintain a complete multi-version documentation site.
echo "Attempting to download existing site content..."
mkdir -p public
# Save current commit for returning later
CURRENT_COMMIT=$(git rev-parse HEAD)
# Try to download existing site as a tarball from gh-pages branch
if git ls-remote --heads origin gh-pages >/dev/null 2>&1; then
echo "gh-pages branch exists, fetching existing content..."
git fetch origin gh-pages:gh-pages || true
git checkout gh-pages -- . 2>/dev/null || echo "No existing gh-pages content"
# Move existing content to public if it exists
if [ -d "wassette" ]; then
cp -r wassette public/ || true
fi
# Return to original commit
git checkout $CURRENT_COMMIT || echo "Could not return to original commit"
else
echo "gh-pages branch does not exist yet, starting fresh"
fi
- name: Prepare versioned output
run: |
# Create directory structure for this version
mkdir -p public/wassette/${{ steps.version.outputs.version }}
# Copy newly built docs to the version directory
cp -r docs/book/* public/wassette/${{ steps.version.outputs.version }}/
# Create root redirect page (this should NOT be in docs source, only at GitHub Pages root)
cat > public/wassette/index.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=latest/">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting to Wassette Documentation</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f5f5f5;
}
.message {
text-align: center;
padding: 2rem;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
a {
color: #4183c4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="message">
<h1>Redirecting to Wassette Documentation</h1>
<p>If you are not redirected automatically, <a href="latest/">click here</a>.</p>
</div>
</body>
</html>
EOF
# Load or create versions.json
if [ -f "public/wassette/versions.json" ]; then
echo "Using existing versions.json"
cp public/wassette/versions.json versions.json.tmp
else
echo "Creating new versions.json"
cp docs/versions.json versions.json.tmp
fi
# Update versions.json with current version
python3 << 'EOF'
import json
version = "${{ steps.version.outputs.version }}"
try:
with open("versions.json.tmp", "r") as f:
data = json.load(f)
except:
data = {"versions": ["latest"], "latest": "latest"}
# Add current version if it's not already in the list
if version not in data["versions"]:
# Insert version after "latest" if it's a tag
if version.startswith("v"):
if "latest" in data["versions"]:
idx = data["versions"].index("latest") + 1
data["versions"].insert(idx, version)
else:
data["versions"].insert(0, version)
else:
# Ensure "latest" is first
if "latest" not in data["versions"]:
data["versions"].insert(0, "latest")
with open("public/wassette/versions.json", "w") as f:
json.dump(data, f, indent=2)
print(f"Updated versions.json with version: {version}")
print(f"All versions: {data['versions']}")
EOF
echo "Current versions.json:"
cat public/wassette/versions.json
echo ""
echo "Directory structure:"
ls -la public/wassette/
- name: Upload artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: public/wassette
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && !contains(github.event.inputs.tag_name, '-'))
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1