This project provides a Python script and GitHub Actions workflow for scanning text files in a specified directory for lines matching a given regular expression.
The script.py
file contains a Python script that:
- Takes two command-line arguments:
- A full path to a directory
- A regular expression pattern
- Scans all
.txt
files in the specified directory - Outputs the filename and line number of the first line in each file that matches the regular expression
The .github/workflows/scan_files.yml
file defines a GitHub Actions workflow that:
- Runs on pushes to the main branch or can be manually triggered
- Sets up a Python environment
- Creates a test directory with sample text files
- Runs the scanning script
- Displays the results directly in the GitHub Actions console output
You can manually trigger the workflow from the Actions tab in the GitHub repository. When doing so, you can specify:
- The directory to scan (default: './test_directory')
- The regular expression to use (default: 'example.*pattern')
- Clone this repository
- Ensure
script.py
is in the root directory - Create the
.github/workflows
directory if it doesn't exist - Place the
scan_files.yml
workflow file in the.github/workflows
directory - Push these changes to your GitHub repository
After the workflow runs (either automatically on push or manually triggered):
- Go to the Actions tab in your GitHub repository
- Click on the specific workflow run
- In the workflow run summary, expand the "Run scanner script" step
- The scan results will be visible directly in the log
We can modify the script.py
file to change how files are scanned or results are reported.