Fix file detection issue in workflow
Some checks failed
Auto-Sort Files / auto-sort (push) Failing after 5s
Some checks failed
Auto-Sort Files / auto-sort (push) Failing after 5s
- Replace process substitution with mapfile array approach for better compatibility - Use mapfile -t to read find results into arrays - Simplify file processing with standard for loops - Fix issue where files weren't being detected properly - Use function return codes to track file movement status - Ensure FILES_MOVED flag is set correctly when files are actually moved - More reliable file detection and processing across different bash versions
This commit is contained in:
@@ -25,9 +25,8 @@ jobs:
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Create a temporary file to track if files were moved
|
# Flag to track if any files were moved
|
||||||
TEMP_FLAG=$(mktemp)
|
FILES_MOVED=false
|
||||||
echo "false" > "$TEMP_FLAG"
|
|
||||||
|
|
||||||
# Function to move files with logging
|
# Function to move files with logging
|
||||||
move_file() {
|
move_file() {
|
||||||
@@ -42,35 +41,37 @@ 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"
|
||||||
echo "true" > "$TEMP_FLAG"
|
return 0 # Success - file was moved
|
||||||
fi
|
fi
|
||||||
|
return 1 # No file moved
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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..."
|
||||||
while IFS= read -r -d '' file; do
|
mapfile -t datasheet_files < <(find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt")
|
||||||
# Skip files already in docs/datasheets/
|
for file in "${datasheet_files[@]}"; do
|
||||||
if [[ "$file" != ./docs/datasheets/* ]]; then
|
if [[ -n "$file" && "$file" != ./docs/datasheets/* ]]; then
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
move_file "$file" "docs/datasheets/$filename"
|
if move_file "$file" "docs/datasheets/$filename"; then
|
||||||
|
FILES_MOVED=true
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done < <(find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt" -print0)
|
done
|
||||||
|
|
||||||
# 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..."
|
||||||
while IFS= read -r -d '' file; do
|
mapfile -t image_files < <(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")
|
||||||
# Skip files already in docs/images/
|
for file in "${image_files[@]}"; do
|
||||||
if [[ "$file" != ./docs/images/* ]]; then
|
if [[ -n "$file" && "$file" != ./docs/images/* ]]; then
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
move_file "$file" "docs/images/$filename"
|
if move_file "$file" "docs/images/$filename"; then
|
||||||
|
FILES_MOVED=true
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
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)
|
done
|
||||||
|
|
||||||
# Check if any files were moved
|
# Check if any files were moved
|
||||||
FILES_MOVED=$(cat "$TEMP_FLAG")
|
if [ "$FILES_MOVED" = true ]; then
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user