forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modulegen: generate sonar configuration (testcontainers#1644)
Signed-off-by: Matthieu MOREL <[email protected]>
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
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,21 @@ | ||
# This file is autogenerated by the 'modulegen' tool. | ||
# Github organization linked to sonarcloud | ||
sonar.organization=testcontainers | ||
|
||
# Project key from sonarcloud dashboard for Github Action, otherwise pick a project key you like | ||
sonar.projectKey=testcontainers_testcontainers-go | ||
|
||
sonar.projectName=testcontainers-go | ||
|
||
sonar.projectVersion={{ .ProjectVersion }} | ||
|
||
sonar.sources=. | ||
|
||
sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/** | ||
|
||
sonar.tests=. | ||
sonar.test.inclusions=**/*_test.go | ||
sonar.test.exclusions=**/vendor/** | ||
|
||
sonar.go.coverage.reportPaths=**/coverage.out | ||
sonar.go.tests.reportPaths={{ .Go.Tests.ReportPaths }} |
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
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
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,43 @@ | ||
package sonar | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"text/template" | ||
|
||
"github.com/testcontainers/testcontainers-go/modulegen/internal/context" | ||
"github.com/testcontainers/testcontainers-go/modulegen/internal/mkdocs" | ||
internal_template "github.com/testcontainers/testcontainers-go/modulegen/internal/template" | ||
) | ||
|
||
type Generator struct{} | ||
|
||
// Generate updates sonar-project.properties | ||
func (g Generator) Generate(ctx context.Context) error { | ||
rootCtx, err := context.GetRootContext() | ||
if err != nil { | ||
return err | ||
} | ||
examples, err := rootCtx.GetExamples() | ||
if err != nil { | ||
return err | ||
} | ||
modules, err := rootCtx.GetModules() | ||
if err != nil { | ||
return err | ||
} | ||
mkdocsConfig, err := mkdocs.ReadConfig(rootCtx.MkdocsConfigFile()) | ||
if err != nil { | ||
fmt.Printf(">> could not read MkDocs config: %v\n", err) | ||
return err | ||
} | ||
tcVersion := mkdocsConfig.Extra.LatestVersion | ||
config := newConfig(tcVersion, examples, modules) | ||
name := "sonar-project.properties.tmpl" | ||
t, err := template.New(name).ParseFiles(filepath.Join("_template", name)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return internal_template.GenerateFile(t, ctx.SonarProjectFile(), name, config) | ||
} |
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,38 @@ | ||
package sonar | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
type Config struct { | ||
Go Go | ||
ProjectVersion string | ||
} | ||
|
||
type Go struct { | ||
Tests Tests | ||
} | ||
|
||
type Tests struct { | ||
ReportPaths string | ||
} | ||
|
||
func newConfig(tcVersion string, examples []string, modules []string) *Config { | ||
reportPaths := []string{"TEST-unit.xml", "modulegen/TEST-unit.xml"} | ||
for _, example := range examples { | ||
reportPaths = append(reportPaths, "examples/"+example+"/TEST-unit.xml") | ||
} | ||
for _, module := range modules { | ||
reportPaths = append(reportPaths, "modules/"+module+"/TEST-unit.xml") | ||
} | ||
sort.Strings(reportPaths) | ||
return &Config{ | ||
Go: Go{ | ||
Tests: Tests{ | ||
ReportPaths: strings.Join(reportPaths, ","), | ||
}, | ||
}, | ||
ProjectVersion: tcVersion, | ||
} | ||
} |
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