@@ -20,14 +20,16 @@ jobs:
2020 repository : ${{ github.event.pull_request.head.repo.full_name }}
2121 path : ivorysql_doc
2222
23- - name : Fetch All Relevant Branches into Local Docs Repo
24- working-directory : ./ivorysql_doc
25- run : |
26- echo "Fetching all branches from origin to update local remote-tracking branches..."
27- git fetch origin --prune --no-tags
28-
29- echo "--- Fetched Remote-Tracking Branches ---"
30- git branch -r
23+ # Skip fetching other branches for PR preview to avoid conflicts
24+ # The PR HEAD is already checked out and we only want to build that version
25+ # - name: Fetch All Relevant Branches into Local Docs Repo
26+ # working-directory: ./ivorysql_doc
27+ # run: |
28+ # echo "Fetching all branches from origin to update local remote-tracking branches..."
29+ # git fetch origin --prune --no-tags
30+ #
31+ # echo "--- Fetched Remote-Tracking Branches ---"
32+ # git branch -r
3133
3234 - name : Checkout Doc Builder Repository (doc_builder)
3335 uses : actions/checkout@v4
@@ -46,13 +48,22 @@ jobs:
4648 - name : Modify Antora Playbooks for Local PR Build
4749 working-directory : ./ivory-doc-builder
4850 env :
49- DETECTED_VERSION : ' master '
51+ PR_BASE_REF : ${{ github.event.pull_request.base.ref }}
5052 START_PAGE_COMPONENT_NAME : " ivorysql-doc"
5153 START_PAGE_FILE_PATH : " welcome.adoc"
5254 run : |
5355 PLAYBOOK_FILES=("antora-playbook-CN.yml" "antora-playbook-EN.yml")
5456 NEW_LOCAL_URL="../ivorysql_doc"
5557
58+ # Extract version from PR base branch (e.g., v5.1 -> 5.1)
59+ if [[ "$PR_BASE_REF" =~ ^v([0-9]+\.[0-9]+) ]]; then
60+ DETECTED_VERSION="${BASH_REMATCH[1]}"
61+ echo "Detected version from PR base branch $PR_BASE_REF: $DETECTED_VERSION"
62+ else
63+ DETECTED_VERSION="master"
64+ echo "Using default version: master (PR base: $PR_BASE_REF)"
65+ fi
66+
5667 for PLAYBOOK_FILE in "${PLAYBOOK_FILES[@]}"; do
5768 if [ -f "$PLAYBOOK_FILE" ]; then
5869 echo "--- Modifying Playbook: $PLAYBOOK_FILE ---"
@@ -65,13 +76,27 @@ jobs:
6576 yq -i ".content.sources[0].branches = [\"HEAD\"]" "$PLAYBOOK_FILE"
6677
6778 yq -i ".content.sources[0].edit_url = false" "$PLAYBOOK_FILE"
68- if [[ -n "$DETECTED_VERSION" ]]; then
69- NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}::${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
79+
80+ # Disable runtime fetch to ensure we use local files
81+ yq -i ".runtime.fetch = false" "$PLAYBOOK_FILE"
82+
83+ if [[ -n "$DETECTED_VERSION" && "$DETECTED_VERSION" != "master" ]]; then
84+ # v5.1+ uses flat structure (no version prefix in path)
85+ # v5.0 and earlier use nested structure (version prefix in path)
86+ # Use version comparison: if DETECTED_VERSION >= 5.1, use flat structure
87+ if [[ "$(printf '%s\n' "5.1" "$DETECTED_VERSION" | sort -V | head -n1)" == "5.1" ]]; then
88+ # For v5.1+: ivorysql-doc:v5.1:welcome.adoc (no version prefix in path)
89+ NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:${START_PAGE_FILE_PATH}"
90+ else
91+ # For v5.0 and earlier: ivorysql-doc:v5.0:v5.0/welcome.adoc (with version prefix)
92+ NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:v${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
93+ fi
7094 yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE"
7195 echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE"
7296 else
73- echo "WARNING : DETECTED_VERSION is empty. Skipping start_page update for $PLAYBOOK_FILE ."
97+ echo "INFO : DETECTED_VERSION is '$DETECTED_VERSION'. Keeping original playbook start_page configuration ."
7498 fi
99+
75100 yq -i ".site.title = .site.title + \" (PR Preview)\"" "$PLAYBOOK_FILE"
76101 echo "Modified content of $PLAYBOOK_FILE:"
77102 cat "$PLAYBOOK_FILE"
0 commit comments