Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 122 additions & 103 deletions .github/workflows/merge-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ on:

jobs:
build-and-deploy:
name: Publish docs (${{ matrix.target }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [html, en, cn]
concurrency:
group: docs-publish-${{ inputs.source_branch || github.ref_name }}-${{ matrix.target }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
Expand All @@ -25,14 +33,17 @@ jobs:
with:
path: ivorysql_doc
ref: ${{ inputs.source_branch || github.sha }}
persist-credentials: false

- 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: Determine Latest Version from ivorysql_docs branches
if: matrix.target == 'html'
id: latest_version_step
shell: bash
run: |
Expand All @@ -55,13 +66,15 @@ jobs:

- 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
mkdir -p "$RUNNER_TEMP/docs-tools"
curl --fail --silent --show-error --location \
https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
--output "$RUNNER_TEMP/docs-tools/yq"
chmod +x "$RUNNER_TEMP/docs-tools/yq"
echo "$RUNNER_TEMP/docs-tools" >> "$GITHUB_PATH"

- name: Modify Antora Playbooks
if: matrix.target == 'html'
working-directory: ./ivory-doc-builder
env:
DETECTED_VERSION: '${{ steps.latest_version_step.outputs.version }}'
Expand Down Expand Up @@ -101,22 +114,88 @@ jobs:
fi
done

- name: Pin PDF assembler to source branch
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.15'

- name: Install Antora CLI
env:
TARGET: ${{ matrix.target }}
run: |
packages=(antora@3.1.7)
if [[ "$TARGET" == html ]]; then
packages+=(@antora/lunr-extension @node-rs/jieba)
else
packages+=(@antora/pdf-extension@1.0.0-beta.20)
fi
npm install --global "${packages[@]}"

- name: Set up Ruby for PDF export
if: matrix.target != 'html'
timeout-minutes: 10
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'

- name: Install Asciidoctor PDF
if: matrix.target != 'html'
timeout-minutes: 10
run: |
gem install asciidoctor-pdf --version "~>2.3.19"
gem install rouge

- name: Export PDF
id: pdf
if: matrix.target != 'html'
timeout-minutes: 60
working-directory: ./ivory-doc-builder
shell: bash
env:
MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
PDF_LANGUAGE: ${{ matrix.target }}
SOURCE_BRANCH: ${{ inputs.source_branch || github.ref_name }}
run: |
if [[ -z "${MERGED_BRANCH}" ]]; then
echo "::error::Merged branch name is empty, cannot update PDF component version."
descriptor="../ivorysql_doc/${PDF_LANGUAGE^^}/antora.yml"
playbook="antora-playbook-${PDF_LANGUAGE^^}.yml"
component="$(yq -er '.name' "$descriptor")"
version="$(yq -er '.version' "$descriptor")"
page="$(yq -r '.start_page // "index.adoc"' "$descriptor")"

if [[ "$component" != ivorysql-doc || "$version" != "$SOURCE_BRANCH" ]]; then
echo "::error::Expected ivorysql-doc version $SOURCE_BRANCH, found $component version $version."
exit 1
fi
if [[ "$page" != *:* ]]; then
page=":$page"
fi

TARGET_COMPONENT_VERSION="${MERGED_BRANCH}@${COMPONENT_NAME}"
echo "Setting antora-assembler.yml component_versions to ${TARGET_COMPONENT_VERSION}"
yq -i ".component_versions = \"${TARGET_COMPONENT_VERSION}\"" antora-assembler.yml
echo "Updated antora-assembler.yml:"
cat antora-assembler.yml
START_PAGE="$component:$page" UI_BUNDLE="./${PDF_LANGUAGE}templates.zip" yq -i '
.content.sources[0].url = "../ivorysql_doc" |
.content.sources[0].branches = ["HEAD"] |
.runtime.fetch = false |
.site.start_page = strenv(START_PAGE) |
.ui.bundle.url = strenv(UI_BUNDLE) |
del(.urls.latest_version_segment, .urls.latest_version_segment_strategy) |
del(.antora.extensions[] | select(. == "@antora/lunr-extension" or .require == "@antora/lunr-extension"))
' "$playbook"

# Keep the dots small enough to fit the line height of every TOC level.
pdf_theme="$(yq -er '.asciidoc.attributes."pdf-theme"' antora-assembler.yml)"
yq -i '.toc."dot-leader"."font-size" = 10' "$pdf_theme"
COMPONENT_VERSION="$version@$component" BUILD_DIR="$RUNNER_TEMP/assembler" yq -i '
.component_versions = strenv(COMPONENT_VERSION) |
.asciidoc.attributes."toc-max-pagenum-digits" = 4 |
.build.dir = strenv(BUILD_DIR) |
.build.command = "asciidoctor-pdf --failure-level ERROR"
' antora-assembler.yml
time npx antora generate --stacktrace --to-dir "$RUNNER_TEMP/pdf-site" "$playbook"
pdf="$RUNNER_TEMP/pdf-site/$component/$version/_exports/index.pdf"
if [[ ! -s "$pdf" ]]; then
echo "::error::PDF export did not produce $pdf."
exit 1
fi
echo "path=$pdf" >> "$GITHUB_OUTPUT"
echo "component_path=$component/$version" >> "$GITHUB_OUTPUT"

- name: Checkout Web Repository (web)
uses: actions/checkout@v4
Expand All @@ -126,6 +205,7 @@ jobs:
token: ${{ secrets.WEB_TOKEN }}

- name: Ensure web index redirects to latest home
if: matrix.target == 'html'
id: update_web_index
working-directory: ./www_publish_target
env:
Expand Down Expand Up @@ -163,100 +243,38 @@ jobs:

echo "index_updated=${UPDATE_NEEDED}" >> "$GITHUB_OUTPUT"

- name: Setup Ruby and Bundler
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'

- name: Install Asciidoctor PDF and related Gems
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:
node-version: '22.15'

- 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

- name: Build English Documentation
working-directory: ./ivory-doc-builder
run: |
echo "Current directory: $(pwd)"
echo "Building English site..."
ls ../www_publish_target/
npx antora generate --stacktrace --to-dir ../www_publish_target/docs/en antora-playbook-EN.yml

- name: Copy English PDF export into web repo
working-directory: ./ivory-doc-builder
env:
MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
run: |
set -euo pipefail

if [[ -z "${MERGED_BRANCH}" ]]; then
echo "::error::Merged branch name is empty, cannot locate PDF output."
exit 1
fi

SOURCE_PDF_EN="build/assembler-pdf/${COMPONENT_NAME}/${MERGED_BRANCH}/_exports/index.pdf"
DEST_EN="../www_publish_target/docs/en/${COMPONENT_NAME}/${MERGED_BRANCH}/ivorysql.pdf"

if [[ ! -f "${SOURCE_PDF_EN}" ]]; then
echo "::error::English PDF not found at ${SOURCE_PDF_EN}"
exit 1
fi

echo "Copying English PDF from ${SOURCE_PDF_EN} to web repo target..."
mkdir -p "$(dirname "${DEST_EN}")"
cp "${SOURCE_PDF_EN}" "${DEST_EN}"
echo "English PDF copied to:"
echo " - ${DEST_EN}"

- name: Build Chinese Documentation
- name: Build English and Chinese websites
if: matrix.target == 'html'
working-directory: ./ivory-doc-builder
shell: bash
run: |
echo "Building Chinese site..."
npx antora generate --stacktrace --to-dir ../www_publish_target/docs/cn antora-playbook-CN.yml
for language in en cn; do
yq '
del(.antora.extensions[] | select(. == "@antora/pdf-extension" or .require == "@antora/pdf-extension")) |
.output.clean = false
' "antora-playbook-${language^^}.yml" > "antora-playbook-html-${language}.yml"
npx antora generate --stacktrace --to-dir "../www_publish_target/docs/${language}" "antora-playbook-html-${language}.yml"
done

- name: Copy Chinese PDF export into web repo
working-directory: ./ivory-doc-builder
- name: Copy PDF into web repository
if: matrix.target != 'html'
working-directory: ./www_publish_target
env:
MERGED_BRANCH: ${{ inputs.source_branch || github.ref_name }}
COMPONENT_NAME: ivorysql-doc
PDF_LANGUAGE: ${{ matrix.target }}
PDF: ${{ steps.pdf.outputs.path }}
COMPONENT_PATH: ${{ steps.pdf.outputs.component_path }}
run: |
set -euo pipefail

if [[ -z "${MERGED_BRANCH}" ]]; then
echo "::error::Merged branch name is empty, cannot locate PDF output."
exit 1
fi

SOURCE_PDF="build/assembler-pdf/${COMPONENT_NAME}/${MERGED_BRANCH}/_exports/index.pdf"
DEST_CN="../www_publish_target/docs/cn/${COMPONENT_NAME}/${MERGED_BRANCH}/ivorysql.pdf"

if [[ ! -f "${SOURCE_PDF}" ]]; then
echo "::error::PDF not found at ${SOURCE_PDF}"
exit 1
fi

echo "Copying PDF from ${SOURCE_PDF} to web repo targets..."
mkdir -p "$(dirname "${DEST_CN}")"
cp "${SOURCE_PDF}" "${DEST_CN}"
echo "PDF copied to:"
echo " - ${DEST_CN}"
web_component="docs/$PDF_LANGUAGE/$COMPONENT_PATH"
mkdir -p "$web_component/_exports"
cp "$PDF" "$web_component/_exports/index.pdf"
cp "$PDF" "$web_component/ivorysql.pdf"

- name: Commit and Push to web Repository new branch , pull request
id: commit_push_new_branch
working-directory: ./www_publish_target
env:
OPEN_PUSH_PR: true
TARGET: ${{ matrix.target }}
run: |
echo "push_pr=${OPEN_PUSH_PR}" >> $GITHUB_OUTPUT
echo "--- Preparing to commit and push changes ---"
Expand All @@ -273,20 +291,21 @@ jobs:
echo "changes_detected=false" >> $GITHUB_OUTPUT
else
echo "Changes detected. Proceeding with add, commit, and push."
SOURCE_COMMIT="$(git -C ../ivorysql_doc rev-parse HEAD)"
echo "source_commit=$SOURCE_COMMIT" >> "$GITHUB_OUTPUT"
COMMIT_MESSAGE="docs: Regenerate documentation ($TARGET) from IvorySQL/ivorysql_docs commit $SOURCE_COMMIT"
if [[ "${OPEN_PUSH_PR}" == "true" ]]; then
NEW_BRANCH_NAME="docs-update-${{ github.run_attempt }}-$(date +'%Y-%m-%d-%H%M%S')"
NEW_BRANCH_NAME="docs-update-${{ github.run_id }}-${{ github.run_attempt }}-$TARGET"
echo "Generated new branch name: ${NEW_BRANCH_NAME}"
echo "new_branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "changes_detected=true" >> $GITHUB_OUTPUT
git checkout -b "${NEW_BRANCH_NAME}"
git add .
COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
git commit -m "${COMMIT_MESSAGE}"
git push origin "${NEW_BRANCH_NAME}"
else
echo "Pushing changes to master branch."
git add .
COMMIT_MESSAGE="docs: Regenerate Antora site from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
git commit -m "${COMMIT_MESSAGE}"
git push origin master
fi
Expand All @@ -300,11 +319,11 @@ jobs:
GH_TOKEN: ${{ secrets.WEB_TOKEN }}
PARAM_BASE_BRANCH: master
PARAM_HEAD_BRANCH: ${{ steps.commit_push_new_branch.outputs.new_branch_name }}
PARAM_TITLE: "Docs: Automated update from IvorySQL/ivorysql_docs commit ${{ github.event.head_commit.id || github.sha }}"
PARAM_TITLE: "Docs: Automated update (${{ matrix.target }}) from IvorySQL/ivorysql_docs"
PARAM_BODY: |
Automated Antora site regeneration based on changes in the IvorySQL/ivorysql_docs repository.

Source commit: `${{ github.server_url }}/${{ github.repository_owner }}/ivorysql_docs/commit/${{ github.event.head_commit.id || github.sha }}`
Source commit: `${{ github.server_url }}/${{ github.repository_owner }}/ivorysql_docs/commit/${{ steps.commit_push_new_branch.outputs.source_commit }}`

- Auto-generated by gh pr create
PARAM_DRAFT: "false"
Expand Down
Loading
Loading