Emit diagnostic to pass fourth integration tests

This commit is contained in:
Owen Mansel-Chan
2023-03-03 11:10:00 +00:00
parent 8d28253175
commit a7a10de9ea
3 changed files with 34 additions and 0 deletions

View File

@@ -143,3 +143,13 @@ func EmitNewerGoVersionNeeded() {
"", 0, 0, 0, 0,
)
}
func EmitGoFilesFoundButNotProcessed() {
emitDiagnostic("go/autobuilder/go-files-found-but-not-processed",
"Go files were found but not processed",
"[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.",
severityError, false,
true, true, true,
"", 0, 0, 0, 0,
)
}

View File

@@ -98,6 +98,15 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
if len(pkgs) == 0 {
log.Println("No packages found.")
wd, err := os.Getwd()
if err != nil {
log.Fatalf("Unable to determine current directory: %s\n", err.Error())
}
if util.FindGoFiles(wd) {
diagnostics.EmitGoFilesFoundButNotProcessed()
}
}
log.Println("Extracting universe scope.")

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"io"
"io/fs"
"log"
"os"
"os/exec"
@@ -281,3 +282,17 @@ func EscapeTrapSpecialChars(s string) string {
s = strings.ReplaceAll(s, "#", "#")
return s
}
func FindGoFiles(root string) bool {
found := false
filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error {
if e != nil {
return e
}
if filepath.Ext(d.Name()) == ".go" {
found = true
}
return nil
})
return found
}