Inspect committed workspace files
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"go/format"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gotool"
|
||||
@@ -15,10 +16,16 @@ import (
|
||||
|
||||
// Settings selects shared validation behavior.
|
||||
type Settings struct {
|
||||
Race bool
|
||||
FullVet bool
|
||||
CompileTargets []Target
|
||||
GoFormat bool
|
||||
Race bool
|
||||
FullVet bool
|
||||
CompileTargets []Target
|
||||
GoFormat bool
|
||||
ModuleDistribution ModuleDistributionSettings
|
||||
}
|
||||
|
||||
// ModuleDistributionSettings selects candidate distribution checks.
|
||||
type ModuleDistributionSettings struct {
|
||||
WorkspaceFiles bool
|
||||
}
|
||||
|
||||
// Target selects one package-compilation target.
|
||||
@@ -91,14 +98,45 @@ func Run(ctx context.Context, request Request) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if request.Settings.GoFormat {
|
||||
if request.Settings.GoFormat || request.Settings.ModuleDistribution.WorkspaceFiles {
|
||||
tree, err := request.ReadCandidateTree(ctx)
|
||||
if err != nil {
|
||||
return &Failure{Check: GoFormat, Cause: err}
|
||||
check := WorkspaceFiles
|
||||
if request.Settings.GoFormat {
|
||||
check = GoFormat
|
||||
}
|
||||
return &Failure{Check: check, Cause: err}
|
||||
}
|
||||
if err := checkGoFormat(ctx, tree); err != nil {
|
||||
return err
|
||||
if request.Settings.GoFormat {
|
||||
if err := checkGoFormat(ctx, tree); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if request.Settings.ModuleDistribution.WorkspaceFiles {
|
||||
if err := checkWorkspaceFiles(tree); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkWorkspaceFiles(tree *CandidateTree) error {
|
||||
var findings []Finding
|
||||
for _, entry := range tree.Entries() {
|
||||
if entry.Type != "blob" {
|
||||
continue
|
||||
}
|
||||
switch path.Base(entry.Path) {
|
||||
case "go.work", "go.work.sum":
|
||||
findings = append(findings, Finding{
|
||||
Path: entry.Path,
|
||||
Message: "workspace file is committed in the candidate",
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(findings) != 0 {
|
||||
return &Failure{Check: WorkspaceFiles, Findings: findings}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user