|
| 1 | +name: Build and deploy multi-version OpenSPP documentation |
| 2 | + |
| 3 | +# This workflow builds and deploys multi-version documentation: |
| 4 | +# - v1.3 (stable) from stable branch -> root (/) |
| 5 | +# - v2.0 from v2-odoo19-doc-refresh branch -> /v2.0/ |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - stable # Only run on stable branch |
| 11 | + workflow_dispatch: # Allow manual trigger |
| 12 | + |
| 13 | +jobs: |
| 14 | + build_multiversion: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout stable branch |
| 18 | + uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + ref: stable |
| 21 | + fetch-depth: 0 # Fetch all history for branch switching |
| 22 | + submodules: true |
| 23 | + |
| 24 | + - name: Set up Python 3.10 |
| 25 | + uses: actions/setup-python@v4 |
| 26 | + with: |
| 27 | + python-version: '3.10' |
| 28 | + |
| 29 | + - name: Install system dependencies |
| 30 | + run: | |
| 31 | + sudo apt-get update |
| 32 | + sudo apt-get install -y graphviz libsasl2-dev libldap2-dev libssl-dev |
| 33 | +
|
| 34 | + # ============================================ |
| 35 | + # BUILD v1.3 (from stable branch) -> ROOT |
| 36 | + # ============================================ |
| 37 | + - name: Install v1.3 dependencies (stable) |
| 38 | + run: | |
| 39 | + pip install -q -r requirements_frozen.txt |
| 40 | +
|
| 41 | + - name: Prepare v1.3 build |
| 42 | + run: | |
| 43 | + # Temporarily disable csvlexer import (not in requirements_frozen.txt) |
| 44 | + sed -i 's/from csvlexer.csv import CsvLexer/# from csvlexer.csv import CsvLexer # disabled for CI/' docs/conf.py |
| 45 | + sed -i "s/lexers\['csv'\] = CsvLexer/# lexers['csv'] = CsvLexer # disabled for CI/" docs/conf.py |
| 46 | +
|
| 47 | + # Save version_switcher.js for later (before switching branches) |
| 48 | + cp docs/_static/version_switcher.js /tmp/version_switcher.js |
| 49 | +
|
| 50 | + - name: Build v1.3 documentation (root) |
| 51 | + run: | |
| 52 | + set -e |
| 53 | + rm -rf _build/ |
| 54 | + export DOCS_VERSION=1.3 |
| 55 | + export DOCS_BASEURL=https://docs.openspp.org/ |
| 56 | + sphinx-build -b html docs _build/html |
| 57 | + echo "v1.3 build complete" |
| 58 | +
|
| 59 | + # ============================================ |
| 60 | + # BUILD v2.0 (from v2-odoo19-doc-refresh branch) -> /v2.0/ |
| 61 | + # ============================================ |
| 62 | + - name: Checkout v2 docs |
| 63 | + run: | |
| 64 | + # Save v1.3 build |
| 65 | + mv _build/html /tmp/v1.3-build |
| 66 | +
|
| 67 | + # Discard local changes to conf.py (csvlexer was disabled for v1.3 build) |
| 68 | + git checkout docs/conf.py |
| 69 | +
|
| 70 | + # Checkout v2 branch |
| 71 | + git checkout v2-odoo19-doc-refresh |
| 72 | + git submodule update --init --recursive |
| 73 | +
|
| 74 | + - name: Install v2.0 dependencies |
| 75 | + run: | |
| 76 | + # Install any additional requirements for v2 |
| 77 | + pip install -q -r requirements_frozen.txt || pip install -q -r requirements.txt |
| 78 | +
|
| 79 | + - name: Build v2.0 documentation (/v2.0/) |
| 80 | + run: | |
| 81 | + set -e |
| 82 | + rm -rf _build/ |
| 83 | + export DOCS_VERSION=2.0 |
| 84 | + export DOCS_BASEURL=https://docs.openspp.org/v2.0/ |
| 85 | + sphinx-build -b html docs _build/html/v2.0 |
| 86 | + echo "v2.0 build complete" |
| 87 | +
|
| 88 | + # ============================================ |
| 89 | + # COMBINE BUILDS & SETUP VERSION SWITCHER |
| 90 | + # ============================================ |
| 91 | + - name: Combine builds |
| 92 | + run: | |
| 93 | + # Move v1.3 build back as root |
| 94 | + mv /tmp/v1.3-build/* _build/html/ |
| 95 | + echo "Combined v1.3 (root) and v2.0 (/v2.0/)" |
| 96 | +
|
| 97 | + - name: Setup version switcher |
| 98 | + run: | |
| 99 | + set -e |
| 100 | +
|
| 101 | + # Create production switcher.json |
| 102 | + cat > _build/html/_static/switcher.json << 'EOF' |
| 103 | + [ |
| 104 | + { |
| 105 | + "name": "1.3 (stable)", |
| 106 | + "version": "1.3", |
| 107 | + "url": "https://docs.openspp.org/" |
| 108 | + }, |
| 109 | + { |
| 110 | + "name": "2.0 (preview)", |
| 111 | + "version": "2.0", |
| 112 | + "url": "https://docs.openspp.org/v2.0/" |
| 113 | + } |
| 114 | + ] |
| 115 | + EOF |
| 116 | +
|
| 117 | + # Copy to v2.0 |
| 118 | + cp _build/html/_static/switcher.json _build/html/v2.0/_static/ |
| 119 | +
|
| 120 | + # Copy version_switcher.js from stable (saved earlier) to both builds |
| 121 | + # This ensures we use the fixed version with proper regex |
| 122 | + cp /tmp/version_switcher.js _build/html/_static/ |
| 123 | + cp /tmp/version_switcher.js _build/html/v2.0/_static/ |
| 124 | +
|
| 125 | + echo "Version switcher configured" |
| 126 | +
|
| 127 | + - name: Inject version switcher script |
| 128 | + run: | |
| 129 | + # Inject script tag into all HTML files that don't already have it |
| 130 | + find _build/html -name "*.html" -exec grep -L "version_switcher.js" {} \; | \ |
| 131 | + xargs -I {} sed -i 's|</body>|<script src="/_static/version_switcher.js"></script></body>|g' {} |
| 132 | +
|
| 133 | + echo "Version switcher script injected" |
| 134 | +
|
| 135 | + - name: Display build summary |
| 136 | + run: | |
| 137 | + echo "============================================" |
| 138 | + echo "Multi-version documentation build complete" |
| 139 | + echo "============================================" |
| 140 | + echo "" |
| 141 | + echo "v1.3 (root):" |
| 142 | + ls -la _build/html/ | head -10 |
| 143 | + echo "" |
| 144 | + echo "v2.0 (/v2.0/):" |
| 145 | + ls -la _build/html/v2.0/ | head -10 |
| 146 | + echo "" |
| 147 | + echo "Version switcher:" |
| 148 | + cat _build/html/_static/switcher.json |
| 149 | +
|
| 150 | + # ============================================ |
| 151 | + # DEPLOY TO CF-PAGES |
| 152 | + # ============================================ |
| 153 | + - name: Deploy to cf-pages branch |
| 154 | + run: | |
| 155 | + set -e |
| 156 | +
|
| 157 | + # Configure git |
| 158 | + git config user.name "github-actions[bot]" |
| 159 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 160 | +
|
| 161 | + # Create a temporary directory for the deployment |
| 162 | + DEPLOY_DIR=$(mktemp -d) |
| 163 | + cp -r _build/html/* "$DEPLOY_DIR/" |
| 164 | +
|
| 165 | + # Fetch cf-pages branch |
| 166 | + git fetch origin cf-pages:cf-pages || git checkout --orphan cf-pages |
| 167 | + git checkout cf-pages |
| 168 | +
|
| 169 | + # Preserve preview deployments (keep_files equivalent) |
| 170 | + if [ -d "previews" ]; then |
| 171 | + cp -r previews "$DEPLOY_DIR/" |
| 172 | + fi |
| 173 | +
|
| 174 | + # Clean current content except .git |
| 175 | + find . -maxdepth 1 ! -name '.git' ! -name '.' -exec rm -rf {} + |
| 176 | +
|
| 177 | + # Copy new content |
| 178 | + cp -r "$DEPLOY_DIR"/* . |
| 179 | +
|
| 180 | + # Add .nojekyll to prevent Jekyll processing |
| 181 | + touch .nojekyll |
| 182 | +
|
| 183 | + # Commit and push |
| 184 | + git add -A |
| 185 | + git commit -m "Deploy multi-version documentation (v1.3 + v2.0)" || echo "No changes to commit" |
| 186 | + git push origin cf-pages |
| 187 | +
|
| 188 | + # Clean up |
| 189 | + rm -rf "$DEPLOY_DIR" |
| 190 | +
|
| 191 | + - name: Display deployment status |
| 192 | + run: | |
| 193 | + echo "============================================" |
| 194 | + echo "Multi-version documentation deployed!" |
| 195 | + echo "============================================" |
| 196 | + echo "" |
| 197 | + echo "URLs:" |
| 198 | + echo " - v1.3 (stable): https://docs.openspp.org/" |
| 199 | + echo " - v2.0 (preview): https://docs.openspp.org/v2.0/" |
0 commit comments