diff --git a/.github/workflows/merge-build-push.yml b/.github/workflows/merge-build-push.yml
index 1245236a..9aab23ee 100644
--- a/.github/workflows/merge-build-push.yml
+++ b/.github/workflows/merge-build-push.yml
@@ -1,10 +1,11 @@
name: Build , Push to web, Deploy Antora Docs
on:
- pull_request_target:
- types:
- - closed
- create:
+ push:
+ branches:
+ - master
+ - 'v[0-9]+.[0-9]+'
+ - 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
source_branch:
@@ -14,23 +15,16 @@ on:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
- if: github.event_name == 'workflow_dispatch' || github.event_name == 'create' || github.event.pull_request.merged == true
permissions:
contents: write
pull-requests: write
steps:
- - name: PR was merged
- if: github.event.pull_request.number != ''
- run: |
- echo "PR #${{ github.event.pull_request.number }} was merged into ${{ github.event.pull_request.base.ref }}."
- echo "Head commit was: ${{ github.event.pull_request.head.sha }}"
-
- name: Checkout Documentation Repository (ivorysql_doc)
uses: actions/checkout@v4
with:
path: ivorysql_doc
- ref: ${{ inputs.source_branch || github.ref }}
+ ref: ${{ inputs.source_branch || github.sha }}
- name: Checkout Doc Builder Repository (doc_builder)
uses: actions/checkout@v4
@@ -107,10 +101,10 @@ jobs:
fi
done
- - name: Pin PDF assembler to merged PR branch
+ - name: Pin PDF assembler to source branch
working-directory: ./ivory-doc-builder
env:
- MERGED_BRANCH: ${{ inputs.source_branch || github.event.pull_request.base.ref || github.ref_name }}
+ MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
run: |
if [[ -z "${MERGED_BRANCH}" ]]; then
@@ -136,7 +130,7 @@ jobs:
working-directory: ./www_publish_target
env:
LATEST_VERSION: ${{ steps.latest_version_step.outputs.version }}
- MERGED_PR_BASE: ${{ github.event.pull_request.base.ref || github.ref_name }}
+ MERGED_PR_BASE: ${{ inputs.source_branch || github.ref_name }}
run: |
set -euo pipefail
@@ -201,7 +195,7 @@ jobs:
- name: Copy English PDF export into web repo
working-directory: ./ivory-doc-builder
env:
- MERGED_BRANCH: ${{ inputs.source_branch || github.event.pull_request.base.ref || github.ref_name }}
+ MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
run: |
set -euo pipefail
@@ -234,7 +228,7 @@ jobs:
- name: Copy Chinese PDF export into web repo
working-directory: ./ivory-doc-builder
env:
- MERGED_BRANCH: ${{ inputs.source_branch || github.event.pull_request.base.ref || github.ref_name }}
+ MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
run: |
set -euo pipefail
diff --git a/.github/workflows/pr-preview-deploy.yml b/.github/workflows/pr-preview-deploy.yml
new file mode 100644
index 00000000..2545f32a
--- /dev/null
+++ b/.github/workflows/pr-preview-deploy.yml
@@ -0,0 +1,244 @@
+name: Deploy PR preview
+
+on:
+ workflow_run:
+ workflows: [Pr preview]
+ types: [completed]
+
+permissions: {}
+
+jobs:
+ verify:
+ if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
+ runs-on: ubuntu-latest
+ permissions:
+ actions: read
+ pull-requests: read
+ outputs:
+ number: ${{ steps.preview.outputs.number }}
+ artifact_id: ${{ steps.preview.outputs.artifact_id }}
+ steps:
+ - name: Match the build artifact to an open pull request
+ id: preview
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const run = context.payload.workflow_run;
+ if (run.path?.split('@')[0] !== '.github/workflows/pr-preview.yml' ||
+ run.repository?.id !== context.payload.repository.id || !run.head_repository) {
+ return;
+ }
+
+ // GitHub can omit pull_requests for fork runs. Use the artifact name
+ // to look up the PR, then verify its source against GitHub's run data.
+ const pattern = new RegExp(`^docs-preview-${run.run_attempt}-pr-([1-9][0-9]*)$`);
+ const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
+ ...context.repo,
+ run_id: run.id,
+ });
+ const matches = artifacts.filter(artifact => !artifact.expired && pattern.test(artifact.name));
+ if (matches.length !== 1) {
+ core.setFailed('Expected one unexpired documentation artifact. Re-run the preview build to upload a new one.');
+ return;
+ }
+
+ const artifact = matches[0];
+ const number = Number(artifact.name.match(pattern)[1]);
+ if (!Number.isSafeInteger(number) ||
+ (run.pull_requests?.length && !run.pull_requests.some(pr => pr.number === number))) {
+ return;
+ }
+
+ const { data: pr } = await github.rest.pulls.get({
+ ...context.repo,
+ pull_number: number,
+ });
+ if (pr.state !== 'open' || pr.head.sha !== run.head_sha ||
+ pr.head.ref !== run.head_branch || pr.head.repo?.id !== run.head_repository.id) {
+ core.notice('The pull request is closed or its source has changed.');
+ return;
+ }
+
+ core.setOutput('number', number);
+ core.setOutput('artifact_id', artifact.id);
+
+ deploy:
+ needs: verify
+ if: needs.verify.outputs.number != ''
+ runs-on: ubuntu-latest
+ concurrency:
+ group: docs-preview-deploy-${{ needs.verify.outputs.number }}
+ cancel-in-progress: false
+ queue: max
+ permissions:
+ actions: read
+ deployments: write
+ pull-requests: write
+ statuses: write
+ env:
+ PR_NUMBER: ${{ needs.verify.outputs.number }}
+ steps:
+ - name: Download the verified preview archive
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ artifact-ids: ${{ needs.verify.outputs.artifact_id }}
+ path: ${{ runner.temp }}/docs-preview-archive
+ github-token: ${{ github.token }}
+ run-id: ${{ github.event.workflow_run.id }}
+ skip-decompress: true
+ digest-mismatch: error
+
+ - name: Validate and extract the static site
+ shell: bash
+ run: |
+ python3 - <<'PY'
+ import os
+ import stat
+ from pathlib import Path
+ from zipfile import ZipFile
+
+ runner_temp = Path(os.environ['RUNNER_TEMP'])
+ downloads = list((runner_temp / 'docs-preview-archive').iterdir())
+ if len(downloads) != 1 or not downloads[0].is_file():
+ raise SystemExit('Expected exactly one preview archive.')
+
+ with ZipFile(downloads[0]) as archive:
+ paths = set()
+ missing_homepages = {'cn/index.html', 'en/index.html'}
+ for entry in archive.infolist():
+ name = entry.filename.removesuffix('/')
+ parts = name.split('/')
+ if (parts[0] not in {'cn', 'en'} or '\\' in name or
+ any(part in {'', '.', '..'} for part in parts) or name in paths or
+ (len(parts) == 1 and not entry.is_dir())):
+ raise SystemExit(f'Invalid or duplicate preview path: {entry.filename!r}')
+ expected_type = stat.S_IFDIR if entry.is_dir() else stat.S_IFREG
+ if stat.S_IFMT(entry.external_attr >> 16) not in (0, expected_type):
+ raise SystemExit(f'Invalid preview file type: {entry.filename!r}')
+ paths.add(name)
+ if not entry.is_dir():
+ missing_homepages.discard(name)
+
+ if missing_homepages:
+ raise SystemExit('The preview archive must include both language homepages.')
+ archive.extractall(runner_temp / 'docs-preview')
+ PY
+
+ cat > "$RUNNER_TEMP/docs-preview/index.html" <<'HTML'
+
+
+
+
IvorySQL Docs Preview
+
+ δΈζι’θ§
+ English preview
+
+ HTML
+
+ - name: Check that this is still the current PR commit
+ id: current
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const { data: pr } = await github.rest.pulls.get({
+ ...context.repo,
+ pull_number: Number(process.env.PR_NUMBER),
+ });
+ core.setOutput('deploy', pr.state === 'open' && pr.head.sha === context.payload.workflow_run.head_sha);
+
+ - name: Deploy to Netlify
+ if: steps.current.outputs.deploy == 'true'
+ id: netlify
+ uses: nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654 # v3.0
+ with:
+ publish-dir: ${{ runner.temp }}/docs-preview
+ deploy-message: "Deploy preview for PR #${{ env.PR_NUMBER }}"
+ # PR HTML and JavaScript are contributor-controlled. Keep them on a draft preview alias.
+ production-deploy: false
+ enable-pull-request-comment: false
+ enable-commit-comment: false
+ enable-commit-status: false
+ enable-github-deployment: false
+ fails-without-credentials: true
+ alias: pr-${{ env.PR_NUMBER }}-doc
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
+ timeout-minutes: 5
+
+ - name: Post preview links and report deployment on GitHub
+ if: steps.netlify.outputs.deploy-url != ''
+ uses: actions/github-script@v7
+ env:
+ DEPLOY_URL: ${{ steps.netlify.outputs.deploy-url }}
+ with:
+ script: |
+ const number = Number(process.env.PR_NUMBER);
+ const sha = context.payload.workflow_run.head_sha;
+ const { data: pr } = await github.rest.pulls.get({
+ ...context.repo,
+ pull_number: number,
+ });
+ if (pr.state !== 'open' || pr.head.sha !== sha) {
+ return;
+ }
+
+ const base = new URL(process.env.DEPLOY_URL);
+ const chinese = new URL('/cn/', base);
+ const english = new URL('/en/', base);
+ const marker = '';
+ const body = [
+ marker,
+ 'π **IvorySQL-Docs Preview Ready**',
+ '',
+ `- **Chinese Preview:** [${chinese}](${chinese})`,
+ `- **English Preview:** [${english}](${english})`,
+ ].join('\n');
+ const comments = await github.paginate(github.rest.issues.listComments, {
+ ...context.repo,
+ issue_number: number,
+ per_page: 100,
+ });
+ const previewComment = comments.find(comment =>
+ comment.user?.login === 'github-actions[bot]' && comment.body?.startsWith(marker)
+ );
+ if (previewComment) {
+ await github.rest.issues.updateComment({ ...context.repo, comment_id: previewComment.id, body });
+ } else {
+ await github.rest.issues.createComment({ ...context.repo, issue_number: number, body });
+ }
+
+ try {
+ await github.rest.repos.createCommitStatus({
+ ...context.repo,
+ sha,
+ context: 'Netlify',
+ description: 'Netlify deployment',
+ state: 'success',
+ target_url: base.href,
+ });
+ } catch (error) {
+ core.warning(`Could not update the Netlify commit status: ${error.message}`);
+ }
+
+ try {
+ const { data: deployment } = await github.rest.repos.createDeployment({
+ ...context.repo,
+ ref: sha,
+ environment: 'pull request',
+ auto_merge: false,
+ required_contexts: [],
+ production_environment: false,
+ });
+ await github.rest.repos.createDeploymentStatus({
+ ...context.repo,
+ deployment_id: deployment.id,
+ state: 'success',
+ environment_url: base.href,
+ });
+ } catch (error) {
+ core.warning(`Could not record the GitHub deployment: ${error.message}`);
+ }
diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml
index 84ae1afb..d2b65830 100644
--- a/.github/workflows/pr-preview.yml
+++ b/.github/workflows/pr-preview.yml
@@ -1,106 +1,95 @@
name: Pr preview
on:
- pull_request_target:
+ pull_request:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: docs-pr-preview-${{ github.event.pull_request.number || github.run_id }}
+ cancel-in-progress: true
jobs:
- build-and-deploy:
+ build:
+ name: Build documentation (${{ matrix.language }})
runs-on: ubuntu-latest
- permissions:
- contents: read
- pull-requests: write
- deployments: write
- statuses: write
+ strategy:
+ matrix:
+ language: [cn, en]
+ env:
+ DOC_LANGUAGE: ${{ matrix.language }}
steps:
- name: Checkout Documentation Repository (ivorysql_doc)
uses: actions/checkout@v4
with:
- ref: ${{ github.event.pull_request.head.sha }}
- repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.sha || github.sha }}
+ repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
path: ivorysql_doc
+ persist-credentials: false
- - name: Fetch All Relevant Branches into Local Docs Repo
- working-directory: ./ivorysql_doc
- run: |
- echo "Fetching all branches from origin to update local remote-tracking branches..."
- git fetch origin --prune --no-tags
-
- echo "--- Fetched Remote-Tracking Branches ---"
- git branch -r
-
- name: Checkout Doc Builder Repository (doc_builder)
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/ivory-doc-builder
path: ivory-doc-builder
-
+ persist-credentials: false
+
- name: Install yq
run: |
- sudo apt-get update -y
- sudo apt-get install -y jq
- sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
- sudo chmod +x /usr/bin/yq
- yq --version
-
- - name: Modify Antora Playbooks for Local PR Build
+ tools_dir="$RUNNER_TEMP/docs-preview-tools"
+ mkdir -p "$tools_dir"
+ curl --fail --silent --show-error --location \
+ https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
+ --output "$tools_dir/yq"
+ chmod +x "$tools_dir/yq"
+ echo "$tools_dir" >> "$GITHUB_PATH"
+
+ - name: Configure Antora for the selected language
working-directory: ./ivory-doc-builder
- env:
- DETECTED_VERSION: 'v6.0'
- START_PAGE_COMPONENT_NAME: "ivorysql-doc"
- START_PAGE_FILE_PATH: "welcome.adoc"
run: |
- PLAYBOOK_FILES=("antora-playbook-CN.yml" "antora-playbook-EN.yml")
- NEW_LOCAL_URL="../ivorysql_doc"
-
- for PLAYBOOK_FILE in "${PLAYBOOK_FILES[@]}"; do
- if [ -f "$PLAYBOOK_FILE" ]; then
- echo "--- Modifying Playbook: $PLAYBOOK_FILE ---"
- echo "Original content of $PLAYBOOK_FILE:"
- cat "$PLAYBOOK_FILE"
- echo # Newline for better readability
-
- yq -i ".content.sources[0].url = \"$NEW_LOCAL_URL\"" "$PLAYBOOK_FILE"
-
- yq -i ".ui.bundle.url = \"./entemplates.zip\"" "$PLAYBOOK_FILE"
-
- yq -i ".content.sources[0].branches = [\"HEAD\"]" "$PLAYBOOK_FILE"
-
- yq -i ".content.sources[0].edit_url = false" "$PLAYBOOK_FILE"
- if [[ -n "$DETECTED_VERSION" ]]; then
- NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}::${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
- yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE"
- echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE"
- else
- echo "WARNING: DETECTED_VERSION is empty. Skipping start_page update for $PLAYBOOK_FILE."
- fi
- yq -i ".site.title = .site.title + \" (PR Preview)\"" "$PLAYBOOK_FILE"
- echo "Modified content of $PLAYBOOK_FILE:"
- cat "$PLAYBOOK_FILE"
- echo "--- Finished modification for $PLAYBOOK_FILE ---"
- echo # Newline
- else
- echo "WARNING: Playbook file $PLAYBOOK_FILE not found in $(pwd)."
- fi
- done
-
- - name: Checkout WWW Repository (www)
- uses: actions/checkout@v4
- with:
- repository: ${{ github.repository_owner }}/ivorysql_web
- path: www_publish_target
-
+ language="${DOC_LANGUAGE^^}"
+ playbook="antora-playbook-${language}.yml"
+ descriptor="../ivorysql_doc/${language}/antora.yml"
+ component="$(yq -er '.name' "$descriptor")"
+ page="$(yq -r '.start_page // "index.adoc"' "$descriptor")"
+
+ # A page without a module coordinate belongs to the ROOT module.
+ if [[ "$page" == *:* ]]; then
+ start_page="${component}:${page}"
+ else
+ start_page="${component}::${page}"
+ fi
+
+ PREVIEW_START_PAGE="$start_page" yq -i '
+ .content.sources[0].url = "../ivorysql_doc" |
+ .content.sources[0].branches = ["HEAD"] |
+ .content.sources[0].edit_url = false |
+ .ui.bundle.url = "./entemplates.zip" |
+ .site.start_page = strenv(PREVIEW_START_PAGE)
+ ' "$playbook"
+
+ if [[ "$GITHUB_EVENT_NAME" == 'pull_request' ]]; then
+ yq -i '
+ .site.title += " (PR Preview)" |
+ del(.antora.extensions[] | select(. == "@antora/pdf-extension" or .require == "@antora/pdf-extension"))
+ ' "$playbook"
+ fi
+
- name: Setup Ruby and Bundler
+ if: github.event_name == 'workflow_dispatch'
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
- name: Install Asciidoctor PDF and related Gems
+ if: github.event_name == 'workflow_dispatch'
run: |
- echo "Installing Asciidoctor PDF gems..."
gem install asciidoctor-pdf --version "~>2.3.19"
gem install rouge
-
+
- name: Setup Node.js
uses: actions/setup-node@v4
with:
@@ -108,61 +97,67 @@ jobs:
- name: Install Antora CLI
run: |
- echo "Installing Antora packages local..."
- npm install --global antora@3.1.7 @antora/lunr-extension @antora/pdf-extension@1.0.0-beta.20 @node-rs/jieba
+ packages=(antora@3.1.7 @antora/lunr-extension @node-rs/jieba)
+ if [[ "$GITHUB_EVENT_NAME" == 'workflow_dispatch' ]]; then
+ packages+=(@antora/pdf-extension@1.0.0-beta.20)
+ fi
+ npm install --global "${packages[@]}"
- - name: Build English Documentation
+ - name: Build documentation
working-directory: ./ivory-doc-builder
run: |
- echo "Current directory: $(pwd)"
- echo "Building English site..."
- #mkdir -p ../www_publish_target/docs/en
- npx antora generate --stacktrace --to-dir ../www_publish_target/docs/en antora-playbook-EN.yml
+ npx antora generate --stacktrace --to-dir "../preview/$DOC_LANGUAGE" "antora-playbook-${DOC_LANGUAGE^^}.yml"
- - name: Build Chinese Documentation
- working-directory: ./ivory-doc-builder
+ - name: Upload HTML preview part
+ if: github.event_name == 'pull_request'
+ uses: actions/upload-artifact@v4
+ with:
+ name: docs-preview-part-${{ matrix.language }}
+ path: preview/
+ if-no-files-found: error
+ overwrite: true
+ retention-days: 3
+
+ - name: Upload documentation PDFs
+ if: github.event_name == 'workflow_dispatch'
+ uses: actions/upload-artifact@v4
+ with:
+ name: docs-pdf-${{ matrix.language }}
+ path: preview/${{ matrix.language }}/**/*.pdf
+ if-no-files-found: error
+ overwrite: true
+
+ build-and-deploy:
+ needs: build
+ if: ${{ !cancelled() && github.event_name == 'pull_request' }}
+ runs-on: ubuntu-latest
+ permissions:
+ actions: read
+ steps:
+ - name: Require both language builds to succeed
+ if: needs.build.result != 'success'
run: |
- echo "Building Chinese site..."
- #mkdir -p ../www_publish_target/docs/cn
- npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml
-
- - name: Deploy to Netlify
- id: netlify_deploy
- uses: nwtgck/actions-netlify@v3.0
+ echo "::error::Both language builds must succeed to package the preview."
+ exit 1
+
+ - name: Download both HTML preview parts
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
- publish-dir: './www_publish_target/docs'
- production-branch: test
- github-token: ${{ secrets.GITHUB_TOKEN }}
- deploy-message: "Deploy preview for PR #${{ github.event.number }}"
- enable-pull-request-comment: false
- enable-commit-comment: false
- enable-commit-status: true
- alias: pr-${{ github.event.number }}-doc
- env:
- NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- timeout-minutes: 5
-
- - name: Post Custom Preview Links Comment
- if: steps.netlify_deploy.outputs.deploy-url
- uses: actions/github-script@v7
+ pattern: docs-preview-part-*
+ merge-multiple: true
+ path: preview/
+ github-token: ${{ github.token }}
+ run-id: ${{ github.run_id }}
+
+ - name: Verify both preview homepages exist
+ run: |
+ test -f preview/cn/index.html
+ test -f preview/en/index.html
+
+ - name: Upload documentation preview
+ uses: actions/upload-artifact@v4
with:
- github-token: ${{ secrets.GITHUB_TOKEN }}
- script: |
- const baseUrl = '${{ steps.netlify_deploy.outputs.deploy-url }}';
-
- const enUrl = `${baseUrl}/en`;
-
- const body = `
- π **IvorySQL-Docs Preview Ready**
-
- - **Chinese Preview:** [${baseUrl}](${baseUrl})
- - **English Preview:** [${enUrl}](${enUrl})
- `;
-
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number,
- body: body
- });
+ name: docs-preview-${{ github.run_attempt }}-pr-${{ github.event.pull_request.number }}
+ path: preview/
+ if-no-files-found: error
+ retention-days: 3