Skip to content

Commit 7d90757

Browse files
committed
update .github/workflows/i18n-check.yml
1 parent 2cd0524 commit 7d90757

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

.github/workflows/i18n-check.yml

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,30 @@ jobs:
1212
runs-on: ubuntu-latest
1313
env:
1414
LOCALES: "zh-cn en zh-hant"
15-
GITHUB_EVENT_NAME: ${{ github.event_name }}
16-
GITHUB_BASE_REF: ${{ github.event.pull_request.base.ref || '' }}
17-
GITHUB_BEFORE: ${{ github.event.before || '' }}
18-
GITHUB_SHA: ${{ github.sha }}
1915
steps:
2016
- name: Checkout code
2117
uses: actions/checkout@v4
2218
with:
2319
fetch-depth: 0
2420

2521
- name: Validate added localized markdown files
22+
shell: bash
2623
run: |
2724
set -euo pipefail
2825
echo "Locales: $LOCALES"
29-
# compute diff range
26+
3027
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
31-
if [ -z "${GITHUB_BASE_REF}" ]; then
32-
echo "GITHUB_BASE_REF is empty for this pull_request event. Exiting."
33-
exit 1
34-
fi
35-
echo "PR event, base ref: ${GITHUB_BASE_REF}"
36-
git fetch origin "${GITHUB_BASE_REF}" --quiet || true
37-
DIFF_RANGE="origin/${GITHUB_BASE_REF}...HEAD"
28+
BASE_REF="${{ github.event.pull_request.base.ref }}"
29+
echo "PR event, base ref: ${BASE_REF}"
30+
git fetch origin "${BASE_REF}" --quiet || true
31+
DIFF_RANGE="origin/${BASE_REF}...HEAD"
3832
else
3933
echo "Push event"
40-
if [ -z "${GITHUB_BEFORE}" ] || [ -z "${GITHUB_SHA}" ]; then
41-
echo "Missing before/sha info for push event. Exiting."
42-
exit 1
43-
fi
44-
DIFF_RANGE="${GITHUB_BEFORE}..${GITHUB_SHA}"
34+
DIFF_RANGE="${GITHUB_SHA}^..${GITHUB_SHA}"
4535
fi
4636
echo "Diff range: $DIFF_RANGE"
4737
48-
# Get list of added files (status A)
4938
mapfile -t ADDED < <(git diff --name-status $DIFF_RANGE | awk '$1=="A" {print $2}')
50-
5139
if [ ${#ADDED[@]} -eq 0 ]; then
5240
echo "No added files in this range. Nothing to check."
5341
exit 0
@@ -56,17 +44,14 @@ jobs:
5644
echo "Added files:"
5745
printf ' - %s\n' "${ADDED[@]}"
5846
59-
# Build map: key = relative path under locale (e.g. "guide/foo.md"), value = list of locales added for that key
6047
declare -A seen
6148
IFS=' ' read -r -a LOCALES_ARR <<< "$LOCALES"
6249
ERR=0
6350
6451
for f in "${ADDED[@]}"; do
65-
# only consider markdown files under the 3 locale dirs
6652
if [[ "$f" =~ ^(zh-cn|en|zh-hant)/.+\.md$ ]]; then
6753
locale="${f%%/*}"
6854
name="${f#*/}"
69-
# trim possible leading ./
7055
name="${name#./}"
7156
seen["$name"]="${seen["$name"]} ${locale}"
7257
fi
@@ -77,18 +62,16 @@ jobs:
7762
exit 0
7863
fi
7964
80-
echo "Checking that for each new localized file all locales are added in this same commit/PR..."
8165
for key in "${!seen[@]}"; do
8266
present="${seen[$key]}"
83-
# normalize to array
8467
read -r -a present_arr <<< "$present"
8568
missing=()
8669
for loc in "${LOCALES_ARR[@]}"; do
8770
found=false
8871
for p in "${present_arr[@]}"; do
8972
if [ "$p" = "$loc" ]; then found=true; break; fi
9073
done
91-
if ! $found; then missing+=("$loc"); fi
74+
if ! $found; then missing+=( "$loc" ); fi
9275
done
9376
if [ ${#missing[@]} -ne 0 ]; then
9477
echo "ERROR: New file '$key' added in locales:${present} but missing in locales: ${missing[*]}"
@@ -101,8 +84,6 @@ jobs:
10184
if [ "$ERR" -ne 0 ]; then
10285
echo ""
10386
echo "One or more localized md files are missing their counterparts. Please add the missing files in the same commit/PR."
104-
echo ""
105-
echo "Expected for each new file under zh-cn/en/zh-hant to have the same relative path and filename."
10687
exit 1
10788
fi
10889

0 commit comments

Comments
 (0)