43 lines
2.0 KiB
Go
43 lines
2.0 KiB
Go
package check
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// A change that adds or modifies a compiled program fails (issue 1577): it is build output, `go build` in a module's folder
|
|
// writes one beside go.mod, and `git add -A` takes it. The build module's fetch step, which holds the merged clone, reads the
|
|
// first bytes of each changed file and reports the programs (mesh-sdk buildstep.MergeInto); the checker judges the answer.
|
|
|
|
// NoProgramsReported is the warning of a build module whose fetch answered no programs field: an older module, which cannot
|
|
// tell, so the check does not refuse a program it did not look for.
|
|
const NoProgramsReported = "the build module did not report programs: a compiled program in the change is not refused"
|
|
|
|
// checkBinariesOf fails a pull request whose change adds or modifies a compiled program, naming each file. It judges the
|
|
// first fetch answer of the pull request, whichever build module gave it; a build module that reports no programs leaves a
|
|
// warning on the check and passes it.
|
|
func (st *state) checkBinariesOf(t *target) verdictPtr {
|
|
key := fmt.Sprintf("%s#%d", t.pull.Repository, t.pull.Number)
|
|
if t.fetched.Merge == "" {
|
|
return nil // no merge was made: nothing was changed to judge
|
|
}
|
|
if t.fetched.Programs == nil {
|
|
st.c.note(fmt.Sprintf("%s: %s (%s)", key, NoProgramsReported, t.module))
|
|
st.c.warn(key, fmt.Sprintf("a compiled program is not refused: %s reported no programs", t.module))
|
|
st.j.logf("%s: %s (%s)", key, NoProgramsReported, t.module)
|
|
return nil
|
|
}
|
|
var found []string
|
|
for _, p := range *t.fetched.Programs {
|
|
if p.Commit != "" {
|
|
found = append(found, fmt.Sprintf("%s: a compiled program added in %s and removed later: it stays in history; squash the branch (issue 1577)", p.Path, short12(p.Commit)))
|
|
continue
|
|
}
|
|
found = append(found, p.Path+": a compiled program is build output: remove it and add it to .gitignore (issue 1577)")
|
|
}
|
|
if len(found) > 0 {
|
|
return failed(t.node, fmt.Sprintf("%s: %s", key, strings.Join(found, "; ")))
|
|
}
|
|
return nil
|
|
}
|