Skip to content

remove the directory v5.1 #238

remove the directory v5.1

remove the directory v5.1 #238

Workflow file for this run

name: Pr preview
on:
pull_request_target:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
statuses: write
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 }}
path: ivorysql_doc
- 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
- 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
working-directory: ./ivory-doc-builder
env:
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
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"
# Extract version from PR base branch (e.g., v5.1 -> 5.1)
if [[ "$PR_BASE_REF" =~ ^v([0-9]+\.[0-9]+) ]]; then
DETECTED_VERSION="${BASH_REMATCH[1]}"
echo "Detected version from PR base branch $PR_BASE_REF: $DETECTED_VERSION"
else
DETECTED_VERSION="master"
echo "Using default version: master (PR base: $PR_BASE_REF)"
fi
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 ".content.sources[0].branches = [\"HEAD\"]" "$PLAYBOOK_FILE"
yq -i ".content.sources[0].edit_url = false" "$PLAYBOOK_FILE"
# Disable runtime fetch to ensure we use local files
yq -i ".runtime.fetch = false" "$PLAYBOOK_FILE"
if [[ -n "$DETECTED_VERSION" && "$DETECTED_VERSION" != "master" ]]; then
# v5.1+ uses flat structure (no version prefix in path)
# v5.0 and earlier use nested structure (version prefix in path)
# Use version comparison: if DETECTED_VERSION >= 5.1, use flat structure
if [[ "$(printf '%s\n' "5.1" "$DETECTED_VERSION" | sort -V | head -n1)" == "5.1" ]]; then
# For v5.1+: ivorysql-doc:v5.1:welcome.adoc (no version prefix in path)
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:${START_PAGE_FILE_PATH}"
else
# For v5.0 and earlier: ivorysql-doc:v5.0:v5.0/welcome.adoc (with version prefix)
NEW_START_PAGE="${START_PAGE_COMPONENT_NAME}:v${DETECTED_VERSION}:v${DETECTED_VERSION}/${START_PAGE_FILE_PATH}"
fi
yq -i ".site.start_page = \"$NEW_START_PAGE\"" "$PLAYBOOK_FILE"
echo "Updated .site.start_page in $PLAYBOOK_FILE to: $NEW_START_PAGE"
else
echo "INFO: DETECTED_VERSION is '$DETECTED_VERSION'. Keeping original playbook start_page configuration."
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
- 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 @node-rs/jieba
- name: Build English 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
- name: Build Chinese Documentation
working-directory: ./ivory-doc-builder
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
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
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
});