Skip to content

Commit bae359e

Browse files
authored
Merge pull request #351 from bcgov/chore/sonar-cloud
Integrated SonarCloud, dropped CodeClimate, fixed on-pr-closed workflow, dropped CodeQL workflow
2 parents 72180e9 + 357a6fc commit bae359e

5 files changed

Lines changed: 157 additions & 107 deletions

File tree

.github/workflows/codeql-analysis.yaml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.github/workflows/unit-tests.yaml

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,39 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19+
tests-preflight:
20+
name: Preflight Check
21+
runs-on: ubuntu-latest
22+
outputs:
23+
PR_EXISTS: ${{ steps.pr-check.outputs.PR_EXISTS }}
24+
timeout-minutes: 10
25+
permissions:
26+
contents: read
27+
steps:
28+
- name: Short circuit if open PR exists for this branch (on push)
29+
id: pr-check
30+
if: github.event_name == 'push'
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
sleep 10
35+
prs=$(gh pr list --head "${{ github.ref_name }}" --state open --repo "${{ github.repository }}" --json number --jq '.[].number')
36+
if [ -n "$prs" ]; then
37+
echo "PR_EXISTS=true" >> $GITHUB_OUTPUT
38+
else
39+
echo "PR_EXISTS=false" >> $GITHUB_OUTPUT
40+
fi
41+
1942
test-app:
2043
name: Unit Tests (App)
44+
needs: tests-preflight
45+
if: needs.tests-preflight.outputs.PR_EXISTS != 'true'
2146
runs-on: ubuntu-latest
22-
if: |
23-
github.event_name == 'push' ||
24-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
2547
defaults:
2648
run:
2749
working-directory: app
2850
outputs:
29-
HAS_CC_SECRETS: ${{ steps.check-secrets.outputs.HAS_CC_SECRETS }}
51+
HAS_SONAR_SECRETS: ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
3052
timeout-minutes: 10
3153
strategy:
3254
fail-fast: true
@@ -37,10 +59,10 @@ jobs:
3759
steps:
3860
- name: Checkout Repository
3961
uses: actions/checkout@v4
40-
- name: Check CodeClimate Secrets
62+
- name: Check Sonar Secrets
4163
id: check-secrets
4264
run: |
43-
echo "HAS_CC_SECRETS=${{ secrets.CC_TEST_REPORTER_ID != '' }}" >> $GITHUB_OUTPUT
65+
echo "HAS_SONAR_SECRETS=${{ secrets.SONAR_TOKEN_APP != '' }}" >> $GITHUB_OUTPUT
4466
- name: Use Node.js ${{ matrix.node-version }}
4567
uses: actions/setup-node@v4
4668
with:
@@ -74,8 +96,8 @@ jobs:
7496
path: ${{ github.workspace }}/app/coverage
7597
retention-days: 1
7698
- name: Monitor Coverage
77-
if: "matrix.node-version == '22.x' && ! github.event.pull_request.head.repo.fork"
78-
uses: slavcodev/coverage-monitor-action@v1
99+
if: "matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
100+
uses: slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
79101
with:
80102
comment_mode: update
81103
comment_footer: false
@@ -87,15 +109,14 @@ jobs:
87109

88110
test-frontend:
89111
name: Unit Tests (Frontend)
112+
needs: tests-preflight
113+
if: needs.tests-preflight.outputs.PR_EXISTS != 'true'
90114
runs-on: ubuntu-latest
91-
if: |
92-
github.event_name == 'push' ||
93-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
94115
defaults:
95116
run:
96117
working-directory: frontend
97118
outputs:
98-
HAS_CC_SECRETS: ${{ steps.check-secrets.outputs.HAS_CC_SECRETS }}
119+
HAS_SONAR_SECRETS: ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
99120
timeout-minutes: 10
100121
strategy:
101122
fail-fast: true
@@ -106,10 +127,10 @@ jobs:
106127
steps:
107128
- name: Checkout Repository
108129
uses: actions/checkout@v4
109-
- name: Check CodeClimate Secrets
130+
- name: Check Sonar Secrets
110131
id: check-secrets
111132
run: |
112-
echo "HAS_CC_SECRETS=${{ secrets.CC_TEST_REPORTER_ID != '' }}" >> $GITHUB_OUTPUT
133+
echo "HAS_SONAR_SECRETS=${{ secrets.SONAR_TOKEN_FRONTEND != '' }}" >> $GITHUB_OUTPUT
113134
- name: Use Node.js ${{ matrix.node-version }}
114135
uses: actions/setup-node@v4
115136
with:
@@ -141,8 +162,8 @@ jobs:
141162
path: ${{ github.workspace }}/frontend/coverage
142163
retention-days: 1
143164
- name: Monitor Coverage
144-
if: "matrix.node-version == '22.x' && ! github.event.pull_request.head.repo.fork"
145-
uses: slavcodev/coverage-monitor-action@v1
165+
if: "matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
166+
uses: slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
146167
with:
147168
comment_mode: update
148169
comment_footer: false
@@ -152,24 +173,50 @@ jobs:
152173
threshold_alert: 50
153174
threshold_warning: 80
154175

155-
test-coverage:
156-
name: Publish to Code Climate
176+
test-coverage-app:
177+
name: Publish App Coverage to SonarCloud
157178
needs:
158179
- test-app
180+
if: needs.test-app.outputs.HAS_SONAR_SECRETS == 'true'
181+
runs-on: ubuntu-latest
182+
timeout-minutes: 10
183+
permissions:
184+
contents: read
185+
steps:
186+
- name: Checkout Repository
187+
uses: actions/checkout@v4.2.2
188+
- name: Restore Coverage Results
189+
uses: actions/download-artifact@v4.3.0
190+
with:
191+
name: coverage-app
192+
path: ${{ github.workspace }}/app/coverage
193+
- name: SonarCloud Scan
194+
uses: SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
195+
env:
196+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_APP }}
197+
with:
198+
projectBaseDir: app
199+
200+
test-coverage-frontend:
201+
name: Publish Frontend Coverage to SonarCloud
202+
needs:
159203
- test-frontend
160-
if: needs.test-app.outputs.HAS_CC_SECRETS == 'true'
204+
if: needs.test-frontend.outputs.HAS_SONAR_SECRETS == 'true'
161205
runs-on: ubuntu-latest
162206
timeout-minutes: 10
207+
permissions:
208+
contents: read
163209
steps:
164210
- name: Checkout Repository
165-
uses: actions/checkout@v4
211+
uses: actions/checkout@v4.2.2
166212
- name: Restore Coverage Results
167-
uses: actions/download-artifact@v4
168-
- name: Publish code coverage
169-
uses: paambaati/codeclimate-action@v9
213+
uses: actions/download-artifact@v4.3.0
214+
with:
215+
name: coverage-frontend
216+
path: ${{ github.workspace }}/frontend/coverage
217+
- name: SonarCloud Scan
218+
uses: SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
170219
env:
171-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
220+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
172221
with:
173-
coverageLocations: |
174-
${{ github.workspace }}/**/lcov.info:lcov
175-
prefix: ${{ github.workplace }}
222+
projectBaseDir: frontend

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,30 @@
33
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
44
[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
55

6-
![Tests](https://github.com/bcgov/nr-permitconnect-navigator-service/workflows/Tests/badge.svg)
7-
[![Maintainability](https://api.codeclimate.com/v1/badges/77078c9bd93bd99d5840/maintainability)](https://codeclimate.com/github/bcgov/nr-permitconnect-navigator-service/maintainability)
8-
[![Test Coverage](https://api.codeclimate.com/v1/badges/77078c9bd93bd99d5840/test_coverage)](https://codeclimate.com/github/bcgov/nr-permitconnect-navigator-service/test_coverage)
6+
[![Tests](https://github.com/bcgov/nr-permitconnect-navigator-service/actions/workflows/unit-tests.yaml/badge.svg)](https://github.com/bcgov/nr-permitconnect-navigator-service/actions/workflows/unit-tests.yaml)
7+
[![CodeQL](https://github.com/bcgov/nr-permitconnect-navigator-service/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/bcgov/nr-permitconnect-navigator-service/actions/workflows/github-code-scanning/codeql)
98

10-
NR PermitConnect Navigator Service
9+
App
10+
11+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
12+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
13+
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
14+
15+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
16+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
17+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_app&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_app)
18+
19+
Frontend
20+
21+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
22+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
23+
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
24+
25+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
26+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
27+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend)
28+
29+
Permit Connect Navigator Service, a case management system for the proponents and staff who use or support the Navigator Service
1130

1231
## Directory Structure
1332

@@ -63,14 +82,14 @@ You can quickly run this application in development mode after cloning by openin
6382
- Create `.env` in the root directory with the following
6483
- `DATABASE_URL="your_connection_string"`
6584

66-
```
85+
```sh
6786
cd app
6887
npm i
6988
npm run prisma:migrate
7089
npm run serve
7190
```
7291

73-
```
92+
```sh
7493
cd frontend
7594
npm i
7695
npm run serve

app/sonar-project.properties

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configuration (https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/analysis-parameters/)
2+
sonar.organization=bcgov-sonarcloud
3+
sonar.projectKey=bcgov-sonarcloud_nr-permitconnect-navigator-service_app
4+
sonar.projectName=nr-permitconnect-navigator-service app
5+
sonar.host.url=https://sonarcloud.io
6+
# sonar.verbose=true # Uncomment to enable very verbose sonar-scanner output
7+
8+
# Path to sources is relative to the sonar-project.properties file. Defaults to .
9+
sonar.sources=.
10+
sonar.language=ts
11+
sonar.sourceEncoding=UTF-8
12+
# sonar.modules=src
13+
14+
# Ignore database migrations and other folders
15+
sonar.exclusions=*.ts,**/cypress/**,**/coverage/**,**/migrations/**,**/node_modules/**,**/tests/**
16+
#sonar.inclusions=
17+
18+
# Path to tests
19+
sonar.tests=tests
20+
21+
# Identify the test files (https://docs.sonarsource.com/sonarqube-server/latest/project-administration/analysis-scope/#setting-the-initial-scope)
22+
#sonar.test.exclusions=
23+
sonar.test.inclusions=**/*spec.ts
24+
25+
# Ignore copy-paste duplication scanning for tests
26+
sonar.cpd.exclusions=**/*spec.ts,**/cypress/**,**/test/**
27+
28+
# Code coverage report location
29+
sonar.javascript.lcov.reportPaths=./coverage/lcov.info

frontend/sonar-project.properties

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configuration (https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/analysis-parameters/)
2+
sonar.organization=bcgov-sonarcloud
3+
sonar.projectKey=bcgov-sonarcloud_nr-permitconnect-navigator-service_frontend
4+
sonar.projectName=nr-permitconnect-navigator-service frontend
5+
sonar.host.url=https://sonarcloud.io
6+
# sonar.verbose=true # Uncomment to enable very verbose sonar-scanner output
7+
8+
# Path to sources is relative to the sonar-project.properties file. Defaults to .
9+
sonar.sources=.
10+
sonar.language=ts
11+
sonar.sourceEncoding=UTF-8
12+
# sonar.modules=src
13+
14+
# Ignore database migrations and other folders
15+
sonar.exclusions=*.ts,**/cypress/**,**/coverage/**,**/migrations/**,**/node_modules/**,**/tests/**
16+
#sonar.inclusions=
17+
18+
# Path to tests
19+
sonar.tests=tests
20+
21+
# Identify the test files (https://docs.sonarsource.com/sonarqube-server/latest/project-administration/analysis-scope/#setting-the-initial-scope)
22+
#sonar.test.exclusions=
23+
sonar.test.inclusions=**/*spec.ts
24+
25+
# Ignore copy-paste duplication scanning for tests
26+
sonar.cpd.exclusions=**/*spec.ts,**/cypress/**,**/test/**
27+
28+
# Code coverage report location
29+
sonar.javascript.lcov.reportPaths=./coverage/lcov.info

0 commit comments

Comments
 (0)