Fix workflow file movement detection issue
All checks were successful
Auto-Sort Files / auto-sort (push) Successful in 5s
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:
@@ -25,8 +25,9 @@ jobs:
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Flag to track if any files were moved
|
||||
FILES_MOVED=false
|
||||
# Create a temporary file to track if files were moved
|
||||
TEMP_FLAG=$(mktemp)
|
||||
echo "false" > "$TEMP_FLAG"
|
||||
|
||||
# Function to move files with logging
|
||||
move_file() {
|
||||
@@ -41,32 +42,35 @@ jobs:
|
||||
if [ "$src" != "$dest" ] && [ -f "$src" ]; then
|
||||
echo "Moving: $src -> $dest"
|
||||
mv "$src" "$dest"
|
||||
FILES_MOVED=true
|
||||
echo "true" > "$TEMP_FLAG"
|
||||
fi
|
||||
}
|
||||
|
||||
# Find and move datasheet files (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/
|
||||
if [[ "$file" != ./docs/datasheets/* ]]; then
|
||||
filename=$(basename "$file")
|
||||
move_file "$file" "docs/datasheets/$filename"
|
||||
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)
|
||||
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/
|
||||
if [[ "$file" != ./docs/images/* ]]; then
|
||||
filename=$(basename "$file")
|
||||
move_file "$file" "docs/images/$filename"
|
||||
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
|
||||
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_moved=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user