Skip to content

Commit 85c0023

Browse files
mprahldhaiducek
authored andcommitted
Run SonarCloud on PRs and pushes
Relates: stolostron/backlog#25949 Signed-off-by: mprahl <[email protected]>
1 parent 0f0e4e6 commit 85c0023

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Sonarcloud scan
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Unit Tests
7+
types:
8+
- completed
9+
10+
jobs:
11+
sonarcloud:
12+
uses: stolostron/governance-policy-framework/.github/workflows/sonarcloud.yml@main
13+
secrets:
14+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/unit-tests.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ jobs:
2323
with:
2424
go-version-file: go.mod
2525

26-
- name: Unit Tests
26+
- name: Test Coverage and Report Generation
2727
run: |
28-
make test
28+
make test-coverage | tee report_unit.json
29+
make gosec-scan
30+
cat gosec.json
31+
32+
- name: Store the GitHub triggering event for the sonarcloud workflow
33+
if: |
34+
github.repository_owner == 'stolostron'
35+
run: |
36+
cat <<EOF > event.json
37+
${{ toJSON(github.event) }}
38+
EOF
39+
40+
- name: Upload artifacts for the sonarcloud workflow
41+
if: |
42+
github.repository_owner == 'stolostron'
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: artifacts
46+
path: |
47+
coverage*.out
48+
event.json
49+
gosec.json

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ vendor/
2424
.idea
2525

2626
bin/
27+
28+
gosec.json
29+
coverage.out

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ lint: lint-dependencies lint-all
8080
############################################################
8181
# test section
8282
############################################################
83+
GOSEC = $(LOCAL_BIN)/gosec
8384

8485
test:
8586
@go test $(TESTARGS) ./...
87+
88+
.PHONY: test-coverage
89+
test-coverage: TESTARGS = -json -cover -covermode=atomic -coverprofile=coverage.out
90+
test-coverage: test
91+
92+
.PHONY: gosec
93+
gosec:
94+
$(call go-get-tool,github.com/securego/gosec/v2/cmd/[email protected])
95+
96+
.PHONY: gosec-scan
97+
gosec-scan: gosec
98+
$(GOSEC) -fmt sonarqube -out gosec.json -no-fail -exclude-dir=.go ./...

0 commit comments

Comments
 (0)