feat: test for duplicate replace values
CI / Validate YAML (push) Successful in 5s

This commit is contained in:
2025-08-06 10:17:37 -07:00
parent 238753f3ea
commit 6944c10fea
+34 -4
View File
@@ -11,6 +11,7 @@ fi
# Temporary file to store all triggers # Temporary file to store all triggers
ALL_TRIGGERS=$(mktemp) ALL_TRIGGERS=$(mktemp)
ALL_REPLACES=$(mktemp)
# Find all YAML files and extract triggers # Find all YAML files and extract triggers
echo "Scanning YAML files in $MATCH_DIR directory..." echo "Scanning YAML files in $MATCH_DIR directory..."
@@ -20,6 +21,11 @@ for file in "$MATCH_DIR"/*.y*ml; do
# Extract triggers using grep and sed # Extract triggers using grep and sed
# This looks for lines with "trigger:" and captures the value # This looks for lines with "trigger:" and captures the value
grep -E '^\s*-\s*trigger:' "$file" | sed 's/.*trigger:\s*"\([^"]*\)".*/\1/' >> "$ALL_TRIGGERS" grep -E '^\s*-\s*trigger:' "$file" | sed 's/.*trigger:\s*"\([^"]*\)".*/\1/' >> "$ALL_TRIGGERS"
# Also extract replace values if they exist
grep -E '^\s*replace:' "$file" | sed 's/.*replace:\s*"\([^"]*\)".*/\1/' >> "$ALL_REPLACES"
else
echo "Warning: No YAML files found in $MATCH_DIR directory!"
continue
fi fi
done done
@@ -32,28 +38,51 @@ fi
# Sort triggers and find duplicates # Sort triggers and find duplicates
echo -e "\nChecking for duplicate triggers..." echo -e "\nChecking for duplicate triggers..."
DUPLICATES=$(sort "$ALL_TRIGGERS" | uniq -d) DUPLICATE_TRIGGERS=$(sort "$ALL_TRIGGERS" | uniq -d)
# Display results # Display results
if [ -z "$DUPLICATES" ]; then if [ -z "$DUPLICATE_TRIGGERS" ]; then
echo "Success: All triggers are unique!" echo "Success: All triggers are unique!"
TOTAL=$(wc -l < "$ALL_TRIGGERS") TOTAL=$(wc -l < "$ALL_TRIGGERS")
echo "Total number of triggers found: $TOTAL" echo "Total number of triggers found: $TOTAL"
else else
echo "Error: Duplicate triggers found:" echo "Error: Duplicate triggers found:"
echo "$DUPLICATES" echo "$DUPLICATE_TRIGGERS"
# Optional: Show which files contain each duplicate # Optional: Show which files contain each duplicate
echo -e "\nDuplicates found in these files:" echo -e "\nDuplicates found in these files:"
for dupe in $DUPLICATES; do for dupe in $DUPLICATE_TRIGGERS; do
echo "Trigger \"$dupe\" found in:" echo "Trigger \"$dupe\" found in:"
grep -l "trigger: \"$dupe\"" "$MATCH_DIR"/*.y*ml grep -l "trigger: \"$dupe\"" "$MATCH_DIR"/*.y*ml
done done
exit 1 exit 1
fi fi
# Sort replace values and find duplicates
echo -e "\nChecking for duplicate replace values..."
DUPLICATE_REPLACES=$(sort "$ALL_REPLACES" | uniq -d)
# Display results
if [ -z "$DUPLICATE_REPLACES" ]; then
echo "Success: All replace values are unique!"
TOTAL_REPLACES=$(wc -l < "$ALL_REPLACES")
echo "Total number of replace values found: $TOTAL_REPLACES"
else
echo "Error: Duplicate replace values found:"
echo "$DUPLICATE_REPLACES"
# Optional: Show which files contain each duplicate replace value
echo -e "\nDuplicates found in these files:"
for dupe in $DUPLICATE_REPLACES; do
echo "Replace value \"$dupe\" found in:"
grep -l "replace: \"$dupe\"" "$MATCH_DIR"/*.y*ml
done
exit 1
fi
# Clean up # Clean up
rm "$ALL_TRIGGERS" rm "$ALL_TRIGGERS"
rm "$ALL_REPLACES"
### Now we test that all gifs.yml replace values match "c.tenor.com". ### Now we test that all gifs.yml replace values match "c.tenor.com".
@@ -86,6 +115,7 @@ if [ -z "$INVALID_REPLACE" ]; then
else else
echo "Error: Invalid replace values found in gifs.yml:" echo "Error: Invalid replace values found in gifs.yml:"
echo "$INVALID_REPLACE" echo "$INVALID_REPLACE"
exit 1
fi fi
# This must always be the final line, so that CI can detect success. If you want to exit with a failure, do so at the conditional point. # This must always be the final line, so that CI can detect success. If you want to exit with a failure, do so at the conditional point.