2025-03-05 09:36:25 +07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Check if required arguments are provided
|
2025-03-08 10:05:07 +07:00
|
|
|
if [ $# -lt 3 ] || [ $# -gt 4 ]; then
|
|
|
|
echo "Usage: $0 <input_file> <root_folder> <output_yaml_file> [list_branch]"
|
|
|
|
echo "Example: $0 exclude_list.txt /path/to/git/repo /path/to/output.yaml 'branch1 branch2'"
|
2025-03-05 09:36:25 +07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
INPUT_FILE="$1"
|
|
|
|
ROOT_FOLDER="$2"
|
|
|
|
OUTPUT_FILE="$3"
|
2025-03-08 10:05:07 +07:00
|
|
|
LIST_BRANCH="$4"
|
2025-03-05 09:36:25 +07:00
|
|
|
|
|
|
|
# Check if input file exists
|
|
|
|
if [ ! -f "$INPUT_FILE" ]; then
|
|
|
|
echo "Error: Input file '$INPUT_FILE' not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if root folder exists
|
|
|
|
if [ ! -d "$ROOT_FOLDER" ]; then
|
|
|
|
echo "Error: Root folder '$ROOT_FOLDER' not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if output YAML file exists, if not create it
|
|
|
|
if [ ! -f "$OUTPUT_FILE" ]; then
|
|
|
|
echo "Output file does not exist. Creating $OUTPUT_FILE"
|
|
|
|
touch "$OUTPUT_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Change to root folder
|
|
|
|
cd "$ROOT_FOLDER" || exit 1
|
|
|
|
|
|
|
|
# Initialize output file
|
|
|
|
echo "branches:" > "$OUTPUT_FILE"
|
|
|
|
|
|
|
|
# Get all git branches
|
|
|
|
git fetch --all
|
2025-03-08 10:05:07 +07:00
|
|
|
if [ -z "$LIST_BRANCH" ]; then
|
|
|
|
branches=$(git branch -r | grep -v HEAD | sed 's/origin\///' | sed 's/^[[:space:]]*//')
|
|
|
|
else
|
|
|
|
branches=$LIST_BRANCH
|
|
|
|
fi
|
2025-03-05 09:36:25 +07:00
|
|
|
|
|
|
|
# Process each branch
|
2025-03-08 10:05:07 +07:00
|
|
|
for branch in $branches; do
|
2025-03-05 09:36:25 +07:00
|
|
|
echo "Processing branch: $branch"
|
|
|
|
|
|
|
|
# Checkout branch
|
|
|
|
git checkout "$branch" 2>/dev/null || continue
|
|
|
|
|
|
|
|
# Get all folders in current branch
|
|
|
|
folders=$(find . -maxdepth 1 -type d -not -path '.' -not -path './.*' | sed 's|./||')
|
|
|
|
|
|
|
|
# Array to store modules not in input file
|
|
|
|
modules=()
|
|
|
|
|
|
|
|
# Check each folder against input file
|
|
|
|
while IFS= read -r folder; do
|
|
|
|
# Skip if folder is empty
|
|
|
|
[ -z "$folder" ] && continue
|
|
|
|
|
|
|
|
# Check if folder is in input file
|
|
|
|
if ! grep -Fxq "$folder" "$INPUT_FILE"; then
|
|
|
|
modules+=("$folder")
|
|
|
|
fi
|
|
|
|
done <<< "$folders"
|
|
|
|
|
|
|
|
# Write to yaml if there are modules
|
|
|
|
if [ ${#modules[@]} -gt 0 ]; then
|
|
|
|
echo " $branch:" >> "$OUTPUT_FILE"
|
|
|
|
echo " modules:" >> "$OUTPUT_FILE"
|
|
|
|
for module in "${modules[@]}"; do
|
|
|
|
echo " - $module" >> "$OUTPUT_FILE"
|
|
|
|
done
|
|
|
|
fi
|
2025-03-08 10:05:07 +07:00
|
|
|
|
|
|
|
done
|
2025-03-05 09:36:25 +07:00
|
|
|
|
|
|
|
echo "Output written to $OUTPUT_FILE"
|