Skip to content
Closed
52 changes: 52 additions & 0 deletions .github/workflows/pr-check-naming-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Test File Naming Check"

on:
pull_request:
types: [opened, reopened, edited, synchronize]

permissions:
contents: read

concurrency:
group: test-name-check-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test-file-naming:
name: Test File Naming Check (pull request)
runs-on: ubuntu-latest

steps:
- name: Harden the runner
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8

- name: Validate test filename convention
shell: bash
run: |
echo "🔍 Checking for invalid test filenames..."

invalid_files=$(
find tests -type f -name "*.py" \
! -name "*_test.py" \
! -path "tests/__init__.py" \
! -path "tests/unit/__init__.py" \
! -path "tests/unit/conftest.py" \
! -path "tests/unit/mock_server.py" \
! -path "tests/integration/__init__.py" \
! -path "tests/integration/utils_for_test.py" \
| sort || true
)

if [ -n "$invalid_files" ]; then
echo "❌ Invalid filenames detected (must end with _test.py):"
echo "$invalid_files"
echo
exit 1
fi

echo "✅ All test filenames follow the convention (*_test.py)."
8 changes: 2 additions & 6 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,24 @@ jobs:

echo "Checking files changed in PR #${PR_NUMBER}..."

# List files in the PR and check for CHANGELOG.md (root or any path ending with /CHANGELOG.md)
FILES_JSON="$(gh api repos/${{ github.repository }}/pulls/${PR_NUMBER}/files --paginate)"
if ! echo "${FILES_JSON}" | jq -e '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i"))' >/dev/null; then
echo "FAIL: CHANGELOG.md was not changed in this PR."
exit 1
fi

# Ensure there is at least one line-level change (+ or -) in the patch for CHANGELOG.md
PATCH_CONTENT="$(echo "${FILES_JSON}" \
| jq -r '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i")) | .patch // empty')"

# If no patch is returned (very large file or API omission), treat presence as sufficient
if [[ -z "${PATCH_CONTENT}" ]]; then
echo "CHANGELOG.md modified (no patch provided by API). Passing."
echo "CHANGELOG.md modified (patch omitted). Passing."
exit 0
fi

# Look for actual line changes (exclude diff headers +++/---)
if echo "${PATCH_CONTENT}" | awk '{print $0}' | grep -E '^[+-]' | grep -vE '^\+\+\+|^\-\-\-' >/dev/null; then
echo "PASS: CHANGELOG.md contains line-level changes."
exit 0
else
echo "FAIL: No line-level changes detected in CHANGELOG.md."
exit 1
fi
fi
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.


### Added

- CI: Add standalone workflow `pr-check-naming-test.yml` to enforce test naming rules:
- Unit tests must be named `test_*.py`
- Integration tests must be named `*_test.py`
- Excludes helper files: `__init__.py`, `conftest.py`, `mock_server.py`, `utils_for_test.py`

### Changed

Expand Down
Loading