awesome-chatgpt-prompts/.github/workflows/csv_linter.yml

77 lines
2.4 KiB
YAML
Raw Permalink Normal View History

2022-12-18 22:38:40 +00:00
name: CSV Linter and Trailing Whitespaces
on:
push:
pull_request:
jobs:
lint_and_check_trailing_whitespaces:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
2025-01-05 20:16:26 +00:00
2022-12-18 22:38:40 +00:00
- name: Set up Python
uses: actions/setup-python@v2
with:
2025-01-05 20:16:26 +00:00
python-version: '3.8'
2022-12-18 22:38:40 +00:00
- name: Install dependencies
run: |
2025-01-05 20:16:26 +00:00
python -m pip install --upgrade pip
2022-12-18 22:38:40 +00:00
python -m pip install csvkit
2025-01-05 20:16:26 +00:00
- name: Validate CSV structure
2022-12-18 22:38:40 +00:00
run: |
2025-01-05 20:16:26 +00:00
echo "Checking CSV structure..."
if ! csvclean -n prompts.csv 2>&1 | tee /tmp/csv_errors.log; then
echo "::error::CSV validation failed"
cat /tmp/csv_errors.log
2022-12-18 22:38:40 +00:00
exit 1
fi
2025-01-05 20:16:26 +00:00
- name: Check CSV format
run: |
echo "Checking CSV format..."
if ! python -c '
import csv
with open("prompts.csv", "r", encoding="utf-8") as f:
reader = csv.reader(f)
headers = next(reader)
if headers != ["act", "prompt"]:
print("Error: CSV headers must be exactly [act, prompt]")
exit(1)
for row_num, row in enumerate(reader, 2):
if len(row) != 2:
print(f"Error: Row {row_num} has {len(row)} columns, expected 2")
exit(1)
if not row[0] or not row[1]:
print(f"Error: Row {row_num} has empty values")
exit(1)
'; then
echo "::error::CSV format check failed"
exit 1
fi
2022-12-18 22:38:40 +00:00
- name: Check Trailing Whitespaces
run: |
2025-01-05 20:16:26 +00:00
echo "Checking for trailing whitespaces..."
if grep -q "[[:space:]]$" prompts.csv; then
echo "::error::Found trailing whitespaces in prompts.csv"
grep -n "[[:space:]]$" prompts.csv | while read -r line; do
echo "Line with trailing whitespace: $line"
done
exit 1
fi
echo "No trailing whitespaces found"
- name: Check for UTF-8 BOM and line endings
run: |
echo "Checking for UTF-8 BOM and line endings..."
if file prompts.csv | grep -q "with BOM"; then
echo "::error::File contains UTF-8 BOM marker"
exit 1
fi
if file prompts.csv | grep -q "CRLF"; then
echo "::error::File contains Windows-style (CRLF) line endings"
2022-12-18 22:38:40 +00:00
exit 1
fi