From aeb9a316793daae4d692a17244d72e49e02a9b25 Mon Sep 17 00:00:00 2001 From: Ben King <9087625+benfdking@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:38:45 +0000 Subject: [PATCH] ci: add unparsable check in fixtures --- .github/workflows/pr.yaml | 7 ++++ .hacking/scripts/check_for_unparsable.sh | 45 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 .hacking/scripts/check_for_unparsable.sh diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5e70a4766..1b40777a6 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -177,3 +177,10 @@ jobs: python-version: ${{ matrix.python-version }} - run: make python_install - run: make ci + check-no-unparsable: + name: Check no unparsable files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: chmod +x ./.hacking/scripts/check_for_unparsable.sh + - run: ./.hacking/scripts/check_for_unparsable.sh diff --git a/.hacking/scripts/check_for_unparsable.sh b/.hacking/scripts/check_for_unparsable.sh new file mode 100755 index 000000000..d6022805a --- /dev/null +++ b/.hacking/scripts/check_for_unparsable.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Usage: +# ./check_pattern.sh "your_grep_pattern" [file1 file2 file3 ...] +# +# Examples: +# # Use the default directory if no files are provided +# ./check_pattern.sh "unparsable:" +# +# # Provide explicit files or directories +# ./check_pattern.sh "error|fail" logs/*.log +# +# Exit codes: +# 0 - Pattern NOT found in any file +# 1 - Pattern found in at least one file + +pattern="unparsable:" +shift # Shift so $@ now contains only filenames (if any) + +# If no files are specified, default to looking in crates/lib-dialects/test/fixtures/dialects/***/*.yml +if [[ $# -eq 0 ]]; then + set -- crates/lib-dialects/test/fixtures/dialects/**\/*.yml +fi + +found=0 +files_found=() + +for filename in "$@"; do + # Use extended regular expressions (-E). -q ensures grep is quiet (no output). + if grep -qE "$pattern" "$filename" 2>/dev/null; then + found=1 + files_found+=("$filename") + fi +done + +# If found in any file, list them +if [[ $found -eq 1 ]]; then + echo "Pattern '$pattern' found in:" + for file in "${files_found[@]}"; do + echo " $file" + done +fi + +# Exit with 1 if found, otherwise 0 +exit $found \ No newline at end of file