Skip to content
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

feat(cicd): Add UT to PR's via SonarCloud #121

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dc249a6
Adding UT to analysis.yml for UT on pr
acoard-aot Oct 18, 2024
2286de5
Re-enable Sonar after setting up SONAR_TOKEN_FRONTEND and SONAR_TOKEN…
acoard-aot Oct 18, 2024
a428998
Analaysis needs test resulst
acoard-aot Oct 18, 2024
3db23a5
Adding sonarcloud.properties file with first pass of config, will lik…
acoard-aot Oct 18, 2024
ae53cb7
Make it so that "draft" PRs will not have their own environment.
acoard-aot Oct 18, 2024
bfd7e5b
Fix folder name
acoard-aot Oct 21, 2024
9e9272f
Delete .sonarcloud.properties and move values into analysis.ylm
acoard-aot Oct 21, 2024
29fe54b
Update dockerfile to trigger UT
acoard-aot Oct 21, 2024
c53495f
Trigger frontend build for UT
acoard-aot Oct 21, 2024
40a19d5
Attempting to fix sonarcloud projectKey via GitHub Action matrix
acoard-aot Oct 21, 2024
c2519fb
Attempting fixing UT envs for log vals
acoard-aot Oct 21, 2024
87c87a0
Fix invalid space before colon in yaml
acoard-aot Oct 21, 2024
db17d12
Move env
acoard-aot Oct 21, 2024
02cc676
Removed duplicate sources
acoard-aot Oct 21, 2024
992a524
Update secret names, after updating values in GitHub
acoard-aot Oct 21, 2024
4660635
Updating sonar.tests, as it was mentioned as unset in action logs
acoard-aot Oct 21, 2024
869673b
Remove duplicate tests after duplicate indexing
acoard-aot Oct 21, 2024
68f1043
Update exclusions to also exclude migrations
acoard-aot Oct 21, 2024
7353791
Setup cpd.exclusions and projectBaseDir
acoard-aot Oct 21, 2024
1b19eb1
Update cpd exclusion as it failed. ProjectBaseDir likely failed too, …
acoard-aot Oct 21, 2024
7ea51a8
Attempting projectBaseDir=/
acoard-aot Oct 21, 2024
ba65bc7
Adding backend/frontend dirs to ProjectBaseDir
acoard-aot Oct 21, 2024
f8753ec
Temporarily hardcoding to verify values
acoard-aot Oct 21, 2024
9b89d64
Remove projectBaseDir as set by "dir", and set it with a slash to exp…
acoard-aot Oct 21, 2024
0d766f1
Quoting input in case it helps
acoard-aot Oct 21, 2024
d25f88a
Copying in test-and-analyze file
acoard-aot Oct 21, 2024
a9ea209
Adding checkout to test and analyze
acoard-aot Oct 21, 2024
ab0dcba
Reverting manual import to test
acoard-aot Oct 21, 2024
40c7848
Re-enable test and analyze manual import
acoard-aot Oct 21, 2024
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
47 changes: 46 additions & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,51 @@ concurrency:
jobs:
#TODO add the Unit TEST with sonar, sample https://github.com/bcgov/quickstart-openshift/blob/main/.github/workflows/analysis.yml#L17-L58

tests:
name: Unit Tests
# TODO - Re-enable below before submitting PR, jsut have it disabled while I work via draft.
# if: ${{ ! github.event.pull_request.draft }}
runs-on: ubuntu-24.04
timeout-minutes: 5
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
matrix:
dir: [backend/sites, frontend/site-registry]
include:
- dir: backend
acoard-aot marked this conversation as resolved.
Show resolved Hide resolved
token: SONAR_TOKEN_BACKEND
- dir: frontend
acoard-aot marked this conversation as resolved.
Show resolved Hide resolved
token: SONAR_TOKEN_FRONTEND
steps:
- uses: bcgov-nr/action-test-and-analyse@v1.2.1
with:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may need env variables for the tests to run, we can always pass all the frontend and backend env vars in the env: , and then it will be picked by each job and they use based on their needs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests are running now without ading any env: so I think it's okay without.

However, I am still having issues with SonarCloud getting the results of the tests, so still investigating.

commands: |
npm ci
npm run test:cov
dir: ${{ matrix.dir }}
node_version: "22"
sonar_args: >
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=quickstart-openshift_${{ matrix.dir }}
acoard-aot marked this conversation as resolved.
Show resolved Hide resolved
-Dsonar.sources=src
-Dsonar.tests.inclusions=**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar_token: ${{ secrets[matrix.token] }}
triggers: ('${{ matrix.dir }}/')


# https://github.com/marketplace/actions/aqua-security-trivy
trivy:
name: Trivy Security Scan
Expand All @@ -41,7 +86,7 @@ jobs:

results:
name: Analysis Results
needs: [ trivy]
needs: [tests, trivy]
if: always()
runs-on: ubuntu-24.04
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploys
if: ${{ ! github.event.pull_request.draft }}
needs: [builds]
uses: ./.github/workflows/.deployer.yml
secrets: inherit
Expand Down
15 changes: 15 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sonar.projectName=nr-site-registry
acoard-aot marked this conversation as resolved.
Show resolved Hide resolved

# Path to sources
sonar.sources=backend/sites,frontend/site-registry
sonar.tests.exclusions=backend/sites/**/*.spec.ts,frontend/site-registry/**/*.spec.ts

# Path to tests
sonar.tests=backend/sites,frontend/site-registry
sonar.tests.inclusions=backend/sites/**/*.spec.ts,frontend/site-registry/**/*.spec.ts

# Source encoding
sonar.sourceEncoding=UTF-8

# Exclusions for copy-paste detection
#sonar.cpd.exclusions=