|
| 1 | +name: Pr preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + build-and-deploy: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + deployments: write |
| 13 | + statuses: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout Documentation Repository (ivorysql_doc) |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: ${{ github.event.pull_request.head.sha }} |
| 20 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 21 | + path: ivorysql_doc |
| 22 | + |
| 23 | + - name: Fetch All Relevant Branches into Local Docs Repo |
| 24 | + working-directory: ./ivorysql_doc |
| 25 | + run: | |
| 26 | + echo "Fetching all branches from origin to update local remote-tracking branches..." |
| 27 | + git fetch origin --prune --no-tags |
| 28 | + |
| 29 | + echo "--- Fetched Remote-Tracking Branches ---" |
| 30 | + git branch -r |
| 31 | + |
| 32 | + - name: Checkout Doc Builder Repository (doc_builder) |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + repository: ${{ github.repository_owner }}/ivory-doc-builder |
| 36 | + path: ivory-doc-builder |
| 37 | + |
| 38 | + - name: Install yq |
| 39 | + run: | |
| 40 | + sudo apt-get update -y |
| 41 | + sudo apt-get install -y jq |
| 42 | + sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq |
| 43 | + sudo chmod +x /usr/bin/yq |
| 44 | + yq --version |
| 45 | +
|
| 46 | + - name: Modify Antora Playbooks for Local PR Build |
| 47 | + working-directory: ./ivory-doc-builder |
| 48 | + env: |
| 49 | + DETECTED_VERSION: 'master' |
| 50 | + START_PAGE_COMPONENT_NAME: "ivorysql-doc" |
| 51 | + START_PAGE_FILE_PATH: "welcome.adoc" |
| 52 | + run: | |
| 53 | + PLAYBOOK_FILES=("antora-playbook-CN.yml" "antora-playbook-EN.yml") |
| 54 | + NEW_LOCAL_URL="../ivorysql_doc" |
| 55 | +
|
| 56 | + for PLAYBOOK_FILE in "${PLAYBOOK_FILES[@]}"; do |
| 57 | + if [ -f "$PLAYBOOK_FILE" ]; then |
| 58 | + echo "--- Modifying Playbook: $PLAYBOOK_FILE ---" |
| 59 | + echo "Original content of $PLAYBOOK_FILE:" |
| 60 | + cat "$PLAYBOOK_FILE" |
| 61 | + echo # Newline for better readability |
| 62 | +
|
| 63 | + yq -i ".content.sources[0].url = \"$NEW_LOCAL_URL\"" "$PLAYBOOK_FILE" |
| 64 | +
|
| 65 | + yq -i ".ui.bundle.url = \"./entemplates.zip\"" "$PLAYBOOK_FILE" |
| 66 | +
|
| 67 | + yq -i ".content.sources[0].branches = [\"HEAD\"]" "$PLAYBOOK_FILE" |
| 68 | + |
| 69 | + yq -i ".content.sources[0].edit_url = false" "$PLAYBOOK_FILE" |
| 70 | + if [[ -n "$DETECTED_VERSION" ]]; then |
| 71 | + NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}::${DETECTED_VERSION}/${START_PAGE_FILE_PATH}" |
| 72 | + yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE" |
| 73 | + echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE" |
| 74 | + else |
| 75 | + echo "WARNING: DETECTED_VERSION is empty. Skipping start_page update for $PLAYBOOK_FILE." |
| 76 | + fi |
| 77 | + yq -i ".site.title = .site.title + \" (PR Preview)\"" "$PLAYBOOK_FILE" |
| 78 | + echo "Modified content of $PLAYBOOK_FILE:" |
| 79 | + cat "$PLAYBOOK_FILE" |
| 80 | + echo "--- Finished modification for $PLAYBOOK_FILE ---" |
| 81 | + echo # Newline |
| 82 | + else |
| 83 | + echo "WARNING: Playbook file $PLAYBOOK_FILE not found in $(pwd)." |
| 84 | + fi |
| 85 | + done |
| 86 | +
|
| 87 | + - name: Checkout WWW Repository (www) |
| 88 | + uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + repository: ${{ github.repository_owner }}/ivorysql_web |
| 91 | + path: www_publish_target |
| 92 | + |
| 93 | + - name: Setup Ruby and Bundler |
| 94 | + uses: ruby/setup-ruby@v1 |
| 95 | + with: |
| 96 | + ruby-version: '3.0' |
| 97 | + |
| 98 | + - name: Install Asciidoctor PDF and related Gems |
| 99 | + run: | |
| 100 | + echo "Installing Asciidoctor PDF gems..." |
| 101 | + gem install asciidoctor-pdf --version "~>2.3.19" |
| 102 | + gem install rouge |
| 103 | + |
| 104 | + - name: Setup Node.js |
| 105 | + uses: actions/setup-node@v4 |
| 106 | + with: |
| 107 | + node-version: '22.15' |
| 108 | + |
| 109 | + - name: Install Antora CLI |
| 110 | + run: | |
| 111 | + echo "Installing Antora packages local..." |
| 112 | + npm install --global antora@3.1.7 @antora/lunr-extension@1.0.0-alpha.11 @antora/pdf-extension@1.0.0-alpha.20 @node-rs/jieba@1.10.3 |
| 113 | +
|
| 114 | + - name: Build English Documentation |
| 115 | + working-directory: ./ivory-doc-builder |
| 116 | + run: | |
| 117 | + echo "Current directory: $(pwd)" |
| 118 | + echo "Building English site..." |
| 119 | + #mkdir -p ../www_publish_target/docs/en |
| 120 | + npx antora generate --stacktrace --to-dir ../www_publish_target/docs/en antora-playbook-EN.yml |
| 121 | +
|
| 122 | + - name: Build Chinese Documentation |
| 123 | + working-directory: ./ivory-doc-builder |
| 124 | + run: | |
| 125 | + echo "Building Chinese site..." |
| 126 | + #mkdir -p ../www_publish_target/docs/cn |
| 127 | + npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml |
| 128 | + |
| 129 | + - name: Deploy to Netlify |
| 130 | + id: netlify_deploy |
| 131 | + uses: nwtgck/actions-netlify@v3.0 |
| 132 | + with: |
| 133 | + publish-dir: './www_publish_target/docs' |
| 134 | + production-branch: test |
| 135 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + deploy-message: "Deploy preview for PR #${{ github.event.number }}" |
| 137 | + enable-pull-request-comment: false |
| 138 | + enable-commit-comment: false |
| 139 | + enable-commit-status: true |
| 140 | + alias: pr-${{ github.event.number }}-doc |
| 141 | + env: |
| 142 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 143 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 144 | + timeout-minutes: 5 |
| 145 | + |
| 146 | + - name: Post Custom Preview Links Comment |
| 147 | + if: steps.netlify_deploy.outputs.deploy-url |
| 148 | + uses: actions/github-script@v7 |
| 149 | + with: |
| 150 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 151 | + script: | |
| 152 | + const baseUrl = '${{ steps.netlify_deploy.outputs.deploy-url }}'; |
| 153 | + |
| 154 | + const enUrl = `${baseUrl}/en`; |
| 155 | +
|
| 156 | + const body = ` |
| 157 | + 🚀 **IvorySQL-Docs Preview Ready** |
| 158 | +
|
| 159 | + - **Chinese Preview:** [${baseUrl}](${baseUrl}) |
| 160 | + - **English Preview:** [${enUrl}](${enUrl}) |
| 161 | + `; |
| 162 | +
|
| 163 | + await github.rest.issues.createComment({ |
| 164 | + owner: context.repo.owner, |
| 165 | + repo: context.repo.repo, |
| 166 | + issue_number: context.issue.number, |
| 167 | + body: body |
| 168 | + }); |
0 commit comments