Skip to content

Commit cd9e2e4

Browse files
authored
Merge pull request #200 from NotHimmel/v5.0
Enhance merge workflow
2 parents 9b172e7 + d6cde53 commit cd9e2e4

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

.github/workflows/merge-build-push.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request_target:
55
types:
66
- closed
7+
create:
78

89
jobs:
910
build-and-deploy:
@@ -91,13 +92,68 @@ jobs:
9192
fi
9293
done
9394
95+
- name: Pin PDF assembler to merged PR branch
96+
working-directory: ./ivory-doc-builder
97+
env:
98+
MERGED_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }}
99+
COMPONENT_NAME: ivorysql-doc
100+
run: |
101+
if [[ -z "${MERGED_BRANCH}" ]]; then
102+
echo "::error::Merged branch name is empty, cannot update PDF component version."
103+
exit 1
104+
fi
105+
106+
TARGET_COMPONENT_VERSION="${MERGED_BRANCH}@${COMPONENT_NAME}"
107+
echo "Setting antora-assembler.yml component_versions to ${TARGET_COMPONENT_VERSION}"
108+
yq -i ".component_versions = \"${TARGET_COMPONENT_VERSION}\"" antora-assembler.yml
109+
echo "Updated antora-assembler.yml:"
110+
cat antora-assembler.yml
111+
94112
- name: Checkout Web Repository (web)
95113
uses: actions/checkout@v4
96114
with:
97115
repository: ${{ github.repository_owner }}/ivorysql_web
98116
path: www_publish_target
99117
token: ${{ secrets.WEB_TOKEN }}
100118

119+
- name: Ensure web index redirects to latest home
120+
id: update_web_index
121+
working-directory: ./www_publish_target
122+
env:
123+
LATEST_VERSION: ${{ steps.latest_version_step.outputs.version }}
124+
MERGED_PR_BASE: ${{ github.event.pull_request.base.ref || github.ref_name }}
125+
run: |
126+
set -euo pipefail
127+
128+
TARGET_BRANCH="v${LATEST_VERSION}"
129+
EXPECTED_PATH="ivorysql-doc/v${LATEST_VERSION}/v${LATEST_VERSION}/welcome.html"
130+
131+
if [[ "${MERGED_PR_BASE}" != "${TARGET_BRANCH}" ]]; then
132+
echo "Base branch ${MERGED_PR_BASE} is not the latest version branch ${TARGET_BRANCH}, skip index redirect check."
133+
echo "index_updated=false" >> "$GITHUB_OUTPUT"
134+
exit 0
135+
fi
136+
137+
UPDATE_NEEDED=false
138+
for lang in cn en; do
139+
FILE_PATH="docs/${lang}/index.html"
140+
if [[ ! -f "${FILE_PATH}" ]]; then
141+
echo "Missing ${FILE_PATH}, cannot update redirect."
142+
continue
143+
fi
144+
145+
if grep -q "${EXPECTED_PATH}" "${FILE_PATH}"; then
146+
echo "${FILE_PATH} already points to latest ${LATEST_VERSION}."
147+
else
148+
# Replace all version segments like vX.Y or vX.Y.Z in href/location/meta/script targets
149+
sed -i -E "s@ivorysql-doc/v[0-9]+(\\.[0-9]+){1,2}/v[0-9]+(\\.[0-9]+){1,2}/welcome\\.html@${EXPECTED_PATH}@g" "${FILE_PATH}"
150+
UPDATE_NEEDED=true
151+
echo "Updated ${FILE_PATH} to latest ${LATEST_VERSION} redirect."
152+
fi
153+
done
154+
155+
echo "index_updated=${UPDATE_NEEDED}" >> "$GITHUB_OUTPUT"
156+
101157
- name: Setup Ruby and Bundler
102158
uses: ruby/setup-ruby@v1
103159
with:
@@ -133,6 +189,36 @@ jobs:
133189
echo "Building Chinese site..."
134190
npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml
135191
192+
- name: Copy PDF exports into web repo
193+
working-directory: ./ivory-doc-builder
194+
env:
195+
MERGED_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }}
196+
COMPONENT_NAME: ivorysql-doc
197+
run: |
198+
set -euo pipefail
199+
200+
if [[ -z "${MERGED_BRANCH}" ]]; then
201+
echo "::error::Merged branch name is empty, cannot locate PDF output."
202+
exit 1
203+
fi
204+
205+
SOURCE_PDF="build/assembler-pdf/${COMPONENT_NAME}/${MERGED_BRANCH}/_exports/index.pdf"
206+
DEST_CN="../www_publish_target/docs/cn/${COMPONENT_NAME}/${MERGED_BRANCH}/ivorysql.pdf"
207+
DEST_EN="../www_publish_target/docs/en/${COMPONENT_NAME}/${MERGED_BRANCH}/ivorysql.pdf"
208+
209+
if [[ ! -f "${SOURCE_PDF}" ]]; then
210+
echo "::error::PDF not found at ${SOURCE_PDF}"
211+
exit 1
212+
fi
213+
214+
echo "Copying PDF from ${SOURCE_PDF} to web repo targets..."
215+
mkdir -p "$(dirname "${DEST_CN}")" "$(dirname "${DEST_EN}")"
216+
cp "${SOURCE_PDF}" "${DEST_CN}"
217+
cp "${SOURCE_PDF}" "${DEST_EN}"
218+
echo "PDF copied to:"
219+
echo " - ${DEST_CN}"
220+
echo " - ${DEST_EN}"
221+
136222
- name: Commit and Push to web Repository new branch , pull request
137223
id: commit_push_new_branch
138224
working-directory: ./www_publish_target

0 commit comments

Comments
 (0)