Skip to content

Commit a7a10de

Browse files
committed
Emit diagnostic to pass fourth integration tests
1 parent 8d28253 commit a7a10de

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

go/extractor/diagnostics/diagnostics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ func EmitNewerGoVersionNeeded() {
143143
"", 0, 0, 0, 0,
144144
)
145145
}
146+
147+
func EmitGoFilesFoundButNotProcessed() {
148+
emitDiagnostic("go/autobuilder/go-files-found-but-not-processed",
149+
"Go files were found but not processed",
150+
"[Specify a custom build command](https://docs.github.com/en/github-ae@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-language) that includes one or more `go build` commands to build the `.go` files to be analyzed.",
151+
severityError, false,
152+
true, true, true,
153+
"", 0, 0, 0, 0,
154+
)
155+
}

go/extractor/extractor.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
9898

9999
if len(pkgs) == 0 {
100100
log.Println("No packages found.")
101+
102+
wd, err := os.Getwd()
103+
if err != nil {
104+
log.Fatalf("Unable to determine current directory: %s\n", err.Error())
105+
}
106+
107+
if util.FindGoFiles(wd) {
108+
diagnostics.EmitGoFilesFoundButNotProcessed()
109+
}
101110
}
102111

103112
log.Println("Extracting universe scope.")

go/extractor/util/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"io"
7+
"io/fs"
78
"log"
89
"os"
910
"os/exec"
@@ -281,3 +282,17 @@ func EscapeTrapSpecialChars(s string) string {
281282
s = strings.ReplaceAll(s, "#", "#")
282283
return s
283284
}
285+
286+
func FindGoFiles(root string) bool {
287+
found := false
288+
filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error {
289+
if e != nil {
290+
return e
291+
}
292+
if filepath.Ext(d.Name()) == ".go" {
293+
found = true
294+
}
295+
return nil
296+
})
297+
return found
298+
}

0 commit comments

Comments
 (0)