|
| 1 | +name: Build , Push to web, Deploy Antora Docs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 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.WEB_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: Move and Rename PDF Files |
| 137 | + id: process_pdfs |
| 138 | + working-directory: ./www_publish_target |
| 139 | + run: | |
| 140 | + echo "--- Searching for PDF files to move and rename ---" |
| 141 | +
|
| 142 | + PDF_FILES_FOUND=$(find . -type f -path '*/_exports/index.pdf') |
| 143 | +
|
| 144 | + if [ -z "${PDF_FILES_FOUND}" ]; then |
| 145 | + echo "No PDF files found to move. Skipping." |
| 146 | + else |
| 147 | + echo "Found PDF files to process:" |
| 148 | + echo "${PDF_FILES_FOUND}" |
| 149 | +
|
| 150 | + echo "${PDF_FILES_FOUND}" | while read PDF_FILE; do |
| 151 | + # ./docs/cn/ivorysql-doc/master/_exports/index.pdf -> ./docs/cn/ivorysql-doc/master |
| 152 | + BASE_DIR="${PDF_FILE%/_exports/index.pdf}" |
| 153 | + |
| 154 | + NEW_PDF_PATH="${BASE_DIR}/ivorysql.pdf" |
| 155 | +
|
| 156 | + echo "Moving '${PDF_FILE}' to '${NEW_PDF_PATH}'" |
| 157 | + mv "${PDF_FILE}" "${NEW_PDF_PATH}" |
| 158 | + done |
| 159 | + |
| 160 | + echo "--- Cleaning up empty _exports directories ---" |
| 161 | + find . -type d -name '_exports' -empty -delete |
| 162 | + fi |
| 163 | + |
| 164 | + echo "--- PDF processing complete ---" |
| 165 | +
|
| 166 | + - name: Commit and Push to web Repository new branch , pull request |
| 167 | + id: commit_push_new_branch |
| 168 | + working-directory: ./www_publish_target |
| 169 | + env: |
| 170 | + OPEN_PUSH_PR: true |
| 171 | + run: | |
| 172 | + echo "push_pr=${OPEN_PUSH_PR}" >> $GITHUB_OUTPUT |
| 173 | + echo "--- Preparing to commit and push changes ---" |
| 174 | + echo "--- Git status ---" |
| 175 | + GIT_STATUS_OUTPUT=$(git status --porcelain) |
| 176 | + echo "${GIT_STATUS_OUTPUT}" |
| 177 | + echo "--- End of git status --porcelain output ---" |
| 178 | +
|
| 179 | + git config user.name "IvorySQL Actions Bot" |
| 180 | + git config user.email "actions-bot@users.noreply.github.com" |
| 181 | + |
| 182 | + if [ -z "${GIT_STATUS_OUTPUT}" ]; then |
| 183 | + echo "No changes to commit." |
| 184 | + echo "changes_detected=false" >> $GITHUB_OUTPUT |
| 185 | + else |
| 186 | + echo "Changes detected. Proceeding with add, commit, and push." |
| 187 | + if [[ "${OPEN_PUSH_PR}" == "true" ]]; then |
| 188 | + NEW_BRANCH_NAME="docs-update-${{ github.run_attempt }}-$(date +'%Y-%m-%d-%H%M%S')" |
| 189 | + echo "Generated new branch name: ${NEW_BRANCH_NAME}" |
| 190 | + echo "new_branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT |
| 191 | + echo "changes_detected=true" >> $GITHUB_OUTPUT |
| 192 | + git checkout -b "${NEW_BRANCH_NAME}" |
| 193 | + git add . |
| 194 | + COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}" |
| 195 | + git commit -m "${COMMIT_MESSAGE}" |
| 196 | + git push origin "${NEW_BRANCH_NAME}" |
| 197 | + else |
| 198 | + echo "Pushing changes to master branch." |
| 199 | + git add . |
| 200 | + COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}" |
| 201 | + git commit -m "${COMMIT_MESSAGE}" |
| 202 | + git push origin master |
| 203 | + fi |
| 204 | + fi |
| 205 | +
|
| 206 | + - name: Create or Update Pull Request with GitHub CLI |
| 207 | + id: cpr |
| 208 | + 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 != '' |
| 209 | + working-directory: ./www_publish_target |
| 210 | + env: |
| 211 | + GH_TOKEN: ${{ secrets.WEB_TOKEN }} |
| 212 | + PARAM_BASE_BRANCH: master |
| 213 | + PARAM_HEAD_BRANCH: ${{ steps.commit_push_new_branch.outputs.new_branch_name }} |
| 214 | + PARAM_TITLE: "Docs: Automated update from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}" |
| 215 | + PARAM_BODY: | |
| 216 | + Automated Antora site regeneration based on changes in the IvorySQL/ivorysql_docs repository. |
| 217 | +
|
| 218 | + Source commit: `${{ github.server_url }}/${{ github.repository_owner }}/ivorysql_docs/commit/${{ github.event.head_commit.id || github.sha }}` |
| 219 | + |
| 220 | + - Auto-generated by gh pr create |
| 221 | + PARAM_DRAFT: "false" |
| 222 | + run: | |
| 223 | + echo "Attempting to create or update Pull Request for branch '${PARAM_HEAD_BRANCH}' into '${PARAM_BASE_BRANCH}'" |
| 224 | + |
| 225 | + DRAFT_FLAG_STRING="" |
| 226 | + if [[ "${PARAM_DRAFT}" == "true" ]]; then |
| 227 | + DRAFT_FLAG_STRING="--draft" |
| 228 | + fi |
| 229 | +
|
| 230 | + echo "Executing: gh pr create --base \"${PARAM_BASE_BRANCH}\" --head \"${PARAM_HEAD_BRANCH}\" --title <title> --body-file <(echo body) ${DRAFT_FLAG_STRING}" |
| 231 | + |
| 232 | + if gh pr create \ |
| 233 | + --base "${PARAM_BASE_BRANCH}" \ |
| 234 | + --head "${PARAM_HEAD_BRANCH}" \ |
| 235 | + --title "${PARAM_TITLE}" \ |
| 236 | + --body-file <(echo "${PARAM_BODY}") \ |
| 237 | + ${DRAFT_FLAG_STRING}; then |
| 238 | + echo "Pull Request created or already exists and metadata might have been updated." |
| 239 | + else |
| 240 | + echo "'gh pr create' command indicated an issue or no action was taken." |
| 241 | +
|
| 242 | + EXISTING_PR_URL=$(gh pr view "${PARAM_HEAD_BRANCH}" --json url -q ".url" 2>/dev/null || echo "") |
| 243 | + if [[ -n "$EXISTING_PR_URL" ]]; then |
| 244 | + echo "An existing PR was found for branch '${PARAM_HEAD_BRANCH}': ${EXISTING_PR_URL}" |
| 245 | + echo "Proceeding to enable auto-merge for this existing PR." |
| 246 | + else |
| 247 | + echo "::error::Failed to create PR and no existing PR found for branch '${PARAM_HEAD_BRANCH}'. Cannot enable auto-merge." |
| 248 | + exit 1 |
| 249 | + fi |
| 250 | + fi |
| 251 | +
|
| 252 | + - name: Enable Auto-Merge for PR |
| 253 | + 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 != '' |
| 254 | + working-directory: ./www_publish_target |
| 255 | + env: |
| 256 | + GH_TOKEN: ${{ secrets.WEB_TOKEN }} |
| 257 | + PR_HEAD_BRANCH: ${{ steps.commit_push_new_branch.outputs.new_branch_name }} |
| 258 | + PR_BASE_BRANCH: master |
| 259 | + MERGE_STRATEGY: MERGE |
| 260 | + run: | |
| 261 | + echo "Attempting to enable auto-merge for PR from branch '$PR_HEAD_BRANCH' to '$PR_BASE_BRANCH'" |
| 262 | + if gh pr merge "$PR_HEAD_BRANCH" \ |
| 263 | + --${MERGE_STRATEGY,,} \ |
| 264 | + --delete-branch; then |
| 265 | + echo "Auto-merge enabled successfully for PR from branch '$PR_HEAD_BRANCH'." |
| 266 | + else |
| 267 | + echo "::warning::Failed to enable auto-merge for PR from branch '$PR_HEAD_BRANCH'." |
| 268 | + 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." |
| 269 | + fi |
0 commit comments