Skip to content

Commit 410105d

Browse files
committed
feat: update translation files meta if there is only rename
1 parent f5ab2d8 commit 410105d

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

.github/workflows/update-en-docs.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ jobs:
6565
LOCALES=$(find . -maxdepth 1 -type d | grep -v "^.$" | grep -v "/en$" | sed 's|^\./||')
6666
echo "Available translation locales: $LOCALES"
6767
echo "locales=$LOCALES" >> $GITHUB_OUTPUT
68+
69+
- name: Stage changes to detect renames
70+
if: steps.check_branch.outputs.branch_exists == 'false'
71+
run: |
72+
# Stage all changes so Git can detect renames
73+
git add .
74+
# Show what Git sees after staging
75+
echo "Git status after staging:"
76+
git status --porcelain
6877
6978
- name: Process file renames and deletions
7079
if: steps.check_branch.outputs.branch_exists == 'false'
@@ -75,6 +84,10 @@ jobs:
7584
# Get list of deleted files from git status
7685
DELETES=$(git status --porcelain | grep -E "^D[[:space:]]+apps/docs/content/en/docs" | sed 's/^D[[:space:]]*//')
7786
87+
# Generate current timestamp in ISO format
88+
CURRENT_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
89+
echo "Current timestamp: $CURRENT_TIMESTAMP"
90+
7891
# Process renames
7992
if [ -n "$RENAMES" ]; then
8093
echo "File renames detected in English docs. Processing for other languages..."
@@ -89,6 +102,15 @@ jobs:
89102
SOURCE=$(echo "$LINE" | awk '{print $1}')
90103
DEST=$(echo "$LINE" | awk '{print $2}')
91104
105+
# Check if there are actual content changes using git diff
106+
# --numstat gives us numeric stats: added lines, removed lines, filename
107+
# If the file was only renamed with no content changes, it will show 0 0
108+
GIT_DIFF=$(git diff --cached --numstat "$SOURCE" "$DEST")
109+
ADDED_LINES=$(echo "$GIT_DIFF" | awk '{print $1}')
110+
REMOVED_LINES=$(echo "$GIT_DIFF" | awk '{print $2}')
111+
112+
echo "Git diff for $SOURCE → $DEST: $ADDED_LINES lines added, $REMOVED_LINES lines removed"
113+
92114
# Replace 'en' with current locale in paths
93115
SOURCE_LOCALE=${SOURCE/content\/en/content\/$LOCALE}
94116
DEST_LOCALE=${DEST/content\/en/content\/$LOCALE}
@@ -98,8 +120,23 @@ jobs:
98120
echo "Renaming $SOURCE_LOCALE to $DEST_LOCALE"
99121
# Create directory if it doesn't exist
100122
mkdir -p $(dirname "$DEST_LOCALE")
123+
101124
# Move the file
102125
mv "$SOURCE_LOCALE" "$DEST_LOCALE"
126+
127+
# If the content is identical (just a rename, not a modification)
128+
# then update the timestamps in the translation file
129+
# Git diff showing 0 added and 0 removed lines means identical content
130+
if [ "$ADDED_LINES" = "0" ] && [ "$REMOVED_LINES" = "0" ]; then
131+
echo "Content unchanged, updating timestamps in $DEST_LOCALE"
132+
133+
# Update source-updated-at and translation-updated-at in the file
134+
# Using portable sed syntax that works on both Linux and macOS
135+
perl -i -pe "s/source-updated-at: .*/source-updated-at: '$CURRENT_TIMESTAMP'/" "$DEST_LOCALE"
136+
perl -i -pe "s/translation-updated-at: .*/translation-updated-at: '$CURRENT_TIMESTAMP'/" "$DEST_LOCALE"
137+
else
138+
echo "Content changed, keeping original timestamps for translation to detect changes"
139+
fi
103140
fi
104141
done
105142
done
@@ -142,7 +179,7 @@ jobs:
142179
if: steps.check_branch.outputs.branch_exists == 'false'
143180
id: check_changes
144181
run: |
145-
if [[ $(git status --porcelain | grep -E "apps/docs/content/.*/docs" | wc -l) -gt 0 ]]; then
182+
if [[ $(git status --porcelain | grep -E "apps/docs/content/" | wc -l) -gt 0 ]]; then
146183
echo "has_changes=true" >> $GITHUB_OUTPUT
147184
echo "Changes detected. Will proceed with PR."
148185
else
@@ -166,4 +203,4 @@ jobs:
166203
delete-branch: true
167204
base: main
168205
add-paths: |
169-
apps/docs/content/*/docs
206+
apps/docs/content/

0 commit comments

Comments
 (0)