Skip to content

Commit 09fed15

Browse files
PaulGreywalCopilot
andauthored
Refactor SonarCloud analysis workflow (#2630)
* Refactor SonarCloud analysis workflow Updated SonarCloud workflow to improve structure and add scheduling. * Add develop branch to SonarCloud analysis workflow * Update .github/workflows/sonarcloud.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/sonarcloud.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update SonarCloud project keys in workflow --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0330741 commit 09fed15

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Analysis
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
8+
schedule:
9+
- cron: "0 11 * * 0" # 3 AM PST = 11 AM UTC, runs Sundays
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions: {}
17+
18+
jobs:
19+
backend-tests:
20+
name: Backend Tests
21+
if: (! github.event.pull_request.draft)
22+
runs-on: ubuntu-24.04
23+
timeout-minutes: 5
24+
services:
25+
postgres:
26+
image: postgres
27+
env:
28+
POSTGRES_PASSWORD: default
29+
options: >-
30+
--health-cmd pg_isready
31+
--health-interval 10s
32+
--health-timeout 5s
33+
--health-retries 5
34+
ports:
35+
- 5432:5432
36+
steps:
37+
- uses: bcgov/action-test-and-analyse@51b50be3bb2522e480ed8eab72735612deff7f15 # v1.4.0
38+
env:
39+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
40+
with:
41+
commands: |
42+
npm ci
43+
npm run lint
44+
npm run test:cov
45+
dir: services
46+
node_version: "22"
47+
sonar_args: >
48+
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
49+
-Dsonar.organization=bcgov-sonarcloud
50+
-Dsonar.projectKey=bcgov_alcs
51+
-Dsonar.sources=apps,libs
52+
-Dsonar.tests.inclusions=**/*spec.ts
53+
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
54+
sonar_token: ${{ env.SONAR_TOKEN }}
55+
triggers: ('services/')
56+
57+
alcs-frontend-tests:
58+
name: ALCS Frontend Tests
59+
if: (! github.event.pull_request.draft)
60+
runs-on: ubuntu-24.04
61+
timeout-minutes: 5
62+
steps:
63+
- uses: bcgov/action-test-and-analyse@51b50be3bb2522e480ed8eab72735612deff7f15 # v1.4.0
64+
env:
65+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
66+
with:
67+
commands: |
68+
npm ci
69+
npm run lint
70+
npm run test:cov
71+
dir: alcs-frontend
72+
node_version: "22"
73+
sonar_args: >
74+
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
75+
-Dsonar.organization=bcgov-sonarcloud
76+
-Dsonar.projectKey=bcgov_alcs
77+
-Dsonar.sources=src
78+
-Dsonar.tests.inclusions=**/*spec.ts
79+
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
80+
sonar_token: ${{ env.SONAR_TOKEN }}
81+
triggers: ('alcs-frontend/')
82+
83+
portal-frontend-tests:
84+
name: Portal Frontend Tests
85+
if: (! github.event.pull_request.draft)
86+
runs-on: ubuntu-24.04
87+
timeout-minutes: 5
88+
steps:
89+
- uses: bcgov/action-test-and-analyse@51b50be3bb2522e480ed8eab72735612deff7f15 # v1.4.0
90+
env:
91+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
92+
with:
93+
commands: |
94+
npm ci
95+
npm run lint
96+
npm run test:cov
97+
dir: portal-frontend
98+
node_version: "22"
99+
sonar_args: >
100+
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
101+
-Dsonar.organization=bcgov-sonarcloud
102+
-Dsonar.projectKey=bcgov_alcs
103+
-Dsonar.sources=src
104+
-Dsonar.tests.inclusions=**/*spec.ts
105+
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
106+
sonar_token: ${{ env.SONAR_TOKEN }}
107+
triggers: ('portal-frontend/')
108+
109+
results:
110+
name: Analysis Results
111+
needs: [backend-tests, alcs-frontend-tests, portal-frontend-tests]
112+
if: (! github.event.pull_request.draft)
113+
runs-on: ubuntu-24.04
114+
steps:
115+
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'canceled')
116+
run: echo "At least one job has failed." && exit 1
117+
- run: echo "Success!"

0 commit comments

Comments
 (0)