-
Notifications
You must be signed in to change notification settings - Fork 3
137 lines (113 loc) · 4.34 KB
/
test-ja-translation.yml
File metadata and controls
137 lines (113 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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