-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Stamer
committed
Feb 9, 2019
0 parents
commit 6c9e672
Showing
9 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin | ||
.scannerwork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
image: golang:1.11.4-stretch | ||
|
||
before_script: | ||
- echo $CI_bin_REF | ||
- echo $CI_PROJECT_DIR | ||
- echo $REPO_NAME | ||
|
||
stages: | ||
- build | ||
- sonar | ||
|
||
build: | ||
stage: build | ||
script: | ||
- make build | ||
- make test | ||
artifacts: | ||
when: on_success | ||
expire_in: 1 day | ||
paths: | ||
- bin | ||
|
||
sonar: | ||
stage: sonar | ||
image: red6/docker-sonar-scanner:latest | ||
script: | ||
- sonar-scanner -Dsonar.host.url="$SONAR_HOST" -Dsonar.login="$SONAR_API_TOKEN" | ||
|
||
variables: | ||
SONAR_HOST: http://sonar.mycompany .de | ||
GO111MODULE: "on" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.PHONY: default | ||
default: build | ||
|
||
all: clean get-deps build test | ||
|
||
version := "0.1.0" | ||
|
||
build: | ||
mkdir -p bin | ||
go build -o bin/service-sonar main.go | ||
|
||
test: build | ||
go test -short -coverprofile=bin/cov.out `go list ./... | grep -v vendor/` | ||
go tool cover -func=bin/cov.out | ||
|
||
clean: | ||
rm -rf ./bin | ||
|
||
sonar: test | ||
sonar-scanner -Dsonar.projectVersion="$(version)" | ||
|
||
start-sonar: | ||
docker run --name sonarqube -p 9000:9000 sonarqube |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Example for SonarQube with Go | ||
|
||
Example on static analysis of Go code using SonarQube. | ||
|
||
## Start SonarQube | ||
|
||
docker run -d --name sonarqube -p 9000:9000 sonarqube | ||
|
||
|
||
## Run SonarQube analysis | ||
|
||
docker run --rm --network host --mount type=volume,src="$(pwd)",dst=/opt/app,type=bind -w=/opt/app red6/docker-sonar-scanner:latest sonar-scanner -Dsonar.login=**SECRET** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module service-sonar |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
func doStuff() string { | ||
return "I do stuff!" | ||
} | ||
|
||
func main() { | ||
log.Printf("starting service sonar ...") | ||
log.Printf(doStuff()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
|
||
// Check the response body is what we expect. | ||
expected := "I do stuff!" | ||
if doStuff() != expected { | ||
t.Errorf("doStuff(): got %v want %v", | ||
doStuff(), expected) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sonar.projectKey=de.red6:service_sonar | ||
sonar.projectName=service_sonar | ||
sonar.projectVersion=1.0.0 | ||
sonar.host.url=http://localhost:9000 | ||
sonar.login=**SECRET** | ||
|
||
sonar.sources=. | ||
sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/* | ||
|
||
sonar.tests=. | ||
sonar.test.inclusions=**/*_test.go | ||
sonar.test.exclusions=**/vendor/** | ||
sonar.go.coverage.reportPaths=bin/cov.out |