Skip to content

Commit

Permalink
Skip .git and skip non-go files in vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy Baukema committed Nov 9, 2023
1 parent 3b1d350 commit e70d4e2
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/fs"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"time"

Expand All @@ -29,7 +31,7 @@ import (
// TODO: Detect and warn on incorrect Go version based on go mod
// TODO: Better error handling when go mod vendor fails
func main() {
log.Debug("Running version v0.0.14")
log.Debug("Running version v0.0.15")

flag.Parse()
inputPath := flag.Arg(0)
Expand Down Expand Up @@ -79,7 +81,7 @@ func main() {
}
}

log.Debug("Ran version v0.0.14")
log.Debug("Ran version v0.0.15")
}

func getMainFiles(absPathStat os.FileInfo, absPath string) ([]string, error) {
Expand Down Expand Up @@ -176,7 +178,23 @@ func packageMainFile(mainFile string, packageDate string) error {
copyDir := tempWorkDir + "/" + filepath.Base(filepath.Dir(goModPath))

log.WithFields(log.Fields{"from": parentDir, "to": copyDir}).Debug("Copying files")
err = copy.Copy(parentDir, copyDir)
err = copy.Copy(parentDir, copyDir, copy.Options{
Skip: func(srcinfo fs.FileInfo, src string, dest string) (bool, error) {
filename := filepath.Base(src)
if filename == ".git" {
fmt.Println("Skipping copying: " + src)
return true, nil
}
pathComponentsLinux := strings.Split(src, "/")
pathComponentsWindows := strings.Split(src, "\\")
isInVendor := slices.Contains(pathComponentsLinux, "vendor") || slices.Contains(pathComponentsWindows, "vendor")
if isInVendor && !srcinfo.IsDir() && !strings.HasSuffix(src, ".go") {
fmt.Println("Skipping copying: " + src)
return true, nil
}
return false, nil
},
})
if err != nil {
return err
}
Expand Down

0 comments on commit e70d4e2

Please sign in to comment.