-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add code analysis and reporting for testGPT #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
SkySingh04
wants to merge
9
commits into
keploy:main
from
SkySingh04:linting-and-analysis-in-testGPT
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f531607
feat: add code analysis and reporting for multiple languages
SkySingh04 d3fb640
feat: enhance action.yml with GitHub token input and report generation
SkySingh04 fca9d5e
feat: add language detection and code analysis scripts with result pa…
SkySingh04 9fa757a
feat: enhance code analysis scripts to handle changed files and add r…
SkySingh04 5d06e9a
feat: improve linter installation checks in analyze-code.sh
SkySingh04 cab32c0
refactor: streamline script permission grants and enhance result pars…
SkySingh04 2b4dbb1
feat: enhance code analysis and result parsing with logging and direc…
SkySingh04 d12f0ef
fix: improve error messages in parse-results.sh for better clarity
SkySingh04 864896b
feat: exclude common non-source files in language detection script
SkySingh04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Change to the workspace directory | ||
| cd $GITHUB_WORKSPACE/$WORKDIR | ||
|
|
||
| # Ensure analysis-reports directory exists | ||
| mkdir -p analysis-reports | ||
|
|
||
| # Function to find existing linter installations | ||
| find_linter() { | ||
| local linter_name=$1 | ||
| local system_path=$(which $linter_name 2>/dev/null) | ||
| echo $system_path | ||
| } | ||
|
|
||
| # Log message function | ||
| log_message() { | ||
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | ||
| } | ||
|
|
||
| log_message "Starting code analysis" | ||
|
|
||
| for lang in $DETECTED_LANGUAGES; do | ||
| case "$lang" in | ||
| go) | ||
| GO_LINTER=$(find_linter golangci-lint) | ||
| if [ -z "$GO_LINTER" ]; then | ||
| log_message "Installing golangci-lint..." | ||
| go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
| else | ||
| log_message "Using system golangci-lint: $GO_LINTER" | ||
| fi | ||
| ;; | ||
| javascript) | ||
| JS_LINTER=$(find_linter eslint) | ||
| if [ -z "$JS_LINTER" ]; then | ||
| log_message "Installing eslint..." | ||
| npm install -g eslint | ||
| else | ||
| log_message "Using system eslint: $JS_LINTER" | ||
| fi | ||
| ;; | ||
| python) | ||
| PY_LINTER=$(find_linter flake8) | ||
| PY_SECURITY=$(find_linter bandit) | ||
| if [ -z "$PY_LINTER" ]; then | ||
| log_message "Installing flake8..." | ||
| pip install flake8 | ||
| else | ||
| log_message "Using system flake8: $PY_LINTER" | ||
| fi | ||
| if [ -z "$PY_SECURITY" ]; then | ||
| log_message "Installing bandit..." | ||
| pip install bandit | ||
| else | ||
| log_message "Using system bandit: $PY_SECURITY" | ||
| fi | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ -n "$PR_FILES" ]; then | ||
| IFS=',' read -ra FILES <<< "$PR_FILES" | ||
|
|
||
| for lang in $DETECTED_LANGUAGES; do | ||
| case "$lang" in | ||
| go) | ||
| GO_FILES=() | ||
| for file in "${FILES[@]}"; do | ||
| if [[ $file == *.go ]]; then | ||
| GO_FILES+=("$file") | ||
| fi | ||
| done | ||
| if [ ${#GO_FILES[@]} -gt 0 ]; then | ||
| golangci-lint run --out-format=github-actions "${GO_FILES[@]}" > analysis-reports/go-lint.txt 2>&1 || true | ||
| else | ||
| echo "No Go files changed in PR" > analysis-reports/go-lint.txt | ||
| fi | ||
| ;; | ||
| javascript) | ||
| JS_FILES=() | ||
| for file in "${FILES[@]}"; do | ||
| if [[ $file == *.js || $file == *.ts || $file == *.jsx || $file == *.tsx ]]; then | ||
| JS_FILES+=("$file") | ||
| fi | ||
| done | ||
| if [ ${#JS_FILES[@]} -gt 0 ] && ([ -f ".eslintrc.js" ] || [ -f ".eslintrc.json" ] || [ -f ".eslintrc.yml" ]); then | ||
| eslint "${JS_FILES[@]}" --format junit -o analysis-reports/js-lint.xml 2>&1 || true | ||
| else | ||
| echo "No JavaScript/TypeScript files changed in PR or no ESLint config found" > analysis-reports/js-lint.txt | ||
| fi | ||
| ;; | ||
| python) | ||
| PY_FILES=() | ||
| for file in "${FILES[@]}"; do | ||
| if [[ $file == *.py ]]; then | ||
| PY_FILES+=("$file") | ||
| fi | ||
| done | ||
| if [ ${#PY_FILES[@]} -gt 0 ]; then | ||
| flake8 "${PY_FILES[@]}" --output-file=analysis-reports/py-lint.txt 2>&1 || true | ||
| bandit -r "${PY_FILES[@]}" -f txt -o analysis-reports/py-security.txt 2>&1 || true | ||
| else | ||
| echo "No Python files changed in PR" > analysis-reports/py-lint.txt | ||
| fi | ||
| ;; | ||
| esac | ||
| done | ||
| else | ||
| for lang in $DETECTED_LANGUAGES; do | ||
| case "$lang" in | ||
| go) | ||
| golangci-lint run --out-format=github-actions ./... > analysis-reports/go-lint.txt 2>&1 || true | ||
| ;; | ||
| javascript) | ||
| if [ -f ".eslintrc.js" ] || [ -f ".eslintrc.json" ] || [ -f ".eslintrc.yml" ]; then | ||
| eslint . --format junit -o analysis-reports/js-lint.xml 2>&1 || true | ||
| else | ||
| echo "No ESLint config found, skipping JavaScript linting" > analysis-reports/js-lint.txt | ||
| fi | ||
| ;; | ||
| python) | ||
| flake8 . --output-file=analysis-reports/py-lint.txt 2>&1 || true | ||
| bandit -r . -f txt -o analysis-reports/py-security.txt 2>&1 || true | ||
| ;; | ||
| esac | ||
| done | ||
| fi | ||
|
|
||
| temp_file=$(mktemp) | ||
| for report in analysis-reports/*; do | ||
| if [ -f "$report" ]; then | ||
| echo "### $(basename "$report")" >> "$temp_file" | ||
| cat "$report" >> "$temp_file" | ||
| echo -e "\n---\n" >> "$temp_file" | ||
| fi | ||
| done | ||
| mv "$temp_file" analysis-reports/final-report.txt | ||
|
|
||
| log_message "Code analysis completed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/bin/bash | ||
|
|
||
| declare -A extensions=( | ||
| ["go"]="go" | ||
| ["js"]="javascript" | ||
| ["ts"]="javascript" | ||
| ["jsx"]="javascript" | ||
| ["tsx"]="javascript" | ||
| ["py"]="python" | ||
| ["java"]="java" | ||
| ) | ||
|
|
||
| LANGUAGES="" | ||
|
|
||
| # Exclude common non-source files | ||
| while IFS= read -r file; do | ||
| ext="${file##*.}" | ||
|
Hermione2408 marked this conversation as resolved.
|
||
| if [[ -n "${extensions[$ext]}" ]]; then | ||
| LANGUAGES+="${extensions[$ext]} " | ||
| fi | ||
| done < <(find . -type f \ | ||
| -not -path "*/\.*/*" \ | ||
| -not -path "*/node_modules/*" \ | ||
| -not -path "*/dist/*" \ | ||
| -not -path "*/build/*" \ | ||
| -not -path "*/target/*" \ | ||
| -not -path "*/vendor/*" \ | ||
| -not -path "*/__pycache__/*" \ | ||
| -size -1M) | ||
|
|
||
| UNIQUE_LANGS=$(echo "$LANGUAGES" | tr ' ' '\n' | sort -u | tr '\n' ' ') | ||
| echo "languages=$UNIQUE_LANGS" >> $GITHUB_OUTPUT | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
| mkdir -p "${GITHUB_WORKSPACE}/${WORKDIR}" | ||
|
|
||
| ANSI_FILTER="s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" | ||
|
|
||
| if [ ! -f "${GITHUB_WORKSPACE}/${WORKDIR}/report.txt" ]; then | ||
| echo "ERROR: Test report file not found. Please ensure tests were executed correctly." > "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" | ||
| else | ||
|
Hermione2408 marked this conversation as resolved.
|
||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total tests: [0-9]+" "${GITHUB_WORKSPACE}/${WORKDIR}/report.txt" | sed -r "${ANSI_FILTER}" > "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out" | ||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test passed: [0-9]+" "${GITHUB_WORKSPACE}/${WORKDIR}/report.txt" | sed -r "${ANSI_FILTER}" > "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out" | ||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test failed: [0-9]+" "${GITHUB_WORKSPACE}/${WORKDIR}/report.txt" | sed -r "${ANSI_FILTER}" > "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out" | ||
|
|
||
| if [ ! -s "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out" ]; then | ||
| echo "ERROR: No valid test summary found in report file. Please check test execution output format." > "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" | ||
| else | ||
| cat "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out" "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out" "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out" > "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" | ||
| fi | ||
| fi | ||
|
|
||
| echo 'KEPLOY_REPORT<<EOF' >> $GITHUB_OUTPUT | ||
| cat "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" >> $GITHUB_OUTPUT | ||
| echo 'EOF' >> $GITHUB_OUTPUT | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
lets not make the yml file cluttered, encouraging to use shell files for same
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.
Sure Yash! I also took the chance to move the parsing to a new script as well