Skip to content

#64 - Introduce the pylint into project #65

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

Merged
merged 17 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions .github/workflows/build.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,48 @@
# limitations under the License.
#

name: Build and Test
name: Test
on:
pull_request:
branches:
- '**'
types: [ opened, synchronize, reopened ]

jobs:
test:
name: Test
static-code-analysis:
runs-on: ubuntu-latest
name: Pylint Static Code Analysis
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Analyze code with Pylint
id: analyze-code
run: |
pylint_score=$(pylint $(git ls-files '*.py')| grep 'rated at' | awk '{print $7}' | cut -d'/' -f1)
echo "PYLINT_SCORE=$pylint_score" >> $GITHUB_ENV

- name: Check Pylint score
run: |
if (( $(echo "$PYLINT_SCORE < 9.5" | bc -l) )); then
echo "Failure: Pylint score is below 9.5 (project score: $PYLINT_SCORE)."
exit 1
else
echo "Success: Pylint score is above 9.5 (project score: $PYLINT_SCORE)."
fi

unit-test:
name: Unit Tests
runs-on: ubuntu-latest

defaults:
Expand All @@ -35,7 +67,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v5.1.1
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
Expand All @@ -58,17 +90,23 @@ jobs:
- name: Check changed files coverage
run: |
# Get the list of changed Python files
CHANGED_FILES=$(git diff --name-only --diff-filter=AMR ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '.py$')
CHANGED_FILES=$(git diff --name-only --diff-filter=AMR ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '.py$' || true)
echo "Changed Python files: $CHANGED_FILES"

# If no Python files have changed, skip the coverage check
if [ -z "$CHANGED_FILES" ]; then
echo "No Python files have changed. Skipping coverage check for changed files."
exit 0
fi

# Convert list to comma-delimited string
CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{printf "%s,", $0} END {print ""}' | sed 's/,$//')

# Generate coverage report for changed files
coverage report --include="$CHANGED_FILES" > coverage_report.txt
echo -e "\nChanged Python files report:\n\n"
cat coverage_report.txt

# Fail if the coverage for changed files is below threshold
COVERAGE_TOTAL=$(awk '/TOTAL/ {print $4}' coverage_report.txt)
echo "Total coverage for changed files: $COVERAGE_TOTAL"
Expand Down
Loading
Loading