From 7e75737a09cffc9564cf6cf1a639b55ce1c96b7c Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 6 Mar 2025 09:32:57 -0800 Subject: [PATCH] feat: add test for duplicate triggers (#1) ### Explanation _No response_ ### Issue _No response_ ### Attestations - [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [x] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [x] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [x] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Reviewed-on: https://git.nhcarrigan.com/nhcarrigan/espanso/pulls/1 Co-authored-by: Naomi Carrigan Co-committed-by: Naomi Carrigan --- .gitea/workflows/ci.yml | 19 ++++++++++++++ test.sh | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100755 test.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..59ac926 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,19 @@ +name: CI +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + name: Validate YAML + + steps: + - name: Checkout Source Files + uses: actions/checkout@v4 + + - name: Run Tests + run: ./test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..688549a --- /dev/null +++ b/test.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Directory containing YAML files +MATCH_DIR="match" + +# Check if directory exists +if [ ! -d "$MATCH_DIR" ]; then + echo "Error: Directory '$MATCH_DIR' not found!" + exit 1 +fi + +# Temporary file to store all triggers +ALL_TRIGGERS=$(mktemp) + +# Find all YAML files and extract triggers +echo "Scanning YAML files in $MATCH_DIR directory..." +for file in "$MATCH_DIR"/*.y*ml; do + if [ -f "$file" ]; then + echo "Processing file: $(basename "$file")" + # Extract triggers using grep and sed + # This looks for lines with "trigger:" and captures the value + grep -E '^\s*-\s*trigger:' "$file" | sed 's/.*trigger:\s*"\([^"]*\)".*/\1/' >> "$ALL_TRIGGERS" + fi +done + +# Check if we found any triggers +if [ ! -s "$ALL_TRIGGERS" ]; then + echo "No triggers found in YAML files. Check file format or directory." + rm "$ALL_TRIGGERS" + exit 1 +fi + +# Sort triggers and find duplicates +echo -e "\nChecking for duplicate triggers..." +DUPLICATES=$(sort "$ALL_TRIGGERS" | uniq -d) + +# Display results +if [ -z "$DUPLICATES" ]; then + echo "Success: All triggers are unique!" + TOTAL=$(wc -l < "$ALL_TRIGGERS") + echo "Total number of triggers found: $TOTAL" +else + echo "Error: Duplicate triggers found:" + echo "$DUPLICATES" + + # Optional: Show which files contain each duplicate + echo -e "\nDuplicates found in these files:" + for dupe in $DUPLICATES; do + echo "Trigger \"$dupe\" found in:" + grep -l "trigger: \"$dupe\"" "$MATCH_DIR"/*.y*ml + done +fi + +# Clean up +rm "$ALL_TRIGGERS"