Skip to content

Commit 49bb104

Browse files
committed
modify pre-preview to show correct url in preview page
1 parent 3195ce1 commit 49bb104

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

.github/workflows/pr-preview.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ jobs:
4646
- name: Modify Antora Playbooks for Local PR Build
4747
working-directory: ./ivory-doc-builder
4848
env:
49-
DETECTED_VERSION: 'master'
49+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
5050
START_PAGE_COMPONENT_NAME: "ivorysql-doc"
5151
START_PAGE_FILE_PATH: "welcome.adoc"
5252
run: |
5353
PLAYBOOK_FILES=("antora-playbook-CN.yml" "antora-playbook-EN.yml")
5454
NEW_LOCAL_URL="../ivorysql_doc"
5555
56+
# Extract version from PR base branch (e.g., v5.1 -> 5.1)
57+
if [[ "$PR_BASE_REF" =~ ^v([0-9]+\.[0-9]+) ]]; then
58+
DETECTED_VERSION="${BASH_REMATCH[1]}"
59+
echo "Detected version from PR base branch $PR_BASE_REF: $DETECTED_VERSION"
60+
else
61+
DETECTED_VERSION="master"
62+
echo "Using default version: master (PR base: $PR_BASE_REF)"
63+
fi
64+
5665
for PLAYBOOK_FILE in "${PLAYBOOK_FILES[@]}"; do
5766
if [ -f "$PLAYBOOK_FILE" ]; then
5867
echo "--- Modifying Playbook: $PLAYBOOK_FILE ---"
@@ -65,13 +74,27 @@ jobs:
6574
yq -i ".content.sources[0].branches = [\"HEAD\"]" "$PLAYBOOK_FILE"
6675
6776
yq -i ".content.sources[0].edit_url = false" "$PLAYBOOK_FILE"
77+
6878
if [[ -n "$DETECTED_VERSION" ]]; then
69-
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}::${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
79+
# v5.1+ uses flat structure (no version prefix in path)
80+
# v5.0 and earlier use nested structure (version prefix in path)
81+
# Use version comparison: if DETECTED_VERSION >= 5.1, use flat structure
82+
if [[ "$DETECTED_VERSION" == "master" ]]; then
83+
# Master branch uses nested structure with 'master' prefix
84+
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:${DETECTED_VERSION}:${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
85+
elif [[ "$(printf '%s\n' "5.1" "$DETECTED_VERSION" | sort -V | head -n1)" == "5.1" ]]; then
86+
# For v5.1+: ivorysql-doc:v5.1:welcome.adoc (no version prefix in path)
87+
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:${START_PAGE_FILE_PATH}"
88+
else
89+
# For v5.0 and earlier: ivorysql-doc:v5.0:v5.0/welcome.adoc (with version prefix)
90+
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:v${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
91+
fi
7092
yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE"
7193
echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE"
7294
else
7395
echo "WARNING: DETECTED_VERSION is empty. Skipping start_page update for $PLAYBOOK_FILE."
7496
fi
97+
7598
yq -i ".site.title = .site.title + \" (PR Preview)\"" "$PLAYBOOK_FILE"
7699
echo "Modified content of $PLAYBOOK_FILE:"
77100
cat "$PLAYBOOK_FILE"

0 commit comments

Comments
 (0)