|
| 1 | +# Multi-Version Documentation System |
| 2 | + |
| 3 | +This repository implements a multi-version documentation system that publishes different versions of the documentation to GitHub Pages. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The system supports three types of documentation deployments: |
| 8 | + |
| 9 | +1. **Stable Documentation** (`main` branch) → Published at https://docs.openspp.org/ |
| 10 | +2. **Preview Documentation** (feature branches) → Published at https://docs.openspp.org/previews/{branch-name}/ |
| 11 | +3. **Version Releases** (future) → Published at https://docs.openspp.org/{version}/ |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +### Environment Variables |
| 16 | + |
| 17 | +The build system uses environment variables to configure each build: |
| 18 | + |
| 19 | +- `DOCS_VERSION`: Version identifier (e.g., "stable", "refactor-structure") |
| 20 | +- `DOCS_BASEURL`: Base URL for the documentation (e.g., "https://docs.openspp.org/") |
| 21 | +- `IS_PREVIEW`: Set to "1" for preview builds, "0" for stable/release builds |
| 22 | + |
| 23 | +### SEO Protection |
| 24 | + |
| 25 | +Preview builds are protected from search engine indexing: |
| 26 | + |
| 27 | +1. **Meta Tags**: Preview builds include `<meta name="robots" content="noindex,nofollow,noarchive">` |
| 28 | +2. **robots.txt**: Only deployed with stable builds, blocks `/previews/` directory |
| 29 | +3. **Visual Indicator**: Preview builds show a warning banner to users |
| 30 | + |
| 31 | +### GitHub Actions Workflow |
| 32 | + |
| 33 | +The `.github/workflows/build_deploy.yml` workflow handles automatic deployment: |
| 34 | + |
| 35 | +- Triggers on push to any branch |
| 36 | +- Main branch deploys to root as stable documentation |
| 37 | +- Other branches deploy to `/previews/{sanitized-branch-name}/` |
| 38 | +- Branch names are sanitized (special characters replaced with hyphens, limited to 50 chars) |
| 39 | + |
| 40 | +### Version Switcher |
| 41 | + |
| 42 | +The documentation includes a version switcher dropdown configured via `docs/_static/switcher.json`. |
| 43 | + |
| 44 | +**Important Note:** sphinx-book-theme version 0.3.3 doesn't have built-in version switcher support. The current implementation uses a custom JavaScript solution (`_static/version_switcher.js`). For full native support, consider upgrading to sphinx-book-theme >= 1.0.0. |
| 45 | + |
| 46 | +#### Managing Versions |
| 47 | + |
| 48 | +Use the helper script to manage versions: |
| 49 | + |
| 50 | +```bash |
| 51 | +# List current versions |
| 52 | +python Scripts/update_version_switcher.py list |
| 53 | + |
| 54 | +# Add a new version |
| 55 | +python Scripts/update_version_switcher.py add \ |
| 56 | + --version "1.2" \ |
| 57 | + --name "Version 1.2" \ |
| 58 | + --url "https://docs.openspp.org/1.2/" |
| 59 | + |
| 60 | +# Remove a version |
| 61 | +python Scripts/update_version_switcher.py remove --version "old-preview" |
| 62 | +``` |
| 63 | + |
| 64 | +### Cleanup of Old Previews |
| 65 | + |
| 66 | +The `.github/workflows/cleanup_previews.yml` workflow automatically removes old preview deployments: |
| 67 | + |
| 68 | +- Runs weekly (Sunday at 00:00 UTC) |
| 69 | +- Can be manually triggered |
| 70 | +- Keeps previews newer than 30 days (configurable) |
| 71 | +- Always keeps at least 10 newest previews (configurable) |
| 72 | +- Updates version switcher when removing previews |
| 73 | + |
| 74 | +To manually trigger cleanup: |
| 75 | +1. Go to Actions → Cleanup old preview deployments |
| 76 | +2. Click "Run workflow" |
| 77 | +3. Optionally adjust keep_days and keep_count parameters |
| 78 | + |
| 79 | +## Local Testing |
| 80 | + |
| 81 | +To test multi-version builds locally: |
| 82 | + |
| 83 | +```bash |
| 84 | +# Test stable build |
| 85 | +export DOCS_VERSION=stable |
| 86 | +export DOCS_BASEURL=https://docs.openspp.org/ |
| 87 | +export IS_PREVIEW=0 |
| 88 | +make html |
| 89 | + |
| 90 | +# Test preview build |
| 91 | +export DOCS_VERSION=my-feature |
| 92 | +export DOCS_BASEURL=https://docs.openspp.org/previews/my-feature/ |
| 93 | +export IS_PREVIEW=1 |
| 94 | +make html |
| 95 | +``` |
| 96 | + |
| 97 | +## Security Features |
| 98 | + |
| 99 | +The implementation includes several security measures: |
| 100 | + |
| 101 | +1. **Branch Name Sanitization**: Only alphanumeric, dots, underscores, and hyphens allowed |
| 102 | +2. **Path Traversal Protection**: Version switcher script validates file paths |
| 103 | +3. **Input Validation**: URLs and version names are validated to prevent injection |
| 104 | +4. **Atomic File Operations**: Prevents corruption during concurrent updates |
| 105 | +5. **Error Handling**: Build failures are properly caught and reported |
| 106 | + |
| 107 | +## Maintenance |
| 108 | + |
| 109 | +### Adding a New Release Version |
| 110 | + |
| 111 | +When creating a new release (e.g., v1.2): |
| 112 | + |
| 113 | +1. Tag the release in git |
| 114 | +2. Update the version switcher: |
| 115 | + ```bash |
| 116 | + python Scripts/update_version_switcher.py add \ |
| 117 | + --version "1.2" \ |
| 118 | + --name "v1.2 (latest)" \ |
| 119 | + --url "https://docs.openspp.org/1.2/" |
| 120 | + ``` |
| 121 | +3. The GitHub Actions workflow will build and deploy to `/1.2/` |
| 122 | + |
| 123 | +### Monitoring |
| 124 | + |
| 125 | +- Check GitHub Actions for build status |
| 126 | +- Review cleanup workflow runs for removed previews |
| 127 | +- Monitor disk usage on GitHub Pages |
| 128 | + |
| 129 | +## Troubleshooting |
| 130 | + |
| 131 | +### Preview Not Appearing |
| 132 | + |
| 133 | +1. Check GitHub Actions for build failures |
| 134 | +2. Verify branch name doesn't contain invalid characters |
| 135 | +3. Check that `keep_files: true` is set in the workflow |
| 136 | + |
| 137 | +### Version Switcher Not Updated |
| 138 | + |
| 139 | +1. Ensure switcher.json is valid JSON |
| 140 | +2. Check file permissions on gh-pages branch |
| 141 | +3. Verify the update script ran successfully |
| 142 | + |
| 143 | +### SEO Issues |
| 144 | + |
| 145 | +1. Verify preview builds have noindex meta tag |
| 146 | +2. Check robots.txt is only present in stable build |
| 147 | +3. Test with Google Search Console or similar tools |
| 148 | + |
| 149 | +## Future Enhancements |
| 150 | + |
| 151 | +- Automatic version detection from git tags |
| 152 | +- PR comment with preview URL |
| 153 | +- Build caching for faster deployments |
| 154 | +- Version-specific search functionality |
0 commit comments