Skip to content

Commit 99a58da

Browse files
authored
Merge pull request #551 from InnerSourceCommons/review-GHA-for-i18n-consistency-check
Review GHA for i18n consistency check
2 parents cd3156e + 9f24d5f commit 99a58da

File tree

1 file changed

+54
-69
lines changed

1 file changed

+54
-69
lines changed
Lines changed: 54 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: i18n check consistency and notify on GitHub Issues
1+
# -------------------------
2+
# To add a new language, do the following:
3+
# - add the 2-letter language code in matrix.language
4+
# - add the flag and language name that you want to use at the beginning of the #check-consistency step
5+
# -------------------------
6+
name: i18n Consistency Check
27

38
on:
4-
pull_request:
5-
branches:
6-
- master
7-
paths:
8-
- .github/workflows/i18n-consistency-check.yml
99
schedule:
10-
- cron: '0 0 1 * *'
10+
- cron: '0 0 1 * *' # run at midnight, on day 1 of the month
1111
workflow_dispatch:
1212

1313
jobs:
@@ -17,82 +17,66 @@ jobs:
1717
matrix:
1818
language: [ja, zh]
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
2121
with:
2222
fetch-depth: '0'
23-
- name: Check consistency
23+
- name: Check consistency and create issue
2424
id: check-consistency
2525
run: |
26-
# Set the issue header
27-
issue="\
28-
# i18n Contents Consistency Issue\\n\
29-
\\n\
30-
The following files may have consistency issues with the English version. Please check and update the files.\\n\
31-
\\n\
32-
This issue is created when there is an update to content/en. It compares the git update history to let you know what updates are overdue. The issue should be closed when the update is complete.\\n"
33-
34-
for file in $(find patterns/2-structured -name '*.md'); do
35-
36-
# Get the translated file name and check if it exists
37-
i18n_filename=$(echo "$file" | sed 's/patterns\/2-structured/translation\/${{matrix.language}}\/patterns/g')
26+
# Declare the flags
27+
declare -A flags=( ["ja"]=":jp: Japanese" ["zh"]=":cn: Chinese")
28+
29+
issue_title="${flags['${{matrix.language}}']}: Content Consistency Issue"
30+
31+
# Heredoc for issue header
32+
cat <<- EOM > issue.md
33+
# i18n Contents Consistency Issue
34+
35+
The following files may have consistency issues with the English version. Please check and update the files.
36+
37+
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.
38+
EOM
39+
40+
# Loop through all files in the English directory
41+
for file in $(find patterns/{2-structured,3-validated} -name '*.md'); do
42+
[[ $file =~ "3-validated" ]] && continue # if the file is under 3-validated, skip (one liner) - 2023/08/26
43+
i18n_filename=$(echo "$file" | sed "s/patterns\/\(2-structured\|3-validated\)/translation\/${{matrix.language}}\/patterns/g")
44+
3845
if [[ ! -e "$i18n_filename" ]]; then
39-
continue
46+
continue
4047
fi
41-
echo $file
42-
echo $i18n_filename
43-
# Loop through all the files in the English directory
44-
# Get the last updated date of the original file and the translated file
45-
original_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $file)" +%s)
48+
49+
original_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $file)" +%s)
4650
i18n_content_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $i18n_filename)" +%s)
47-
48-
# print the last updated date of the original file and the translated file
49-
50-
# Check if the translated file is updated after the original file
51-
if [[ $(($original_updated_at - $i18n_content_updated_at)) -ge 1 ]]; then
52-
# Get the title of the content
53-
content_header=$(echo "$(cat "$file")" | grep -E '^title+' | sort -r | head -n1)
51+
52+
if [[ $((original_updated_at - i18n_content_updated_at)) -ge 1 ]]; then
53+
content_header=$(grep -E '^title+' "$file" | sort -r | head -n1)
5454
content_title=$(echo "$content_header" | sed 's/title: //g')
55-
56-
# Get the days since the translated file is overdue
57-
days_since_overdue_updates=$(($(( $(date +%s) - $original_updated_at))/ 60 / 60 / 24))
58-
# Get the diff between the original file and the translated file
55+
56+
content_title=$(awk '/## Title/{flag=1; next} /##/{flag=0; exit} flag{printf "%s", $0}' "$file")
57+
days_since_overdue_updates=$(( ($(date +%s) - original_updated_at) / 60 / 60 / 24 ))
5958
original_last_update_hash=$(git log -1 --format=%H $file)
60-
# Get the parent hash of the original last update hash
6159
parent_hash=$(git log -1 --format=%P $original_last_update_hash)
62-
# Get the diff between the original file and the translated file
63-
64-
result=$(echo "$(git diff ${parent_hash} HEAD $file)" | sed '1,4 s/^/# /')
65-
echo -e "$result"
60+
result=$(git diff "${parent_hash}" HEAD "$file" | sed '1,4 s/^/# /')
61+
62+
# Append to the issue.md file
63+
cat <<- EOM >> issue.md
64+
<details><summary><b>$content_title</b> ($file)</summary>
6665
67-
# Add the contents to the issue.md file
68-
issue+="<details><summary><b>$content_title</b> ($file)</summary>\\n\\n"
69-
issue+="- Original File(en): [$file](https://github.com/$GITHUB_REPOSITORY/blob/master/$file)\\n"
70-
issue+="- Translated File(${{matrix.language}}): [$i18n_filename](https://github.com/$GITHUB_REPOSITORY/blob/master/$i18n_filename)\\n"
71-
issue+="- [Diff on GitHub](https://github.com/yuhattor/innersourcecommons.org/compare/$i18n_last_update_hash...$original_last_update_hash)\\n"
72-
issue+="- Days since overdue updates: $days_since_overdue_updates days\\n"
73-
issue+="\`\`\`diff\\n"
74-
issue+="$result"
75-
issue+="\\n\`\`\`\\n"
76-
issue+="</details>\\n"
77-
echo -e "$issue" >> issue.md
78-
issue=""
66+
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.
67+
68+
\`\`\`diff
69+
$result
70+
\`\`\`
71+
</details>
72+
EOM
7973
fi
8074
done
81-
- name: Create Issue
82-
run: |
83-
# Declare the flags
84-
declare -A flags=(
85-
["ja"]="🇯🇵 Japanese"
86-
["zh"]="🇨🇳 Chinese"
87-
)
88-
89-
# Set the issue title
90-
issue_title="${flags[${{matrix.language}}]}: Content Consistency Issue"
91-
75+
9276
# Get the existing issue ID
93-
existing_issue_id=$(gh issue list -S "state:open type:issue title:$issue_title" | cut -f1)
94-
95-
# If the issue.md file exists, create a new issue or comment on the existing issue
77+
existing_issue_id=$(gh issue list -S "is:issue is:open $issue_title" | cut -f1)
78+
echo "existing_issue_id: $existing_issue_id"
79+
# Create a new issue or comment on the existing one
9680
if [ -f issue.md ]; then
9781
if expr "$existing_issue_id" : '^[0-9]*$' >/dev/null; then
9882
gh issue comment "$existing_issue_id" -F issue.md -R $GITHUB_REPOSITORY
@@ -102,3 +86,4 @@ jobs:
10286
fi
10387
env:
10488
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+

0 commit comments

Comments
 (0)