|
6 | 6 | paths: |
7 | 7 | - 'docs/**' |
8 | 8 | - '.github/workflows/docs.yml' |
| 9 | + tags: |
| 10 | + - 'v*' |
9 | 11 | pull_request: |
10 | 12 | branches: [ "main" ] |
11 | 13 | paths: |
@@ -48,19 +50,164 @@ jobs: |
48 | 50 | cargo install mdbook-tabs |
49 | 51 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
50 | 52 |
|
| 53 | + - name: Install mdbook-mermaid |
| 54 | + run: | |
| 55 | + 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 |
| 56 | + echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH |
| 57 | +
|
51 | 58 | - name: Setup Pages |
52 | 59 | id: pages |
53 | 60 | uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0 |
54 | 61 |
|
| 62 | + - name: Determine version |
| 63 | + id: version |
| 64 | + run: | |
| 65 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 66 | + VERSION="${{ github.ref_name }}" |
| 67 | + else |
| 68 | + VERSION="latest" |
| 69 | + fi |
| 70 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 71 | + echo "Building documentation for version: $VERSION" |
| 72 | +
|
55 | 73 | - name: Build with mdBook |
56 | 74 | run: | |
57 | 75 | cd docs |
58 | 76 | mdbook build |
59 | 77 |
|
| 78 | + - name: Download existing GitHub Pages content |
| 79 | + run: | |
| 80 | + # IMPORTANT: GitHub Pages deployments completely replace the entire site with |
| 81 | + # the uploaded artifact. Without this preservation step, deploying a new version |
| 82 | + # (e.g., v0.4.0) would delete all previously published versions (e.g., v0.3.0, latest). |
| 83 | + # We fetch content from the gh-pages branch and merge it with the new version |
| 84 | + # to maintain a complete multi-version documentation site. |
| 85 | + echo "Attempting to download existing site content..." |
| 86 | + mkdir -p public |
| 87 | + |
| 88 | + # Save current commit for returning later |
| 89 | + CURRENT_COMMIT=$(git rev-parse HEAD) |
| 90 | + |
| 91 | + # Try to download existing site as a tarball from gh-pages branch |
| 92 | + if git ls-remote --heads origin gh-pages >/dev/null 2>&1; then |
| 93 | + echo "gh-pages branch exists, fetching existing content..." |
| 94 | + git fetch origin gh-pages:gh-pages || true |
| 95 | + git checkout gh-pages -- . 2>/dev/null || echo "No existing gh-pages content" |
| 96 | + # Move existing content to public if it exists |
| 97 | + if [ -d "wassette" ]; then |
| 98 | + cp -r wassette public/ || true |
| 99 | + fi |
| 100 | + # Return to original commit |
| 101 | + git checkout $CURRENT_COMMIT || echo "Could not return to original commit" |
| 102 | + else |
| 103 | + echo "gh-pages branch does not exist yet, starting fresh" |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Prepare versioned output |
| 107 | + run: | |
| 108 | + # Create directory structure for this version |
| 109 | + mkdir -p public/wassette/${{ steps.version.outputs.version }} |
| 110 | +
|
| 111 | + # Copy newly built docs to the version directory |
| 112 | + cp -r docs/book/* public/wassette/${{ steps.version.outputs.version }}/ |
| 113 | +
|
| 114 | + # Create root redirect page (this should NOT be in docs source, only at GitHub Pages root) |
| 115 | + cat > public/wassette/index.html << 'EOF' |
| 116 | + <!DOCTYPE html> |
| 117 | + <html lang="en"> |
| 118 | + <head> |
| 119 | + <meta charset="UTF-8"> |
| 120 | + <meta http-equiv="refresh" content="0; url=latest/"> |
| 121 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 122 | + <title>Redirecting to Wassette Documentation</title> |
| 123 | + <style> |
| 124 | + body { |
| 125 | + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; |
| 126 | + display: flex; |
| 127 | + justify-content: center; |
| 128 | + align-items: center; |
| 129 | + height: 100vh; |
| 130 | + margin: 0; |
| 131 | + background-color: #f5f5f5; |
| 132 | + } |
| 133 | + .message { |
| 134 | + text-align: center; |
| 135 | + padding: 2rem; |
| 136 | + background: white; |
| 137 | + border-radius: 8px; |
| 138 | + box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
| 139 | + } |
| 140 | + a { |
| 141 | + color: #4183c4; |
| 142 | + text-decoration: none; |
| 143 | + } |
| 144 | + a:hover { |
| 145 | + text-decoration: underline; |
| 146 | + } |
| 147 | + </style> |
| 148 | + </head> |
| 149 | + <body> |
| 150 | + <div class="message"> |
| 151 | + <h1>Redirecting to Wassette Documentation</h1> |
| 152 | + <p>If you are not redirected automatically, <a href="latest/">click here</a>.</p> |
| 153 | + </div> |
| 154 | + </body> |
| 155 | + </html> |
| 156 | + EOF |
| 157 | + |
| 158 | + # Load or create versions.json |
| 159 | + if [ -f "public/wassette/versions.json" ]; then |
| 160 | + echo "Using existing versions.json" |
| 161 | + cp public/wassette/versions.json versions.json.tmp |
| 162 | + else |
| 163 | + echo "Creating new versions.json" |
| 164 | + cp docs/versions.json versions.json.tmp |
| 165 | + fi |
| 166 | + |
| 167 | + # Update versions.json with current version |
| 168 | + python3 << 'EOF' |
| 169 | + import json |
| 170 | + |
| 171 | + version = "${{ steps.version.outputs.version }}" |
| 172 | + |
| 173 | + try: |
| 174 | + with open("versions.json.tmp", "r") as f: |
| 175 | + data = json.load(f) |
| 176 | + except: |
| 177 | + data = {"versions": ["latest"], "latest": "latest"} |
| 178 | + |
| 179 | + # Add current version if it's not already in the list |
| 180 | + if version not in data["versions"]: |
| 181 | + # Insert version after "latest" if it's a tag |
| 182 | + if version.startswith("v"): |
| 183 | + if "latest" in data["versions"]: |
| 184 | + idx = data["versions"].index("latest") + 1 |
| 185 | + data["versions"].insert(idx, version) |
| 186 | + else: |
| 187 | + data["versions"].insert(0, version) |
| 188 | + else: |
| 189 | + # Ensure "latest" is first |
| 190 | + if "latest" not in data["versions"]: |
| 191 | + data["versions"].insert(0, "latest") |
| 192 | + |
| 193 | + with open("public/wassette/versions.json", "w") as f: |
| 194 | + json.dump(data, f, indent=2) |
| 195 | + |
| 196 | + print(f"Updated versions.json with version: {version}") |
| 197 | + print(f"All versions: {data['versions']}") |
| 198 | + EOF |
| 199 | + |
| 200 | + echo "Current versions.json:" |
| 201 | + cat public/wassette/versions.json |
| 202 | + |
| 203 | + echo "" |
| 204 | + echo "Directory structure:" |
| 205 | + ls -la public/wassette/ |
| 206 | +
|
60 | 207 | - name: Upload artifact |
61 | 208 | uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 |
62 | 209 | with: |
63 | | - path: docs/book |
| 210 | + path: public/wassette |
64 | 211 |
|
65 | 212 | # Deployment job |
66 | 213 | deploy: |
|
69 | 216 | url: ${{ steps.deployment.outputs.page_url }} |
70 | 217 | runs-on: ubuntu-latest |
71 | 218 | needs: build |
72 | | - if: github.ref == 'refs/heads/main' |
| 219 | + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') |
73 | 220 | steps: |
74 | 221 | - name: Deploy to GitHub Pages |
75 | 222 | id: deployment |
|
0 commit comments