Skip to content

Commit

Permalink
Prmdr sonarcube coverage
Browse files Browse the repository at this point in the history
- Unit testing coverage reports have been added the test outputs
- New Makefile command to handle coverage testing
- Sonarcube scan integrated with new coverage reports. 

---------

Co-authored-by: Scott Alexander <scott.alexander@madetech.com>
  • Loading branch information
SRAlexander and Scott Alexander authored Oct 20, 2023
1 parent a946416 commit 3f6f1ca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
name: SonarCloud
Expand All @@ -13,6 +14,45 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x

- name: Configure React environment vars
env:
ENDPOINT_DOC_STORE_API: http://test-endpoint.com
AWS_REGION: test region
OIDC_PROVIDER_ID: not provided yet
BUILD_ENV: development
IMAGE_VERSION: 'ndr-${{ vars.BUILD_ENV }}-app:${{ github.sha }}'
run: |
./react-environment-config.sh
working-directory: ./app
shell: bash

- run: make clean-install
- run: make test-ui-coverage

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python_version: 3.11

- name: Make virtual environment
run: |
make env
- name: Start virtual environment
run: |
source ./lambdas/venv/bin/activate
# echo PATH=$PATH >> $GITHUB_ENV
- name: Test with pytest
run: |
make test-unit-coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ format:
test-unit:
cd ./lambdas && ./venv/bin/python3 -m pytest tests/

test-unit-coverage:
cd ./lambdas && ./venv/bin/python3 -m pytest --cov-report xml:coverage.xml --cov tests/

test-unit-collect:
cd ./lambdas && ./venv/bin/python3 -m pytest tests/ --collect-only

Expand Down Expand Up @@ -80,6 +83,9 @@ storybook:
test-ui:
npm --prefix ./app run test-all

test-ui-coverage:
npm --prefix ./app run test-all:coverage

build:
npm --prefix ./app run build

Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build-env-check": "node ./react-build-env-checker.js && react-scripts build",
"test": "./node_modules/.bin/react-scripts test --watchAll=true",
"test-all": "./node_modules/.bin/react-scripts test --watchAll=false",
"test-all:coverage": "./node_modules/.bin/react-scripts test --watchAll=false --coverage src",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"format": "prettier --write \"**/*.+(ts|tsx|js|scss|json|css|md)\"",
Expand Down
2 changes: 2 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sonar.organization=prm-repository
sonar.projectName=Repository
sonar.projectVersion=1.0

sonar.javascript.lcov.reportPaths=app/coverage/lcov.info
sonar.python.coverage.reportPaths=lambdas/coverage.xml

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
Expand Down

0 comments on commit 3f6f1ca

Please sign in to comment.