-
Notifications
You must be signed in to change notification settings - Fork 183
127 lines (103 loc) · 5.64 KB
/
i18n-consistency-checker.yaml
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
# -------------------------
# To add a new language, do the following:
# - add the 2-letter language code in matrix.language
# - add the flag and language name that you want to use at the beginning of the #check-consistency step
# -------------------------
name: i18n Consistency Check
on:
schedule:
- cron: '0 0 1 * *' # run at midnight, on day 1 of the month
workflow_dispatch:
jobs:
consistency-check:
runs-on: ubuntu-latest
strategy:
matrix:
language: [ja, zh, pt-br, gl]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Check consistency
id: check-consistency
run: |
# Declare the flags
declare -A flags=( ["ja"]=":jp: Japanese" ["zh"]=":cn: Chinese" ["pt-br"]=":brazil: Brazilian Portuguese" ["gl"]="Galician" )
# Loop through all files in the English directory
for file in $(find patterns/{2-structured,3-validated} -name '*.md'); do
echo "Original file: $file"
#[[ $file =~ "3-validated" ]] && continue # if the file is under 3-validated, skip (one liner) - 2023/08/26
#[[ $file =~ "/templates" ]] && continue # if the file is under /templates, skip. consistency check does not work for that yet.
if [[ $file =~ "/templates" ]]; then
i18n_filename=$(echo "$file" | sed -E "s_patterns/(2-structured|3-validated)/templates_translation/${{matrix.language}}/templates_g")
else
i18n_filename=$(echo "$file" | sed -E "s_patterns/(2-structured|3-validated)_translation/${{matrix.language}}/patterns_g")
fi
echo "Translation file: $i18n_filename"
if [[ ! -e "$i18n_filename" ]]; then
echo "NOT TRANSLATED"
cat <<- EOM >> issue.md
<details><summary><b>New File</b> ($file)</summary>
For more information, please compare [the original file(en)](https://github.com/$GITHUB_REPOSITORY/blob/master/$file).
</details>
EOM
continue
fi
original_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $file)" +%s)
i18n_content_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $i18n_filename)" +%s)
if [[ $((original_updated_at - i18n_content_updated_at)) -ge 1 ]]; then
echo "WARNING"
content_header=$(grep -E '^title+' "$file" | sort -r | head -n1)
content_title=$(echo "$content_header" | sed 's/title: //g')
content_title=$(awk '/## Title/{flag=1; next} /##/{flag=0; exit} flag{printf "%s", $0}' "$file")
days_since_overdue_updates=$(( ($(date +%s) - original_updated_at) / 60 / 60 / 24 ))
original_last_update_hash=$(git log -1 --format=%H $file)
parent_hash=$(git log -1 --format=%P $original_last_update_hash)
result=$(git diff "${parent_hash}" HEAD "$file" | sed '1,4 s/^/# /')
# Append to the issue.md file
cat <<- EOM >> issue.md
<details><summary><b>$content_title</b> ($file)</summary>
For more information, please compare [the original file(en)](https://github.com/$GITHUB_REPOSITORY/blob/master/$file) with [the translated file](https://github.com/$GITHUB_REPOSITORY/blob/master/$i18n_filename). You can view [the differences](https://github.com/$GITHUB_REPOSITORY/compare/$i18n_last_update_hash...$original_last_update_hash) on GitHub. The number of days since overdue updates is **$days_since_overdue_updates** days.
\`\`\`diff
$result
\`\`\`
</details>
EOM
else
echo "CHECK"
fi
done
- name: Check issue.md existence
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "issue.md"
- name: Create issue
if: steps.check_files.outputs.files_exists == 'true'
run: |
# Declare the flags
declare -A flags=( ["ja"]=":jp: Japanese" ["zh"]=":cn: Chinese" ["pt-br"]=":brazil: Brazilian Portuguese" ["gl"]="Galician" )
# Heredoc for issue header
cat <<- EOM > issue-full.md
# i18n Contents Consistency Issue
The following files may have consistency issues with the English version. Please check and update the files.
This issue is created when any of the English patterns have changed (in folder `patterns/`). It compares the git update history to let you know what updates are overdue. The issue should be closed when the update is complete.
EOM
# combine header and rest of file created in previous steps
cat issue.md >> issue-full.md
# title of the GitHub issue to look for
issue_title="${flags['${{matrix.language}}']}: Content Consistency Issue"
# Get the existing issue ID
search_query="is:issue is:open in:title \"$issue_title\""
echo "search_query: $search_query"
existing_issue_id=$(gh issue list -L 1 -S "$search_query" | cut -f1)
echo "existing_issue_id: $existing_issue_id"
cat issue-full.md
# Create a new issue or comment on the existing one
#if expr "$existing_issue_id" : '^[0-9]*$' >/dev/null; then
# gh issue comment "$existing_issue_id" -F issue-full.md -R $GITHUB_REPOSITORY
#else
# gh issue create -t "$issue_title" -F issue-full.md -R $GITHUB_REPOSITORY -l "Type - Translation"
#fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}