-
Notifications
You must be signed in to change notification settings - Fork 0
ci: Update coverage script to use 'tests' directory and simplify exec… #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @ipv1337, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request aims to update the coverage script to use the 'tests' directory directly and simplify the execution process. The primary change involves modifying the script to directly target the 'tests' directory for test execution and removing the logic that attempts to locate the test directory in various locations. This change streamlines the test execution process and ensures that the script fails if the 'tests' directory is not found, providing clearer error messages and preventing the CI from continuing with potentially incorrect test configurations.
Highlights
- Test Directory Handling: The script now directly uses the 'tests' directory and exits if it's not found, simplifying the previous logic that searched for the directory in multiple locations.
- Simplified Test Execution: The test execution is simplified by running all tests within the 'tests' directory in a single pytest command, removing the need to define and run test groups individually.
- Error Handling: The script now exits with an error code if the main test directory is missing, ensuring that CI pipelines fail fast and provide clear error messages.
Changelog
- scripts/run_coverage_ci.sh
- Modified the script to directly use the 'tests' directory for test execution.
- Removed the logic that attempts to locate the test directory in various locations.
- Added a check to ensure that the 'tests' directory exists and exit if it's not found.
- Simplified the test execution by running all tests within the 'tests' directory in a single pytest command.
- Removed the individual test group execution logic.
- Updated the pytest command to use 'src/cli_code' for coverage.
- Added a check for pytest run failure and timeout, and provide appropriate warnings.
- Added a final summary of the test run, including failed and timed out tests.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A test directory's plight,
To be found and run just right,
No more searching far,
Just where tests are,
Ensuring code shines bright.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request updates the coverage script to use the 'tests' directory and simplifies execution. The changes look good overall, but there are a few areas that could be improved for clarity and error handling.
Summary of Findings
- Error Handling: The script now exits if the test directory is not found, which is good. However, consider adding more specific error messages or logging to help diagnose issues.
- Simplification: The removal of the complex logic for finding the test directory makes the script more straightforward. However, ensure that the assumption of a 'tests' directory is valid for all use cases.
- Timeout Handling: The script now includes timeout handling, which is good. However, consider adding more specific error messages or logging to help diagnose issues.
Merge Readiness
The changes in this pull request improve the reliability and maintainability of the coverage script. However, I recommend addressing the comments to enhance error handling and ensure the script is robust. I am unable to approve this pull request, and users should have others review and approve this code before merging.
| if [ ! -d "$TEST_DIR" ]; then | ||
| echo "Warning: Test directory $TEST_DIR not found in current directory" | ||
|
|
||
| # Try parent directory | ||
| if [ -d "../$TEST_DIR" ]; then | ||
| TEST_DIR="../$TEST_DIR" | ||
| echo "Found test directory in parent directory: $TEST_DIR" | ||
| # Try in GitHub workspace | ||
| elif [ -n "$GITHUB_WORKSPACE" ] && [ -d "$GITHUB_WORKSPACE/$TEST_DIR" ]; then | ||
| TEST_DIR="$GITHUB_WORKSPACE/$TEST_DIR" | ||
| echo "Found test directory in GITHUB_WORKSPACE: $TEST_DIR" | ||
| # Use find to locate test directory | ||
| else | ||
| TEST_DIR_FOUND=$(find . -type d -name "test_dir" | head -1) | ||
| if [ -n "$TEST_DIR_FOUND" ]; then | ||
| TEST_DIR="$TEST_DIR_FOUND" | ||
| echo "Found test directory using find: $TEST_DIR" | ||
| else | ||
| echo "Error: Could not find test directory" | ||
| echo "Current directory: $(pwd)" | ||
| echo "Available directories:" | ||
| ls -la | ||
| # Continue anyway to avoid failing the CI | ||
| # We'll handle individual files not found later | ||
| fi | ||
| fi | ||
| echo "Error: Test directory '$TEST_DIR' not found!" | ||
| echo "Current directory: $(pwd)" | ||
| echo "Available directories:" | ||
| ls -la | ||
| exit 1 # Fail the script if the main test directory is missing | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a more descriptive error message that includes potential causes for the missing directory (e.g., incorrect working directory, missing setup step).
| if [ ! -d "$TEST_DIR" ]; then | |
| echo "Warning: Test directory $TEST_DIR not found in current directory" | |
| # Try parent directory | |
| if [ -d "../$TEST_DIR" ]; then | |
| TEST_DIR="../$TEST_DIR" | |
| echo "Found test directory in parent directory: $TEST_DIR" | |
| # Try in GitHub workspace | |
| elif [ -n "$GITHUB_WORKSPACE" ] && [ -d "$GITHUB_WORKSPACE/$TEST_DIR" ]; then | |
| TEST_DIR="$GITHUB_WORKSPACE/$TEST_DIR" | |
| echo "Found test directory in GITHUB_WORKSPACE: $TEST_DIR" | |
| # Use find to locate test directory | |
| else | |
| TEST_DIR_FOUND=$(find . -type d -name "test_dir" | head -1) | |
| if [ -n "$TEST_DIR_FOUND" ]; then | |
| TEST_DIR="$TEST_DIR_FOUND" | |
| echo "Found test directory using find: $TEST_DIR" | |
| else | |
| echo "Error: Could not find test directory" | |
| echo "Current directory: $(pwd)" | |
| echo "Available directories:" | |
| ls -la | |
| # Continue anyway to avoid failing the CI | |
| # We'll handle individual files not found later | |
| fi | |
| fi | |
| echo "Error: Test directory '$TEST_DIR' not found!" | |
| echo "Current directory: $(pwd)" | |
| echo "Available directories:" | |
| ls -la | |
| exit 1 # Fail the script if the main test directory is missing | |
| fi | |
| if [ ! -d "$TEST_DIR" ]; then | |
| echo "Error: Test directory '$TEST_DIR' not found! This could be due to an incorrect working directory or a missing setup step." | |
| echo "Current directory: $(pwd)" | |
| echo "Available directories:" | |
| ls -la | |
| exit 1 # Fail the script if the main test directory is missing | |
| fi |
| EXIT_CODE=$? | ||
|
|
||
| # Print summary of test results | ||
| echo "" | tee -a "$SUMMARY_LOG" | ||
| echo "Test Summary:" | tee -a "$SUMMARY_LOG" | ||
| echo "-------------" | tee -a "$SUMMARY_LOG" | ||
| echo "Failed tests: $FAILED_TESTS" | tee -a "$SUMMARY_LOG" | ||
| echo "Timed out tests: $TIMED_OUT_TESTS" | tee -a "$SUMMARY_LOG" | ||
| echo "Log files available in: $LOG_DIR" | tee -a "$SUMMARY_LOG" | ||
| echo "Summary log: $SUMMARY_LOG" | tee -a "$SUMMARY_LOG" | ||
|
|
||
| # Extract overall coverage percentage for GitHub output | ||
| if [ -f "coverage.xml" ]; then | ||
| echo "✅ coverage.xml file exists" | tee -a "$SUMMARY_LOG" | ||
|
|
||
| # Extract overall coverage percentage | ||
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))") | ||
| echo "Overall coverage percentage: $COVERAGE" | tee -a "$SUMMARY_LOG" | ||
|
|
||
| # Set output for GitHub Actions | ||
| if [ -n "$GITHUB_OUTPUT" ]; then | ||
| echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | ||
| if [ $EXIT_CODE -ne 0 ]; then | ||
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" | ||
| if [ $EXIT_CODE -eq 124 ]; then | ||
| echo "⚠️ WARNING: Pytest run TIMED OUT (after $CI_TIMEOUT seconds)" | tee -a "$SUMMARY_LOG" | ||
| TIMED_OUT_TESTS=1 | ||
| FAILED_TESTS=0 # Treat timeout as a special case, not necessarily failed tests | ||
| else | ||
| echo "Note: GITHUB_OUTPUT not defined, skipping GitHub output" | tee -a "$SUMMARY_LOG" | ||
| echo "⚠️ WARNING: Pytest run FAILED with exit code $EXIT_CODE" | tee -a "$SUMMARY_LOG" | ||
| FAILED_TESTS=1 | ||
| TIMED_OUT_TESTS=0 | ||
| fi | ||
| echo "Check logs in $LOG_DIR for details." | tee -a "$SUMMARY_LOG" | ||
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding logging or more descriptive output to indicate whether the pytest run timed out or failed due to other reasons. This can help in debugging CI failures.
| EXIT_CODE=$? | |
| # Print summary of test results | |
| echo "" | tee -a "$SUMMARY_LOG" | |
| echo "Test Summary:" | tee -a "$SUMMARY_LOG" | |
| echo "-------------" | tee -a "$SUMMARY_LOG" | |
| echo "Failed tests: $FAILED_TESTS" | tee -a "$SUMMARY_LOG" | |
| echo "Timed out tests: $TIMED_OUT_TESTS" | tee -a "$SUMMARY_LOG" | |
| echo "Log files available in: $LOG_DIR" | tee -a "$SUMMARY_LOG" | |
| echo "Summary log: $SUMMARY_LOG" | tee -a "$SUMMARY_LOG" | |
| # Extract overall coverage percentage for GitHub output | |
| if [ -f "coverage.xml" ]; then | |
| echo "✅ coverage.xml file exists" | tee -a "$SUMMARY_LOG" | |
| # Extract overall coverage percentage | |
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))") | |
| echo "Overall coverage percentage: $COVERAGE" | tee -a "$SUMMARY_LOG" | |
| # Set output for GitHub Actions | |
| if [ -n "$GITHUB_OUTPUT" ]; then | |
| echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" | |
| if [ $EXIT_CODE -eq 124 ]; then | |
| echo "⚠️ WARNING: Pytest run TIMED OUT (after $CI_TIMEOUT seconds)" | tee -a "$SUMMARY_LOG" | |
| TIMED_OUT_TESTS=1 | |
| FAILED_TESTS=0 # Treat timeout as a special case, not necessarily failed tests | |
| else | |
| echo "Note: GITHUB_OUTPUT not defined, skipping GitHub output" | tee -a "$SUMMARY_LOG" | |
| echo "⚠️ WARNING: Pytest run FAILED with exit code $EXIT_CODE" | tee -a "$SUMMARY_LOG" | |
| FAILED_TESTS=1 | |
| TIMED_OUT_TESTS=0 | |
| fi | |
| echo "Check logs in $LOG_DIR for details." | tee -a "$SUMMARY_LOG" | |
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" | |
| if [ $EXIT_CODE -eq 124 ]; then | |
| echo "⚠️ WARNING: Pytest run TIMED OUT (after $CI_TIMEOUT seconds)" | tee -a "$SUMMARY_LOG" | |
| TIMED_OUT_TESTS=1 | |
| FAILED_TESTS=0 # Treat timeout as a special case, not necessarily failed tests | |
| else | |
| echo "⚠️ WARNING: Pytest run FAILED with exit code $EXIT_CODE" | tee -a "$SUMMARY_LOG" | |
| FAILED_TESTS=1 | |
| TIMED_OUT_TESTS=0 | |
| fi | |
| echo "Check logs in $LOG_DIR for details." | tee -a "$SUMMARY_LOG" | |
| echo "----------------------------------------" | tee -a "$SUMMARY_LOG" | |
| else |
| if [ $FAILED_TESTS -gt 0 ] && [ "$CI_EXIT_ON_TEST_FAILURE" = "1" ]; then | ||
| echo "Exiting with failure code due to test failures." | ||
| exit 1 | ||
| elif [ $TIMED_OUT_TESTS -gt 0 ]; then | ||
| echo "Exiting with failure code due to test timeouts." | ||
| exit 1 # Or a different code if desired for timeouts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a different exit code for timeouts to differentiate them from other test failures. This can be useful for monitoring and alerting purposes.
| if [ $FAILED_TESTS -gt 0 ] && [ "$CI_EXIT_ON_TEST_FAILURE" = "1" ]; then | |
| echo "Exiting with failure code due to test failures." | |
| exit 1 | |
| elif [ $TIMED_OUT_TESTS -gt 0 ]; then | |
| echo "Exiting with failure code due to test timeouts." | |
| exit 1 # Or a different code if desired for timeouts | |
| if [ $FAILED_TESTS -gt 0 ] && [ "$CI_EXIT_ON_TEST_FAILURE" = "1" ]; then | |
| echo "Exiting with failure code due to test failures." | |
| exit 1 | |
| elif [ $TIMED_OUT_TESTS -gt 0 ]; then | |
| echo "Exiting with failure code due to test timeouts." | |
| exit 2 # Or a different code if desired for timeouts | |
| fi |
Code Coverage Report📊 Current Coverage: 19.02% Detailed coverage analysis is available in SonarCloud Coverage Change DetailsThis shows code coverage for changes in this PR. To improve coverage, consider adding tests for new or modified code. |
Code Coverage Report📊 Current Coverage: 19.02% Detailed coverage analysis is available in SonarCloud Coverage Change DetailsThis shows code coverage for changes in this PR. To improve coverage, consider adding tests for new or modified code. |
|



…ution