Skip to content

Commit ece0257

Browse files
authored
Move one-line po-files detector to a script file (#2515)
1 parent cfb2984 commit ece0257

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

Diff for: .github/workflows/pull-translation.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v2
2020
with:
2121
token: "${{ secrets.TARANTOOLBOT_TOKEN }}"
22-
fetch-depth: 2
22+
fetch-depth: 0
2323

2424
- name: Set branch name from source branch
2525
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
@@ -47,15 +47,20 @@ jobs:
4747
run: make cleanup-po
4848

4949
- name: Set $CHANGED_POS for changed .rst files only
50-
run: echo "CHANGED_POS=$(echo "$(git diff --name-only | grep .po | sed "s/.po//" | sed "s/locale\/ru\/LC_MESSAGES\///")" | awk -v rst="$(git diff-tree --no-commit-id --name-only -r HEAD | grep .rst | tr "\n" " ")" 'rst ~ $0{ print "locale/ru/LC_MESSAGES/"$0".po" }')" >> $GITHUB_ENV
50+
shell: bash
51+
run: |
52+
set -x
53+
. list_changed_po.sh
54+
if [ -z "${CHANGED_POS}" ]; then exit 1; fi
55+
echo "CHANGED_POS=${CHANGED_POS}" >> $GITHUB_ENV
5156
if: ${{github.event.inputs.commit_po_for_unchanged_rst == 'false'}}
5257

5358
- name: Set $CHANGED_POS for all .rst files
54-
run: echo "CHANGED_POS=.po" >> $GITHUB_ENV
59+
run: echo "CHANGED_POS=*.po" >> $GITHUB_ENV
5560
if: ${{github.event.inputs.commit_po_for_unchanged_rst != 'false'}}
5661

5762
- name: Commit translation files
58-
uses: stefanzweifel/git-auto-commit-action@v4.1.2
63+
uses: stefanzweifel/git-auto-commit-action@v4.12.0
5964
with:
6065
commit_message: "Update translations"
6166
file_pattern: "${{ env.CHANGED_POS }}"

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ locale/**/*.mo
77
_*_build/
88
deploy_key
99
.venv
10+
venv
1011
output
1112
*.pyc
1213
_theme/tarantool/static/design.css.map

Diff for: list_changed_po.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
# The root directory of .po files
4+
locale_path=locale/ru/LC_MESSAGES/
5+
6+
ESCAPED_REPLACE=$(printf '%s\n' "$locale_path" | sed -e 's/[\/&]/\\&/g')
7+
8+
unset CHANGED_POS
9+
10+
get_git_diff () {
11+
echo "$(git diff --name-only ; git ls-files . --exclude-standard --others)"
12+
}
13+
14+
get_changed_po () {
15+
changed_po_files="$(get_git_diff | grep \\.po)"
16+
if [ -z "${changed_po_files}" ]; then
17+
echo "ERROR: changed .po files not found"
18+
return
19+
fi
20+
echo "$(get_git_diff | grep \\.po)"
21+
}
22+
23+
get_po_base_names () {
24+
echo "$(get_changed_po | sed "s/.po//" | sed "s/$ESCAPED_REPLACE//")"
25+
}
26+
27+
get_rst_from_diff () {
28+
echo $(git diff-tree --no-commit-id --name-only -r HEAD..origin/latest | grep .rst)
29+
}
30+
31+
echo "* Getting changed .po files:"
32+
changed_po="$(get_changed_po)"
33+
echo $changed_po
34+
35+
echo
36+
echo "* Getting a list of .rst files to compare with changed .po files:"
37+
rst_from_diff=$(get_rst_from_diff)
38+
echo $rst_from_diff
39+
40+
echo
41+
echo "* Filtering corresponding .po files to the changed .rst in the closest commit:"
42+
po_files_to_commit=$(get_po_base_names | awk -v rst="$rst_from_diff" -v locale_path=$locale_path 'rst ~ $0{ printf locale_path; print ""$0".po" }')
43+
echo $po_files_to_commit
44+
45+
if [ -n "${po_files_to_commit}" ]; then
46+
export CHANGED_POS="$(echo $po_files_to_commit | tr "\n" " ")"
47+
else
48+
echo "ERROR: could not find any matched po file to commit"
49+
fi

0 commit comments

Comments
 (0)