1+ name : Build , Push to web, Deploy Antora Docs
2+
3+ on :
4+ pull_request :
5+ types :
6+ - closed
7+
8+ jobs :
9+ build-and-deploy :
10+ runs-on : ubuntu-latest
11+ if : github.event.pull_request.merged == true
12+ permissions :
13+ contents : write
14+ pull-requests : write
15+
16+ steps :
17+ - name : PR was merged
18+ run : |
19+ echo "PR #${{ github.event.pull_request.number }} was merged into ${{ github.event.pull_request.base.ref }}."
20+ echo "Head commit was: ${{ github.event.pull_request.head.sha }}"
21+
22+ - name : Checkout Documentation Repository (ivorysql_doc)
23+ uses : actions/checkout@v4
24+ with :
25+ path : ivorysql_doc
26+
27+ - name : Checkout Doc Builder Repository (doc_builder)
28+ uses : actions/checkout@v4
29+ with :
30+ repository : ${{ github.repository_owner }}/ivory-doc-builder
31+ path : ivory-doc-builder
32+
33+ - name : Determine Latest Version from ivorysql_docs branches
34+ id : latest_version_step
35+ shell : bash
36+ run : |
37+ echo "Detecting latest version from remote branches of IvorySQL/ivorysql_docs..."
38+ LATEST_VERSION_NUMBER=$( \
39+ git ls-remote --heads --refs "https://github.com/IvorySQL/ivorysql_docs.git" 'refs/heads/v*.*' | \
40+ sed 's_^[^\t]*\trefs/heads/v__g' | \
41+ grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' | \
42+ sort -V | \
43+ tail -n1 \
44+ )
45+
46+ if [[ -z "$LATEST_VERSION_NUMBER" ]]; then
47+ echo "::error::Could not determine latest version from branches. Please check git ls-remote command and repo accessibility."
48+ exit 1
49+ fi
50+
51+ echo "Detected latest version number: $LATEST_VERSION_NUMBER"
52+ echo "version=$LATEST_VERSION_NUMBER" >> "$GITHUB_OUTPUT"
53+
54+ - name : Install yq
55+ run : |
56+ sudo apt-get update -y
57+ sudo apt-get install -y jq
58+ sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
59+ sudo chmod +x /usr/bin/yq
60+ yq --version
61+
62+ - name : Modify Antora Playbooks
63+ working-directory : ./ivory-doc-builder
64+ env :
65+ DETECTED_VERSION : ' ${{ steps.latest_version_step.outputs.version }}'
66+ START_PAGE_COMPONENT_NAME : " ivorysql-doc"
67+ START_PAGE_FILE_PATH : " welcome.adoc"
68+ run : |
69+ PLAYBOOK_FILES=("antora-playbook-CN.yml" "antora-playbook-EN.yml")
70+
71+ for PLAYBOOK_FILE in "${PLAYBOOK_FILES[@]}"; do
72+ if [ -f "$PLAYBOOK_FILE" ]; then
73+ echo "--- Modifying Playbook: $PLAYBOOK_FILE ---"
74+ echo "Original content of $PLAYBOOK_FILE:"
75+ cat "$PLAYBOOK_FILE"
76+ echo # Newline for better readability
77+
78+ if [[ -n "$DETECTED_VERSION" ]]; then
79+ NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}::v${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
80+ yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE"
81+ echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE"
82+ else
83+ echo "WARNING: DETECTED_VERSION is empty. Skipping start_page update for $PLAYBOOK_FILE."
84+ fi
85+ echo "Modified content of $PLAYBOOK_FILE:"
86+ cat "$PLAYBOOK_FILE"
87+ echo "--- Finished modification for $PLAYBOOK_FILE ---"
88+ echo # Newline
89+ else
90+ echo "WARNING: Playbook file $PLAYBOOK_FILE not found in $(pwd)."
91+ fi
92+ done
93+
94+ - name : Checkout Web Repository (web)
95+ uses : actions/checkout@v4
96+ with :
97+ repository : ${{ github.repository_owner }}/ivorysql_web
98+ path : www_publish_target
99+ token : ${{ secrets.IVORY_TOKEN }}
100+
101+ - name : Setup Ruby and Bundler
102+ uses : ruby/setup-ruby@v1
103+ with :
104+ ruby-version : ' 3.0'
105+
106+ - name : Install Asciidoctor PDF and related Gems
107+ run : |
108+ echo "Installing Asciidoctor PDF gems..."
109+ gem install asciidoctor-pdf --version "~>2.3.19"
110+ gem install rouge
111+
112+ - name : Setup Node.js
113+ uses : actions/setup-node@v4
114+ with :
115+ node-version : ' 22.15'
116+
117+ - name : Install Antora CLI
118+ run : |
119+ echo "Installing Antora packages local..."
120+ npm install --global antora@3.1.7 @antora/lunr-extension @antora/pdf-extension @node-rs/jieba
121+
122+ - name : Build English Documentation
123+ working-directory : ./ivory-doc-builder
124+ run : |
125+ echo "Current directory: $(pwd)"
126+ echo "Building English site..."
127+ ls ../www_publish_target/
128+ npx antora generate --stacktrace --to-dir ../www_publish_target/docs/en antora-playbook-EN.yml
129+
130+ - name : Build Chinese Documentation
131+ working-directory : ./ivory-doc-builder
132+ run : |
133+ echo "Building Chinese site..."
134+ npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml
135+
136+ - name : Commit and Push to web Repository new branch , pull request
137+ id : commit_push_new_branch
138+ working-directory : ./www_publish_target
139+ env :
140+ OPEN_PUSH_PR : true
141+ run : |
142+ echo "push_pr=${OPEN_PUSH_PR}" >> $GITHUB_OUTPUT
143+ echo "--- Preparing to commit and push changes ---"
144+ echo "--- Git status ---"
145+ GIT_STATUS_OUTPUT=$(git status --porcelain)
146+ echo "${GIT_STATUS_OUTPUT}"
147+ echo "--- End of git status --porcelain output ---"
148+
149+ git config user.name "IvorySQL Actions Bot"
150+ git config user.email "actions-bot@users.noreply.github.com"
151+
152+ if [ -z "${GIT_STATUS_OUTPUT}" ]; then
153+ echo "No changes to commit."
154+ echo "changes_detected=false" >> $GITHUB_OUTPUT
155+ else
156+ echo "Changes detected. Proceeding with add, commit, and push."
157+ if [[ "${OPEN_PUSH_PR}" == "true" ]]; then
158+ NEW_BRANCH_NAME="docs-update-${{ github.run_attempt }}-$(date +'%Y-%m-%d-%H%M%S')"
159+ echo "Generated new branch name: ${NEW_BRANCH_NAME}"
160+ echo "new_branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT
161+ echo "changes_detected=true" >> $GITHUB_OUTPUT
162+ git checkout -b "${NEW_BRANCH_NAME}"
163+ git add .
164+ COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
165+ git commit -m "${COMMIT_MESSAGE}"
166+ git push origin "${NEW_BRANCH_NAME}"
167+ else
168+ echo "Pushing changes to master branch."
169+ git add .
170+ COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
171+ git commit -m "${COMMIT_MESSAGE}"
172+ git push origin master
173+ fi
174+ fi
175+
176+ - name : Create or Update Pull Request with GitHub CLI
177+ id : cpr
178+ if : steps.commit_push_new_branch.outputs.push_pr == 'true' && steps.commit_push_new_branch.outputs.changes_detected == 'true' && steps.commit_push_new_branch.outputs.new_branch_name != ''
179+ working-directory : ./www_publish_target
180+ env :
181+ GH_TOKEN : ${{ secrets.IVORY_TOKEN }}
182+ PARAM_BASE_BRANCH : master
183+ PARAM_HEAD_BRANCH : ${{ steps.commit_push_new_branch.outputs.new_branch_name }}
184+ PARAM_TITLE : " Docs: Automated update from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
185+ PARAM_BODY : |
186+ Automated Antora site regeneration based on changes in the IvorySQL/ivorysql_docs repository.
187+
188+ Source commit: `${{ github.server_url }}/${{ github.repository_owner }}/ivorysql_docs/commit/${{ github.event.head_commit.id || github.sha }}`
189+
190+ - Auto-generated by gh pr create
191+ PARAM_DRAFT : " false"
192+ run : |
193+ echo "Attempting to create or update Pull Request for branch '${PARAM_HEAD_BRANCH}' into '${PARAM_BASE_BRANCH}'"
194+
195+ DRAFT_FLAG_STRING=""
196+ if [[ "${PARAM_DRAFT}" == "true" ]]; then
197+ DRAFT_FLAG_STRING="--draft"
198+ fi
199+
200+ echo "Executing: gh pr create --base \"${PARAM_BASE_BRANCH}\" --head \"${PARAM_HEAD_BRANCH}\" --title <title> --body-file <(echo body) ${DRAFT_FLAG_STRING}"
201+
202+ if gh pr create \
203+ --base "${PARAM_BASE_BRANCH}" \
204+ --head "${PARAM_HEAD_BRANCH}" \
205+ --title "${PARAM_TITLE}" \
206+ --body-file <(echo "${PARAM_BODY}") \
207+ ${DRAFT_FLAG_STRING}; then
208+ echo "Pull Request created or already exists and metadata might have been updated."
209+ else
210+ echo "'gh pr create' command indicated an issue or no action was taken."
211+
212+ EXISTING_PR_URL=$(gh pr view "${PARAM_HEAD_BRANCH}" --json url -q ".url" 2>/dev/null || echo "")
213+ if [[ -n "$EXISTING_PR_URL" ]]; then
214+ echo "An existing PR was found for branch '${PARAM_HEAD_BRANCH}': ${EXISTING_PR_URL}"
215+ echo "Proceeding to enable auto-merge for this existing PR."
216+ else
217+ echo "::error::Failed to create PR and no existing PR found for branch '${PARAM_HEAD_BRANCH}'. Cannot enable auto-merge."
218+ exit 1
219+ fi
220+ fi
221+
222+ - name : Enable Auto-Merge for PR
223+ if : steps.cpr.outcome == 'success' && steps.commit_push_new_branch.outputs.push_pr == 'true' && steps.commit_push_new_branch.outputs.changes_detected == 'true' && steps.commit_push_new_branch.outputs.new_branch_name != ''
224+ working-directory : ./www_publish_target
225+ env :
226+ GH_TOKEN : ${{ secrets.IVORY_TOKEN }}
227+ PR_HEAD_BRANCH : ${{ steps.commit_push_new_branch.outputs.new_branch_name }}
228+ PR_BASE_BRANCH : master
229+ MERGE_STRATEGY : MERGE
230+ run : |
231+ echo "Attempting to enable auto-merge for PR from branch '$PR_HEAD_BRANCH' to '$PR_BASE_BRANCH'"
232+ if gh pr merge "$PR_HEAD_BRANCH" \
233+ --${MERGE_STRATEGY,,} \
234+ --delete-branch; then
235+ echo "Auto-merge enabled successfully for PR from branch '$PR_HEAD_BRANCH'."
236+ else
237+ echo "::warning::Failed to enable auto-merge for PR from branch '$PR_HEAD_BRANCH'."
238+ echo "This might be because the PR is not mergeable (e.g., has conflicts, is a draft PR), requires reviews, auto-merge is already enabled, or the PR could not be uniquely identified by branch name."
239+ fi
0 commit comments