Skip to content

Commit

Permalink
(feat)trivy-action (#81)
Browse files Browse the repository at this point in the history
In GitHub trivy action container we need safe directory to run git fetch

Co-authored-by: oranmoshai <oran.moshai@aquasec.com>
  • Loading branch information
oranmoshai and oranmoshai authored Apr 24, 2022
1 parent 7807c2b commit 37a0bb0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/scanner/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func gitExec(args ...string) (out string, err error) {
cmd := exec.Command("git", args...)
output, err := cmd.CombinedOutput()
if err != nil {
return out, errors.Wrap(err, "failed run git cmd")
return out, errors.Wrap(err, fmt.Sprintf("failed run git cmd output: %s", string(output)))
}

return string(output), nil
Expand Down Expand Up @@ -55,6 +55,11 @@ func createDiffScanFs() error {

// In GitHub we need fetch the remote branch first
if os.Getenv("GITHUB_BASE_REF") != "" {
// In GitHub trivy action container we need safe directory to run git fetch
_, err = gitExec("config", "--global", "--add", "safe.directory", "/github/workspace")
if err != nil {
return errors.Wrap(err, "failed git fetch ref")
}
_, err = gitExec("fetch", "origin", fmt.Sprintf("refs/heads/%s", os.Getenv("GITHUB_BASE_REF")))
if err != nil {
return errors.Wrap(err, "failed git fetch ref")
Expand Down

0 comments on commit 37a0bb0

Please sign in to comment.