Skip to content

Commit 52de30f

Browse files
committed
feat: update translation files if there are renames or deletions under en folder
1 parent e17e86f commit 52de30f

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

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

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,92 @@ jobs:
5757
rsync -av --delete nextjs-v13/docs/ apps/docs/content/en/docs/13/
5858
rm -rf nextjs-v13
5959
60+
- name: Find available translation locales
61+
if: steps.check_branch.outputs.branch_exists == 'false'
62+
id: find_locales
63+
run: |
64+
cd apps/docs/content
65+
LOCALES=$(find . -maxdepth 1 -type d | grep -v "^.$" | grep -v "/en$" | sed 's|^\./||')
66+
echo "Available translation locales: $LOCALES"
67+
echo "locales=$LOCALES" >> $GITHUB_OUTPUT
68+
69+
- name: Process file renames and deletions
70+
if: steps.check_branch.outputs.branch_exists == 'false'
71+
run: |
72+
# Get list of renamed files from git status
73+
RENAMES=$(git status --porcelain | grep -E "^R[[:space:]]+apps/docs/content/en/docs" | sed 's/^R[[:space:]]*//')
74+
75+
# Get list of deleted files from git status
76+
DELETES=$(git status --porcelain | grep -E "^D[[:space:]]+apps/docs/content/en/docs" | sed 's/^D[[:space:]]*//')
77+
78+
# Process renames
79+
if [ -n "$RENAMES" ]; then
80+
echo "File renames detected in English docs. Processing for other languages..."
81+
82+
# For each locale
83+
for LOCALE in ${{ steps.find_locales.outputs.locales }}; do
84+
echo "Processing renames for locale: $LOCALE"
85+
86+
# For each renamed file
87+
echo "$RENAMES" | while read -r LINE; do
88+
# Split the line into source and destination
89+
SOURCE=$(echo "$LINE" | awk '{print $1}')
90+
DEST=$(echo "$LINE" | awk '{print $2}')
91+
92+
# Replace 'en' with current locale in paths
93+
SOURCE_LOCALE=${SOURCE/content\/en/content\/$LOCALE}
94+
DEST_LOCALE=${DEST/content\/en/content\/$LOCALE}
95+
96+
# Check if source file exists in this locale
97+
if [ -f "$SOURCE_LOCALE" ]; then
98+
echo "Renaming $SOURCE_LOCALE to $DEST_LOCALE"
99+
# Create directory if it doesn't exist
100+
mkdir -p $(dirname "$DEST_LOCALE")
101+
# Move the file
102+
mv "$SOURCE_LOCALE" "$DEST_LOCALE"
103+
fi
104+
done
105+
done
106+
else
107+
echo "No file renames detected in English docs."
108+
fi
109+
110+
# Process deletions
111+
if [ -n "$DELETES" ]; then
112+
echo "File deletions detected in English docs. Processing for other languages..."
113+
114+
# For each locale
115+
for LOCALE in ${{ steps.find_locales.outputs.locales }}; do
116+
echo "Processing deletions for locale: $LOCALE"
117+
118+
# For each deleted file
119+
echo "$DELETES" | while read -r FILE; do
120+
# Replace 'en' with current locale in paths
121+
FILE_LOCALE=${FILE/content\/en/content\/$LOCALE}
122+
123+
# Check if file exists in this locale
124+
if [ -f "$FILE_LOCALE" ]; then
125+
echo "Deleting $FILE_LOCALE"
126+
rm -f "$FILE_LOCALE"
127+
128+
# Check if parent directory is empty and remove it if it is
129+
DIR=$(dirname "$FILE_LOCALE")
130+
if [ -d "$DIR" ] && [ -z "$(ls -A $DIR)" ]; then
131+
echo "Removing empty directory: $DIR"
132+
rmdir "$DIR"
133+
fi
134+
fi
135+
done
136+
done
137+
else
138+
echo "No file deletions detected in English docs."
139+
fi
140+
60141
- name: Check for modifications
61142
if: steps.check_branch.outputs.branch_exists == 'false'
62143
id: check_changes
63144
run: |
64-
if [[ $(git status --porcelain | grep -E "apps/docs/content/en/docs" | wc -l) -gt 0 ]]; then
145+
if [[ $(git status --porcelain | grep -E "apps/docs/content/.*/docs" | wc -l) -gt 0 ]]; then
65146
echo "has_changes=true" >> $GITHUB_OUTPUT
66147
echo "Changes detected. Will proceed with PR."
67148
else
@@ -85,4 +166,4 @@ jobs:
85166
delete-branch: true
86167
base: main
87168
add-paths: |
88-
apps/docs/content/en/docs
169+
apps/docs/content/*/docs

0 commit comments

Comments
 (0)