Test Japanese Translation #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Japanese Translation | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| relative_md_path: | |
| description: Optional path under markdown-translator/docs-for-test/en, for example tidb-cloud-intro.md | |
| required: false | |
| default: "" | |
| permissions: | |
| contents: read | |
| jobs: | |
| translate-ja: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: yarn | |
| cache-dependency-path: markdown-translator/yarn.lock | |
| - name: Install dependencies | |
| working-directory: markdown-translator | |
| run: yarn --frozen-lockfile | |
| - name: Configure translation credentials | |
| shell: bash | |
| env: | |
| GCP_KEY: ${{ secrets.GCP_KEY }} | |
| GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
| GCP_GLOSSARY_ID: ${{ secrets.GCP_GLOSSARY_ID }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${GCP_KEY}" ] || [ -z "${GCP_PROJECT_ID}" ] || [ -z "${GCP_GLOSSARY_ID}" ]; then | |
| echo "Missing one or more required secrets: GCP_KEY, GCP_PROJECT_ID, GCP_GLOSSARY_ID" >&2 | |
| exit 1 | |
| fi | |
| CREDENTIALS_FILE="$RUNNER_TEMP/gcp-key.json" | |
| echo "${GCP_KEY}" | base64 --decode > "${CREDENTIALS_FILE}" | |
| echo "GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_FILE}" >> "$GITHUB_ENV" | |
| echo "PROJECT_ID=${GCP_PROJECT_ID}" >> "$GITHUB_ENV" | |
| echo "GLOSSARY_ID=${GCP_GLOSSARY_ID}" >> "$GITHUB_ENV" | |
| - name: Generate artifact name | |
| id: artifact | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TIMESTAMP="$(date -u +'%Y%m%d-%H%M%S')" | |
| echo "name=ja-translation-output-${TIMESTAMP}" >> "$GITHUB_OUTPUT" | |
| - name: Prepare input and output directories | |
| id: prepare | |
| shell: bash | |
| env: | |
| RELATIVE_MD_PATH: ${{ inputs.relative_md_path }} | |
| run: | | |
| set -euo pipefail | |
| SOURCE_DIR="$GITHUB_WORKSPACE/markdown-translator/docs-for-test/en" | |
| TEMP_INPUT_DIR="$(mktemp -d)" | |
| OUTPUT_DIR="$GITHUB_WORKSPACE/markdown-translator/docs-for-test/ja" | |
| if [ ! -d "${SOURCE_DIR}" ]; then | |
| echo "Source directory not found: ${SOURCE_DIR}" >&2 | |
| exit 1 | |
| fi | |
| cp -R "${SOURCE_DIR}/." "${TEMP_INPUT_DIR}/" | |
| if [ -n "${RELATIVE_MD_PATH}" ]; then | |
| case "${RELATIVE_MD_PATH}" in | |
| /*|*..*) | |
| echo "relative_md_path must be a relative path under markdown-translator/docs-for-test/en" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| TARGET_FILE="${TEMP_INPUT_DIR}/${RELATIVE_MD_PATH}" | |
| if [ ! -f "${TARGET_FILE}" ]; then | |
| echo "Requested file not found: ${RELATIVE_MD_PATH}" >&2 | |
| exit 1 | |
| fi | |
| case "${TARGET_FILE}" in | |
| *.md) ;; | |
| *) | |
| echo "relative_md_path must point to a .md file" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| find "${TEMP_INPUT_DIR}" -type f -name '*.md' ! -path "${TARGET_FILE}" -delete | |
| fi | |
| rm -rf "${OUTPUT_DIR}" | |
| mkdir -p "${OUTPUT_DIR}" | |
| echo "temp_input_dir=${TEMP_INPUT_DIR}" >> "$GITHUB_OUTPUT" | |
| echo "output_dir=${OUTPUT_DIR}" >> "$GITHUB_OUTPUT" | |
| - name: Run Japanese translation | |
| run: | | |
| set -euo pipefail | |
| node markdown-translator/src/index_ja.js \ | |
| --input-dir "${{ steps.prepare.outputs.temp_input_dir }}" \ | |
| --output-dir "${{ steps.prepare.outputs.output_dir }}" | |
| - name: Show generated files | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if find markdown-translator/docs-for-test/ja -type f -name '*.md' | grep -q .; then | |
| { | |
| echo "## Generated Japanese files" | |
| find markdown-translator/docs-for-test/ja -type f -name '*.md' | sort | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "No translated Markdown files were generated." >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| - name: Upload translated files | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.artifact.outputs.name }} | |
| path: markdown-translator/docs-for-test/ja | |
| if-no-files-found: error |