|
1 | 1 | #!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# ====================================================================================================================================================== |
| 5 | +# @file: pr-check-test-files.sh |
| 6 | +# |
| 7 | +# @Description A CI check written in bash that enforces the '_test.py' suffix to ensure Pytest can automatically discover |
| 8 | +# new or renamed test files in a Pull Request. |
| 9 | +# |
| 10 | +# @logic: |
| 11 | +# 1. Identifies files as (A) Added, (R) Renamed, or (C) Copied using 'git diff' to check |
| 12 | +# relevant filename ($file1 for added files, $file2 for renamed/copied files). |
| 13 | +# 2. Validates paths against allowed test directories (unit/integration). |
| 14 | +# 3. Excludes specific utility (ex., conftest.py, utils.py) and non-Python files. |
| 15 | +# 4. Parses tab-separated Git output via IFS=$'\t' to ensure robust filename handling. |
| 16 | +# 5. Routes files using case statement based on git status |
| 17 | +# |
| 18 | +# @types: |
| 19 | +# - String: Used for file paths and git status codes. |
| 20 | +# - Array: Used for 'TEST_DIRS', 'EXCEPTION_NAMES', and accumulating errors. |
| 21 | +# |
| 22 | +# @Parameters: |
| 23 | +# - None: This script does not accept CLI arguments. It derives the input from the current Git state compared against origin/main. |
| 24 | +# |
| 25 | +# @Dependencies: |
| 26 | +# - Git: (for diff) |
| 27 | +# - Bash: (runs the script) |
| 28 | +# - Pytest: (naming standard) |
| 29 | +# |
| 30 | +# @Permissions: |
| 31 | +# - Requires Execute permissions (chmod +x) to run. Also needs Read access to the git repository to perform the diff. |
| 32 | +# |
| 33 | +# @Return |
| 34 | +# - 0: All test files follow the naming standard. |
| 35 | +# - 1: Exits with status 1 and outputs error messages in red. |
| 36 | +# Includes a yellow instructional block providing reason why the file failed. |
| 37 | +# ====================================================================================================================================================== |
| 38 | + |
2 | 39 | RED="\033[31m" |
3 | 40 | YELLOW="\033[33m" |
4 | 41 | RESET="\033[0m" |
|
0 commit comments