RunDevboxTestscripts generates and runs a testscript test for each Devbox project in dir. For each project, runs `devbox run run_test` (if script exists) and asserts it succeeds.
(t *testing.T, dir string)
| 27 | // RunDevboxTestscripts generates and runs a testscript test for each Devbox project in dir. |
| 28 | // For each project, runs `devbox run run_test` (if script exists) and asserts it succeeds. |
| 29 | func RunDevboxTestscripts(t *testing.T, dir string) { |
| 30 | // ensure the state home dir for devbox exists |
| 31 | err := os.MkdirAll(xdgStateHomeDir, 0o700) |
| 32 | if err != nil && !errors.Is(err, fs.ErrNotExist) { |
| 33 | t.Error(err) |
| 34 | } |
| 35 | |
| 36 | shard := shardFromEnv(t) |
| 37 | // projectIdx counts the projects that are actually run (in deterministic |
| 38 | // WalkDir order) so we can assign each to a shard. It is incremented only |
| 39 | // after all skip conditions, keeping the numbering identical on every runner. |
| 40 | projectIdx := 0 |
| 41 | err = filepath.WalkDir(dir, func(path string, entry os.DirEntry, err error) error { |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | if !entry.IsDir() { |
| 47 | return nil |
| 48 | } |
| 49 | |
| 50 | configPath := filepath.Join(path, "devbox.json") |
| 51 | config, err := devconfig.Open(configPath) |
| 52 | if err != nil { |
| 53 | // skip directories that do not have a devbox.json defined |
| 54 | if errors.Is(err, fs.ErrNotExist) { |
| 55 | return nil |
| 56 | } |
| 57 | return err |
| 58 | } |
| 59 | // skip configs that do not have a run_test defined |
| 60 | if _, ok := config.Scripts()["run_test"]; !ok { |
| 61 | t.Logf("skipping config due to missing run_test at: %s\n", path) |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | if strings.Contains(path, "pipenv") { |
| 66 | // pipenv takes 1100 seconds on CICD |
| 67 | |
| 68 | // CI env var is always true in GitHub Actions |
| 69 | // https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables |
| 70 | isInCI := envir.IsCI() |
| 71 | if isInCI && runtime.GOOS == "darwin" { |
| 72 | t.Logf("skipping pipenv on darwin in CI. config at: %s\n", path) |
| 73 | return nil |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if strings.Contains(path, "drupal") { |
| 78 | // drupal has errors like: https://gist.github.com/savil/9c67ffa50a2c51d118f3a4ce29ab920d |
| 79 | t.Logf("skipping drupal, config at: %s\n", path) |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | // Assign this project a stable shard slot, then skip it if it does not |
| 84 | // belong to the current runner. |
| 85 | idx := projectIdx |
| 86 | projectIdx++ |