Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Stamer committed Feb 9, 2019
0 parents commit 6c9e672
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
.scannerwork
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
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"
23 changes: 23 additions & 0 deletions Makefile
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
12 changes: 12 additions & 0 deletions README.md
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**
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module service-sonar
4 changes: 4 additions & 0 deletions index.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions main.go
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())
}
16 changes: 16 additions & 0 deletions main_test.go
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)
}

}
13 changes: 13 additions & 0 deletions sonar-project.properties
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

0 comments on commit 6c9e672

Please sign in to comment.