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
|
||||
set -e
|
||||
|
||||
# Create a temporary file to track if files were moved
|
||||
TEMP_FLAG=$(mktemp)
|
||||
echo "false" > "$TEMP_FLAG"
|
||||
# Flag to track if any files were moved
|
||||
FILES_MOVED=false
|
||||
|
||||
# Function to move files with logging
|
||||
move_file() {
|
||||
@@ -42,35 +41,37 @@ jobs:
|
||||
if [ "$src" != "$dest" ] && [ -f "$src" ]; then
|
||||
echo "Moving: $src -> $dest"
|
||||
mv "$src" "$dest"
|
||||
echo "true" > "$TEMP_FLAG"
|
||||
return 0 # Success - file was moved
|
||||
fi
|
||||
return 1 # No file moved
|
||||
}
|
||||
|
||||
# Find and move datasheet files (DS_ prefix)
|
||||
echo "Searching for datasheet files with DS_ prefix..."
|
||||
while IFS= read -r -d '' file; do
|
||||
# Skip files already in docs/datasheets/
|
||||
if [[ "$file" != ./docs/datasheets/* ]]; then
|
||||
mapfile -t datasheet_files < <(find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt")
|
||||
for file in "${datasheet_files[@]}"; do
|
||||
if [[ -n "$file" && "$file" != ./docs/datasheets/* ]]; then
|
||||
filename=$(basename "$file")
|
||||
move_file "$file" "docs/datasheets/$filename"
|
||||
if move_file "$file" "docs/datasheets/$filename"; then
|
||||
FILES_MOVED=true
|
||||
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)
|
||||
echo "Searching for image files with IMG_ prefix..."
|
||||
while IFS= read -r -d '' file; do
|
||||
# Skip files already in docs/images/
|
||||
if [[ "$file" != ./docs/images/* ]]; then
|
||||
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")
|
||||
for file in "${image_files[@]}"; do
|
||||
if [[ -n "$file" && "$file" != ./docs/images/* ]]; then
|
||||
filename=$(basename "$file")
|
||||
move_file "$file" "docs/images/$filename"
|
||||
if move_file "$file" "docs/images/$filename"; then
|
||||
FILES_MOVED=true
|
||||
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
|
||||
FILES_MOVED=$(cat "$TEMP_FLAG")
|
||||
rm "$TEMP_FLAG"
|
||||
|
||||
if [ "$FILES_MOVED" = "true" ]; then
|
||||
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