65
65
LOCALES=$(find . -maxdepth 1 -type d | grep -v "^.$" | grep -v "/en$" | sed 's|^\./||')
66
66
echo "Available translation locales: $LOCALES"
67
67
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
68
77
69
78
- name : Process file renames and deletions
70
79
if : steps.check_branch.outputs.branch_exists == 'false'
75
84
# Get list of deleted files from git status
76
85
DELETES=$(git status --porcelain | grep -E "^D[[:space:]]+apps/docs/content/en/docs" | sed 's/^D[[:space:]]*//')
77
86
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
+
78
91
# Process renames
79
92
if [ -n "$RENAMES" ]; then
80
93
echo "File renames detected in English docs. Processing for other languages..."
@@ -89,6 +102,15 @@ jobs:
89
102
SOURCE=$(echo "$LINE" | awk '{print $1}')
90
103
DEST=$(echo "$LINE" | awk '{print $2}')
91
104
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
+
92
114
# Replace 'en' with current locale in paths
93
115
SOURCE_LOCALE=${SOURCE/content\/en/content\/$LOCALE}
94
116
DEST_LOCALE=${DEST/content\/en/content\/$LOCALE}
@@ -98,8 +120,23 @@ jobs:
98
120
echo "Renaming $SOURCE_LOCALE to $DEST_LOCALE"
99
121
# Create directory if it doesn't exist
100
122
mkdir -p $(dirname "$DEST_LOCALE")
123
+
101
124
# Move the file
102
125
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
103
140
fi
104
141
done
105
142
done
@@ -142,7 +179,7 @@ jobs:
142
179
if : steps.check_branch.outputs.branch_exists == 'false'
143
180
id : check_changes
144
181
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
146
183
echo "has_changes=true" >> $GITHUB_OUTPUT
147
184
echo "Changes detected. Will proceed with PR."
148
185
else
@@ -166,4 +203,4 @@ jobs:
166
203
delete-branch : true
167
204
base : main
168
205
add-paths : |
169
- apps/docs/content/*/docs
206
+ apps/docs/content/
0 commit comments