MCPcopy Index your code
hub / github.com/jetify-com/devbox / walkExampleDir

Function walkExampleDir

testscripts/testrunner/updater/main.go:46–95  ·  view source on GitHub ↗
(devboxRepoDir, path string, dirEntry fs.DirEntry, err error)

Source from the content-addressed store, hash-verified

44var examplesToTry = 0
45
46func walkExampleDir(devboxRepoDir, path string, dirEntry fs.DirEntry, err error) error {
47 if err != nil {
48 return errors.WithStack(err)
49 }
50
51 // Uncomment to try out changes
52 // if examplesToTry > 3 {
53 // return nil
54 // }
55 _ = examplesToTry // silence linter
56
57 // If it is a directory, then we don't continue.
58 if dirEntry.IsDir() {
59 // Skip if it is a directory that we don't want to process at all.
60 skippedDirs := []string{".devbox", "node_modules"}
61 if lo.Contains(skippedDirs, dirEntry.Name()) {
62 return filepath.SkipDir
63 }
64 return nil
65 }
66
67 // If it is not a devbox.json file, then we don't continue.
68 if dirEntry.Name() != "devbox.json" {
69 return nil
70 }
71
72 // Read the devbox.json file
73 contentBytes, err := os.ReadFile(path)
74 if err != nil {
75 return errors.WithStack(err)
76 }
77 content := string(contentBytes)
78
79 // Skip if it doesn't have a run_test script
80 if !strings.Contains(content, "run_test") {
81 fmt.Printf("SKIP: config at %s lacks run_test\n", path)
82 return nil
83 }
84
85 // run `devbox update` on this example
86 devboxExecutable := filepath.Join(devboxRepoDir, "dist", "devbox")
87 cmd := exec.Command(devboxExecutable, "update", "-c", filepath.Dir(path))
88 if err := cmd.Run(); err != nil {
89 return errors.WithStack(err)
90 }
91 fmt.Printf("Ran `devbox update` on %s\n", path)
92 examplesToTry++
93
94 return nil
95}
96
97func devboxRepoDir() (string, error) {
98 _, filename, _, ok := runtime.Caller(0)

Callers 1

runFunction · 0.85

Calls 2

CommandMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected