Skip to content

Commit 7ef4e5b

Browse files
authored
Merge pull request #115 from sergioteula/fix-sonar-errors
Fix sonar errors
2 parents 83d26a9 + 0046e94 commit 7ef4e5b

File tree

8 files changed

+92
-6
lines changed

8 files changed

+92
-6
lines changed

.coveragerc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[run]
2+
branch = True
3+
source = amazon_paapi
4+
relative_files = True
5+
omit = **/sdk/**
6+
7+
[report]
8+
fail_under = 80
9+
skip_covered = true
10+
skip_empty = true
11+
12+
[html]
13+
directory = coverage_html_report
14+
skip_covered = false

.githooks/pre-push

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ source "${ROOT_DIR}/scripts/helpers"
77
./scripts/check_black
88
./scripts/check_flake8
99
./scripts/check_pylint
10+
./scripts/run_tests
1011

1112
header "Proceeding with push"

.github/workflows/lint-and-test.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Lint and test
33
on:
44
push:
55

6+
permissions:
7+
pull-requests: read
8+
69
jobs:
710

811
isort:
@@ -13,7 +16,7 @@ jobs:
1316
- ${{github.workspace}}:/code
1417
steps:
1518
- name: Check out code
16-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
1720
- name: Check imports order
1821
run: ./scripts/check_isort
1922

@@ -25,7 +28,7 @@ jobs:
2528
- ${{github.workspace}}:/code
2629
steps:
2730
- name: Check out code
28-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
2932
- name: Check code format
3033
run: ./scripts/check_black
3134

@@ -37,7 +40,7 @@ jobs:
3740
- ${{github.workspace}}:/code
3841
steps:
3942
- name: Check out code
40-
uses: actions/checkout@v2
43+
uses: actions/checkout@v3
4144
- name: Check code errors
4245
run: ./scripts/check_flake8
4346

@@ -49,6 +52,41 @@ jobs:
4952
- ${{github.workspace}}:/code
5053
steps:
5154
- name: Check out code
52-
uses: actions/checkout@v2
55+
uses: actions/checkout@v3
5356
- name: Check code errors
5457
run: ./scripts/check_pylint
58+
59+
test:
60+
runs-on: ubuntu-latest
61+
container:
62+
image: sergioteula/pytools
63+
volumes:
64+
- ${{github.workspace}}:/code
65+
steps:
66+
- name: Check out code
67+
uses: actions/checkout@v3
68+
- name: Run tests
69+
run: ./scripts/run_tests
70+
- name: Save code coverage file
71+
uses: actions/upload-artifact@v3
72+
with:
73+
name: coverage
74+
path: coverage.xml
75+
76+
sonar:
77+
runs-on: ubuntu-latest
78+
needs: [test]
79+
steps:
80+
- name: Check out code
81+
uses: actions/checkout@v3
82+
with:
83+
fetch-depth: 0
84+
- name: Download a single artifact
85+
uses: actions/download-artifact@v3
86+
with:
87+
name: coverage
88+
- name: Check code errors
89+
uses: SonarSource/sonarcloud-github-action@master
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.DS_Store
44
secrets.py
55
test.py
6+
coverage_html_report
67

78

89
# Byte-compiled / optimized / DLL files

amazon_paapi/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_items(
114114
return sort_items(results, items_ids, include_unavailable)
115115

116116
def search_items(
117-
self,
117+
self, # NOSONAR
118118
item_count: int = None,
119119
item_page: int = None,
120120
actor: str = None,

scripts/helpers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GREEN="\033[0;32m"
55
RED="\033[0;31m"
66
YELLOW="\033[0;33m"
77
NC="\033[0m"
8-
LINE="--------------------------------------------------------------------"
8+
LINE="----------------------------------------------------------------------"
99

1010
check_if_installed() {
1111
if [ -x "$(command -v "${1}")" ]; then

scripts/run_tests

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /bin/bash
2+
3+
ROOT_DIR="$(git rev-parse --show-toplevel)"
4+
source "${ROOT_DIR}/scripts/helpers"
5+
6+
header "Running tests"
7+
8+
if [ -n "$(check_if_installed docker)" ]; then
9+
docker run -v "${PWD}:/code" sergioteula/pytools bash -c \
10+
"coverage run -m unittest && coverage xml && coverage html && echo && coverage report"
11+
elif [ -n "$(check_if_installed coverage)" ]; then
12+
coverage run -m unittest && coverage xml && coverage html && echo && coverage report
13+
else
14+
error "coverage is not installed"
15+
exit 1
16+
fi
17+
18+
EXIT_CODE="$?"
19+
if [ "$EXIT_CODE" = "0" ]; then
20+
success "Tests passed"
21+
else
22+
error "Tests failed"
23+
exit 1
24+
fi

sonar-project.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sonar.organization=sergioteula
2+
sonar.projectKey=sergioteula_python-amazon-paapi
3+
sonar.sources=amazon_paapi
4+
sonar.exclusions=**/sdk/**
5+
sonar.qualitygate.wait=true
6+
sonar.python.version=3.6,3.7,3.8,3.9,3.10
7+
sonar.tests=tests
8+
sonar.python.coverage.reportPaths=coverage.xml

0 commit comments

Comments
 (0)