|
| 1 | +name: Build and Deploy Antora Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push |
| 5 | + |
| 6 | +jobs: |
| 7 | + build-and-deploy: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout Documentation Repository (ivorysql_doc) |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + path: ivorysql_doc |
| 17 | + |
| 18 | + - name: Checkout Doc Builder Repository (doc_builder) |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + repository: IvorySQL/ivory-doc-builder |
| 22 | + path: ivory-doc-builder |
| 23 | + |
| 24 | + - name: Checkout Web Repository (web) |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + repository: IvorySQL/ivorysql_web |
| 28 | + path: www_publish_target |
| 29 | + token: ${{ secrets.IVROY_TOKEN }} |
| 30 | + |
| 31 | + - name: Setup Ruby and Bundler |
| 32 | + uses: ruby/setup-ruby@v1 |
| 33 | + with: |
| 34 | + ruby-version: '3.0' |
| 35 | + |
| 36 | + - name: Install Asciidoctor PDF and related Gems |
| 37 | + run: | |
| 38 | + echo "Installing Asciidoctor PDF gems..." |
| 39 | + gem install asciidoctor-pdf --version "~>2.3.19" |
| 40 | + gem install rouge |
| 41 | + |
| 42 | + - name: Setup Node.js |
| 43 | + uses: actions/setup-node@v4 |
| 44 | + with: |
| 45 | + node-version: '22.15' |
| 46 | + |
| 47 | + - name: Install Antora CLI |
| 48 | + run: | |
| 49 | + echo "Installing Antora packages local..." |
| 50 | + npm install --global antora@3.1.7 @antora/lunr-extension @antora/pdf-extension @node-rs/jieba |
| 51 | +
|
| 52 | + - name: Build English Documentation |
| 53 | + working-directory: ./ivory-doc-builder |
| 54 | + run: | |
| 55 | + echo "Current directory: $(pwd)" |
| 56 | + echo "Building English site..." |
| 57 | + ls ../www_publish_target/ |
| 58 | + npx antora generate --stacktrace --to-dir ../www_publish_target/docs/en antora-playbook-EN.yml |
| 59 | +
|
| 60 | + - name: Build Chinese Documentation |
| 61 | + working-directory: ./ivory-doc-builder |
| 62 | + run: | |
| 63 | + echo "Building Chinese site..." |
| 64 | + npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml |
| 65 | +
|
| 66 | + - name: Commit and Push to web Repository new branch , pull request |
| 67 | + id: commit_push_new_branch |
| 68 | + working-directory: ./www_publish_target |
| 69 | + run: | |
| 70 | + echo "--- Preparing to commit and push changes ---" |
| 71 | + NEW_TEXT="docs-$(date +'%Y-%m-%d-%H%M%S')" |
| 72 | + touch "${NEW_TEXT}".md |
| 73 | + echo "test" >> "${NEW_TEXT}".md |
| 74 | + echo "--- Git status ---" |
| 75 | + GIT_STATUS_OUTPUT=$(git status --porcelain) |
| 76 | + echo "${GIT_STATUS_OUTPUT}" |
| 77 | + echo "--- End of git status --porcelain output ---" |
| 78 | +
|
| 79 | + git config user.name "IvorySQL Actions Bot" |
| 80 | + git config user.email "actions-bot@users.noreply.github.com" |
| 81 | + |
| 82 | + if [ -z "${GIT_STATUS_OUTPUT}" ]; then |
| 83 | + echo "No changes to commit." |
| 84 | + echo "changes_detected=false" >> $GITHUB_OUTPUT |
| 85 | + else |
| 86 | + echo "Changes detected. Proceeding with add, commit, and push." |
| 87 | + NEW_BRANCH_NAME="docs-update-${{ github.run_attempt }}-$(date +'%Y-%m-%d-%H%M%S')" |
| 88 | + echo "Generated new branch name: ${NEW_BRANCH_NAME}" |
| 89 | + echo "new_branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT |
| 90 | + echo "changes_detected=true" >> $GITHUB_OUTPUT |
| 91 | + git checkout -b "${NEW_BRANCH_NAME}" |
| 92 | + git add . |
| 93 | + COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}" |
| 94 | + git commit -m "${COMMIT_MESSAGE}" |
| 95 | + git push origin "${NEW_BRANCH_NAME}" |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Create or Update Pull Request with GitHub CLI |
| 99 | + id: cpr |
| 100 | + if: steps.commit_push_new_branch.outputs.changes_detected == 'true' && steps.commit_push_new_branch.outputs.new_branch_name != '' |
| 101 | + working-directory: ./www_publish_target |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ secrets.IVROY_TOKEN }} |
| 104 | + PARAM_BASE_BRANCH: master |
| 105 | + PARAM_HEAD_BRANCH: ${{ steps.commit_push_new_branch.outputs.new_branch_name }} |
| 106 | + PARAM_TITLE: "Docs: Automated update from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}" |
| 107 | + PARAM_BODY: | |
| 108 | + Automated Antora site regeneration based on changes in the IvorySQL/ivorysql_docs repository. |
| 109 | +
|
| 110 | + Source commit: `${{ github.server_url }}/${{ github.repository_owner }}/ivorysql_docs/commit/${{ github.event.head_commit.id || github.sha }}` |
| 111 | + |
| 112 | + - Auto-generated by gh pr create |
| 113 | + PARAM_DRAFT: "false" |
| 114 | + run: | |
| 115 | + echo "Attempting to create or update Pull Request for branch '${PARAM_HEAD_BRANCH}' into '${PARAM_BASE_BRANCH}'" |
| 116 | + |
| 117 | + DRAFT_FLAG_STRING="" |
| 118 | + if [[ "${PARAM_DRAFT}" == "true" ]]; then |
| 119 | + DRAFT_FLAG_STRING="--draft" |
| 120 | + fi |
| 121 | +
|
| 122 | + echo "Executing: gh pr create --base \"${PARAM_BASE_BRANCH}\" --head \"${PARAM_HEAD_BRANCH}\" --title <title> --body-file <(echo body) ${DRAFT_FLAG_STRING}" |
| 123 | + |
| 124 | + if gh pr create \ |
| 125 | + --base "${PARAM_BASE_BRANCH}" \ |
| 126 | + --head "${PARAM_HEAD_BRANCH}" \ |
| 127 | + --title "${PARAM_TITLE}" \ |
| 128 | + --body-file <(echo "${PARAM_BODY}") \ |
| 129 | + ${DRAFT_FLAG_STRING}; then |
| 130 | + echo "Pull Request created or updated successfully." |
| 131 | + else |
| 132 | + echo "'gh pr create' command failed." |
| 133 | + echo "This could be because a PR from '${PARAM_HEAD_BRANCH}' to '${PARAM_BASE_BRANCH}' already exists and could not be updated with the provided metadata, or another error occurred." |
| 134 | + echo "New commits pushed to '${PARAM_HEAD_BRANCH}' in the previous step should automatically update an existing PR's content." |
| 135 | + |
| 136 | + EXISTING_PR_URL=$(gh pr view "${PARAM_HEAD_BRANCH}" --json url -q ".url" 2>/dev/null || echo "") |
| 137 | + if [[ -n "$EXISTING_PR_URL" ]]; then |
| 138 | + echo "An existing PR was found for branch '${PARAM_HEAD_BRANCH}': ${EXISTING_PR_URL}" |
| 139 | + echo "The 'gh pr create' command might have already updated its metadata if possible." |
| 140 | + echo "If specific metadata changes were not applied, you might consider using 'gh pr edit ${EXISTING_PR_URL} ...' with specific flags in a separate step if needed." |
| 141 | + else |
| 142 | + echo "Failed to create PR and no existing PR found for branch '${PARAM_HEAD_BRANCH}' using 'gh pr view'. Check GH CLI error output above for more details." |
| 143 | + exit 1 |
| 144 | + fi |
| 145 | + fi |
0 commit comments