Ma77Ball commented on code in PR #5308: URL: https://github.com/apache/texera/pull/5308#discussion_r3347180622
########## .github/workflows/sync-docs-to-site.yml: ########## @@ -0,0 +1,184 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Syncs docs/ into the website's content/docs/latest/ and pushes to the website. +# Needs secret SITE_SYNC_TOKEN: a token with Contents:write on +# apache/incubator-texera-site. + +name: Sync docs to website + +on: + push: + branches: + - main + paths: + - 'docs/**' + workflow_dispatch: + +# Run one sync at a time. +concurrency: + group: sync-docs-to-site + cancel-in-progress: false + +permissions: + contents: read + +jobs: + sync: + # Skip on forks. + if: github.repository == 'apache/texera' + runs-on: ubuntu-latest + steps: + - name: Checkout texera + uses: actions/checkout@v5 + with: + path: texera + + - name: Checkout incubator-texera-site + uses: actions/checkout@v5 + with: + repository: apache/incubator-texera-site + ref: main + path: site + fetch-depth: 0 + token: ${{ secrets.SITE_SYNC_TOKEN }} + + - name: Sync docs/ into content/docs/latest/ + env: + SOURCE_DOCS: texera/docs + TARGET_DOCS: site/content/docs/latest + run: | + python3 - <<'PY' + import os + import pathlib + import sys + + source = pathlib.Path(os.environ["SOURCE_DOCS"]) + target = pathlib.Path(os.environ["TARGET_DOCS"]) + + + def split_front_matter(text): + # Split a page into (front matter, body) on the '---' fences. + if not text.startswith("---\n"): + return "", text + lines = text.split("\n") + for i in range(1, len(lines)): + if lines[i] == "---": + return "\n".join(lines[: i + 1]) + "\n", "\n".join(lines[i + 1 :]) + return "", text + + + def normalize_body(body): + # Trim surrounding blank lines; "" if the body is empty. + body = body.lstrip("\n").rstrip() + return body + "\n" if body else "" + + + if not source.is_dir(): + print(f"error: source dir not found: {source}", file=sys.stderr) + sys.exit(2) + target.mkdir(parents=True, exist_ok=True) + + source_rels = set() + created = updated = deleted = 0 + + # For each source page: keep the target's front matter, use the source body. + for sfile in sorted(source.rglob("*.md")): + rel = sfile.relative_to(source) + source_rels.add(rel) + tfile = target / rel + + src_text = sfile.read_text(encoding="utf-8") + _, src_body = split_front_matter(src_text) + + if tfile.exists(): + target_fm, _ = split_front_matter(tfile.read_text(encoding="utf-8")) + else: + target_fm, _ = split_front_matter(src_text) + + body = normalize_body(src_body) + if body: + new_text = target_fm + ("\n" if target_fm else "") + body + else: + new_text = target_fm Review Comment: Checked the live site: its pages already carry exactly one blank line after the front matter, and `target_fm` ends with a single newline, so `target_fm + "\n" + body` reproduces that format. When the body is unchanged the regenerated text is byte-identical, so no diff is produced. Keeping it to match the site convention. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
