Fix workflow file movement detection issue
All checks were successful
Auto-Sort Files / auto-sort (push) Successful in 5s

- Replace pipe-based while loop with process substitution to preserve variable scope
- Use temporary file to track FILES_MOVED status across subshells
- Fix issue where files were moved but commit/push steps were skipped
- Use find with -print0 and while read -d '' for proper handling of filenames with spaces
- Ensure FILES_MOVED flag is properly set when files are actually moved
- Now correctly triggers commit and push steps when files are reorganized
This commit is contained in:
2025-08-11 11:16:49 +07:00
parent 6b2cc9e28d
commit 4371c0f201

View File

@@ -25,8 +25,9 @@ jobs:
#!/bin/bash #!/bin/bash
set -e set -e
# Flag to track if any files were moved # Create a temporary file to track if files were moved
FILES_MOVED=false TEMP_FLAG=$(mktemp)
echo "false" > "$TEMP_FLAG"
# Function to move files with logging # Function to move files with logging
move_file() { move_file() {
@@ -41,32 +42,35 @@ jobs:
if [ "$src" != "$dest" ] && [ -f "$src" ]; then if [ "$src" != "$dest" ] && [ -f "$src" ]; then
echo "Moving: $src -> $dest" echo "Moving: $src -> $dest"
mv "$src" "$dest" mv "$src" "$dest"
FILES_MOVED=true echo "true" > "$TEMP_FLAG"
fi fi
} }
# Find and move datasheet files (DS_ prefix) # Find and move datasheet files (DS_ prefix)
echo "Searching for datasheet files with DS_ prefix..." echo "Searching for datasheet files with DS_ prefix..."
find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt" | while read file; do while IFS= read -r -d '' file; do
# Skip files already in docs/datasheets/ # Skip files already in docs/datasheets/
if [[ "$file" != ./docs/datasheets/* ]]; then if [[ "$file" != ./docs/datasheets/* ]]; then
filename=$(basename "$file") filename=$(basename "$file")
move_file "$file" "docs/datasheets/$filename" move_file "$file" "docs/datasheets/$filename"
fi fi
done done < <(find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt" -print0)
# Find and move image files (IMG_ prefix) # Find and move image files (IMG_ prefix)
echo "Searching for image files with IMG_ prefix..." echo "Searching for image files with IMG_ prefix..."
find . -name "IMG_*.png" -o -name "IMG_*.jpg" -o -name "IMG_*.jpeg" -o -name "IMG_*.svg" -o -name "IMG_*.gif" -o -name "IMG_*.pdf" -o -name "IMG_*.webp" | while read file; do while IFS= read -r -d '' file; do
# Skip files already in docs/images/ # Skip files already in docs/images/
if [[ "$file" != ./docs/images/* ]]; then if [[ "$file" != ./docs/images/* ]]; then
filename=$(basename "$file") filename=$(basename "$file")
move_file "$file" "docs/images/$filename" move_file "$file" "docs/images/$filename"
fi fi
done done < <(find . -name "IMG_*.png" -o -name "IMG_*.jpg" -o -name "IMG_*.jpeg" -o -name "IMG_*.svg" -o -name "IMG_*.gif" -o -name "IMG_*.pdf" -o -name "IMG_*.webp" -print0)
# Check if any files were moved # Check if any files were moved
if [ "$FILES_MOVED" = true ]; then FILES_MOVED=$(cat "$TEMP_FLAG")
rm "$TEMP_FLAG"
if [ "$FILES_MOVED" = "true" ]; then
echo "Files were moved. Setting output for commit step." echo "Files were moved. Setting output for commit step."
echo "files_moved=true" >> $GITHUB_OUTPUT echo "files_moved=true" >> $GITHUB_OUTPUT
else else