|
| 1 | +#<!-- |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +#--> |
| 19 | +name: Build and Deploy Site |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + branches: [main] |
| 24 | + paths: |
| 25 | + - 'docs/**' |
| 26 | + - 'website/**' |
| 27 | + - '.github/workflows/build-site.yml' |
| 28 | + workflow_dispatch: |
| 29 | + |
| 30 | +concurrency: |
| 31 | + group: "site-deploy" |
| 32 | + cancel-in-progress: true |
| 33 | + |
| 34 | +jobs: |
| 35 | + build-and-deploy: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + # ── Build Next.js landing page ── |
| 44 | + - name: Set up Node.js |
| 45 | + uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version: 20 |
| 48 | + cache: npm |
| 49 | + cache-dependency-path: website/package-lock.json |
| 50 | + |
| 51 | + - name: Install Node dependencies |
| 52 | + working-directory: ./website |
| 53 | + run: npm ci |
| 54 | + |
| 55 | + - name: Build landing page |
| 56 | + working-directory: ./website |
| 57 | + run: npm run build |
| 58 | + |
| 59 | + # ── Build Sphinx docs ── |
| 60 | + - name: Set up Python 3.12 |
| 61 | + uses: actions/setup-python@v5 |
| 62 | + with: |
| 63 | + python-version: '3.12' |
| 64 | + cache: 'pip' |
| 65 | + |
| 66 | + - name: Install system dependencies |
| 67 | + run: | |
| 68 | + sudo apt-get update |
| 69 | + sudo apt-get install -y graphviz |
| 70 | +
|
| 71 | + - name: Install Sphinx and dependencies |
| 72 | + run: | |
| 73 | + python -m pip install --upgrade --no-cache-dir pip setuptools |
| 74 | + python -m pip install --upgrade --no-cache-dir sphinx sphinx-rtd-theme sphinx-simplepdf |
| 75 | + pip install -e ".[documentation]" |
| 76 | +
|
| 77 | + - name: Build Sphinx documentation |
| 78 | + working-directory: ./docs |
| 79 | + run: | |
| 80 | + python -m sphinx -T -W --keep-going -b dirhtml -d _build/doctrees -D language=en . _build/html |
| 81 | +
|
| 82 | + # ── Merge outputs and deploy ── |
| 83 | + - name: Assemble site |
| 84 | + run: | |
| 85 | + mkdir -p /tmp/site-output |
| 86 | +
|
| 87 | + # Landing page at root |
| 88 | + cp -r website/out/* /tmp/site-output/ |
| 89 | +
|
| 90 | + # Sphinx docs at /docs/ |
| 91 | + mkdir -p /tmp/site-output/docs |
| 92 | + cp -r docs/_build/html/* /tmp/site-output/docs/ |
| 93 | +
|
| 94 | + # Redirects for old Sphinx paths |
| 95 | + cp .htaccess /tmp/site-output/ |
| 96 | +
|
| 97 | + echo "Site structure:" |
| 98 | + ls -la /tmp/site-output/ |
| 99 | + echo "Docs:" |
| 100 | + ls -la /tmp/site-output/docs/ | head -20 |
| 101 | +
|
| 102 | + # TODO: Remove this step once we confirm ASF infra honors .htaccess (AllowOverride). |
| 103 | + # This was added as a fallback for PR #679 (landing page migration) because: |
| 104 | + # The .htaccess was not being deployed (dotglob fix above solves this) and |
| 105 | + # ASF infra may not honor .htaccess for the publish serving mode in .asf.yaml. |
| 106 | + # Once confirmed, the .htaccess 301s are sufficient and these static HTML |
| 107 | + # redirects can be removed to avoid bloating the asf-site branch. |
| 108 | + - name: Generate HTML redirect fallbacks |
| 109 | + run: | |
| 110 | + # Scan Sphinx build output and generate static HTML redirects for every page. |
| 111 | + # These act as fallback if the server does not process .htaccess. |
| 112 | + BASE_URL="https://burr.apache.org" |
| 113 | + OUTPUT="/tmp/site-output" |
| 114 | + DOCS_BUILD="docs/_build/html" |
| 115 | + COUNT=0 |
| 116 | +
|
| 117 | + # Find every index.html in the Sphinx output (dirhtml builder creates dir/index.html per page) |
| 118 | + while IFS= read -r file; do |
| 119 | + # Get path relative to build root, e.g. "getting_started/install/index.html" |
| 120 | + rel="${file#$DOCS_BUILD/}" |
| 121 | + dir="$(dirname "$rel")" |
| 122 | +
|
| 123 | + # Skip the docs root (landing page lives there) and paths already in site output |
| 124 | + if [ "$dir" = "." ] || [ -e "$OUTPUT/$dir/index.html" ]; then |
| 125 | + continue |
| 126 | + fi |
| 127 | +
|
| 128 | + target="$BASE_URL/docs/$dir/" |
| 129 | + mkdir -p "$OUTPUT/$dir" |
| 130 | + printf '<!DOCTYPE html><html><head>\n<meta charset="utf-8">\n<meta http-equiv="refresh" content="0; url=%s">\n<link rel="canonical" href="%s">\n<script>window.location.replace("%s")</script>\n</head><body>Redirecting to <a href="%s">%s</a>...</body></html>\n' \ |
| 131 | + "$target" "$target" "$target" "$target" "$target" \ |
| 132 | + > "$OUTPUT/$dir/index.html" |
| 133 | + COUNT=$((COUNT + 1)) |
| 134 | + done < <(find "$DOCS_BUILD" -name "index.html" -type f) |
| 135 | +
|
| 136 | + echo "Generated $COUNT HTML redirect fallbacks." |
| 137 | +
|
| 138 | + - name: Deploy to asf-site / asf-staging |
| 139 | + if: github.event_name != 'pull_request' |
| 140 | + run: | |
| 141 | + if [ "${{ github.ref }}" = "refs/heads/main" ]; then |
| 142 | + TARGET_BRANCH="asf-site" |
| 143 | + else |
| 144 | + TARGET_BRANCH="asf-staging" |
| 145 | + fi |
| 146 | +
|
| 147 | + git config --global user.name "GitHub Actions" |
| 148 | + git config --global user.email "actions@github.com" |
| 149 | +
|
| 150 | + mkdir -p /tmp/gh-pages |
| 151 | +
|
| 152 | + if ! git clone --branch $TARGET_BRANCH --single-branch \ |
| 153 | + https://github.com/${{ github.repository }}.git /tmp/gh-pages 2>/dev/null; then |
| 154 | + rm -rf /tmp/gh-pages |
| 155 | + mkdir -p /tmp/gh-pages |
| 156 | + cd /tmp/gh-pages |
| 157 | + git init |
| 158 | + git checkout -b $TARGET_BRANCH |
| 159 | + git remote add origin https://github.com/${{ github.repository }}.git |
| 160 | + cd - |
| 161 | + fi |
| 162 | +
|
| 163 | + rm -rf /tmp/gh-pages/content |
| 164 | + mkdir -p /tmp/gh-pages/content |
| 165 | + shopt -s dotglob |
| 166 | + cp -r /tmp/site-output/* /tmp/gh-pages/content/ |
| 167 | +
|
| 168 | + cd /tmp/gh-pages |
| 169 | +
|
| 170 | + if [ ! -f README.md ]; then |
| 171 | + echo "# Apache Burr Website" > README.md |
| 172 | + echo "This branch contains the built site (landing page + docs)." >> README.md |
| 173 | + fi |
| 174 | +
|
| 175 | + git add -A |
| 176 | +
|
| 177 | + if [ -n "$(git status --porcelain)" ]; then |
| 178 | + git commit -m "Deploy site from ${{ github.sha }}" |
| 179 | + git push https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git $TARGET_BRANCH |
| 180 | + echo "Deployed to $TARGET_BRANCH" |
| 181 | + else |
| 182 | + echo "No changes to deploy" |
| 183 | + fi |
0 commit comments