GitHub Action
Filename Inspector
- Description
- How It Works
- Inputs
- Outputs
- Usage Example
- How To Build
- Running Unit Tests
- Code Coverage
- Run Action Locally
- Contributing
- License
The Filename Inspector GitHub Action is designed to ensure naming conventions in project files within specified repository directories. It scans for project files and reports any missing specified file name patterns, helping maintain consistency and adherence to project standards. The tool is not limited to any programming language files; it scans file names and ignores extensions until they are used in filters.
This action scans the specified paths
for project files and checks if their file names fit the name_patterns.
It reports the count of files not meeting the naming conventions, with options to fail the action if violations are found.
- Description: List of file name patterns that project files should fit, separated by commas. Supports fnmatch pattern.
- Required: Yes
- Example:
*UnitTest.*,*IntegrationTest.*
- Description: List of paths to include in the scan, separated by commas. Supports the glob pattern.
- Required: Yes
- Example:
**/src/test/java/**,**/src/test/scala/**/*.txt
- Description: List of filenames to exclude from name-pattern checks, separated by commas. Support fnmatch pattern.
- Required: No
- Default: ``
- Description: Specifies the format of the output report. Options include console, csv, and json.
- Required: No
- Default:
console
- Options:
console
: Prints the list of violated files to the console.csv
: Generates a CSV file with the report. No printout of violated files to the console, unless verbose is enabled. Path to the report file is provided in thereport-path
output.json
: Generates a JSON file with the report. No printout of violated files to the console, unless verbose is enabled. Path to the report file is provided in thereport-path
output.
- Description: Enable verbose logging to provide detailed output during the action’s execution, aiding in troubleshooting and setup.
- Required: No
- Default:
false
- Note: If workflow run in debug mode, 'verbose-logging' is set to 'true.'
- Description: Set to true to fail the action if any convention violations are detected. Set false to continue without failure.
- Required: No
- Default:
false
- Description: Count of files not complying with the specified file name patterns.
- Description: Path to the generated report file. Not used if the
report-format
is set toconsole
.
name: Check Project Files Naming Conventions
on: [push]
jobs:
check_naming:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Filename Inspector Default
id: scan-test-files
uses: AbsaOSS/[email protected]
with:
name-patterns: '*UnitTest.*,*IntegrationTest.*'
paths: '**/src/test/java/**,**/src/test/scala/**'
name: Check Project Files Naming Conventions
on: [push]
jobs:
check_naming:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Filename Inspector Full Custom
id: scan-test-files
uses: AbsaOSS/[email protected]
with:
name-patterns: |
*UnitTest.*,
*IntegrationTest.*
paths: |
**/src/test/java/**,
**/src/test/scala/**
excludes: |
src/exclude_dir/*.py,
tests/exclude_file.py
report-format: 'console'
verbose-logging: 'false'
fail-on-violation: 'false'
Clone the repository and navigate to the project directory:
git clone https://github.com/AbsaOSS/filename-inspector.git
cd filename-inspector
Install the dependencies:
pip install -r requirements.txt
Unit tests are written using pytest. To run the tests, use the following command:
pytest
This will execute all tests located in the tests directory and generate a code coverage report.
Code coverage is collected using pytest-cov coverage tool. To run the tests and collect coverage information, use the following command:
pytest --cov=src --cov-report html tests/
See the coverage report on the path:
htmlcov/index.html
Create *.sh file and place it in the project root.
#!/bin/bash
# Set environment variables based on the action inputs
export INPUT_NAME_PATTERNS="*UnitTest.*,*IntegrationTest.*"
export INPUT_PATHS="**/src/test/java/**,**/src/test/scala/**"
export INPUT_EXCLUDES="src/exclude_dir/*.py,tests/exclude_file.py"
export INPUT_REPORT_FORMAT="console"
export INPUT_VERBOSE_LOGGING="true"
export INPUT_FAIL_ON_VIOLATION="false"
# Run the Python script
python3 ./src/filename_inspector.py
Feel free to submit issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.