getReleaseFiles returns the release files.
(w *world.World)
| 18 | |
| 19 | // getReleaseFiles returns the release files. |
| 20 | func getReleaseFiles(w *world.World) ([]*v1pb.Release_File, error) { |
| 21 | // Use doublestar for recursive glob support (**/*.sql) |
| 22 | matches, err := doublestar.FilepathGlob(w.FilePattern) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | if len(matches) == 0 { |
| 27 | return nil, errors.Errorf("no files found for pattern: %s", w.FilePattern) |
| 28 | } |
| 29 | |
| 30 | slices.Sort(matches) |
| 31 | |
| 32 | if w.Declarative { |
| 33 | // For declarative files, we need to concat all the file contents if it is rollout. |
| 34 | if w.IsRollout { |
| 35 | var contents []byte |
| 36 | for _, m := range matches { |
| 37 | content, err := os.ReadFile(m) |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | // Add newline separator between files to prevent SQL statements from being concatenated |
| 42 | if len(contents) > 0 { |
| 43 | contents = append(contents, '\n') |
| 44 | } |
| 45 | contents = append(contents, content...) |
| 46 | } |
| 47 | return []*v1pb.Release_File{ |
| 48 | { |
| 49 | // use file pattern as the path |
| 50 | Path: w.FilePattern, |
| 51 | Version: w.CurrentTime.Format(versionFormat), |
| 52 | Statement: contents, |
| 53 | }, |
| 54 | }, nil |
| 55 | } |
| 56 | |
| 57 | var files []*v1pb.Release_File |
| 58 | for _, m := range matches { |
| 59 | content, err := os.ReadFile(m) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | files = append(files, &v1pb.Release_File{ |
| 64 | Path: m, |
| 65 | Version: w.CurrentTime.Format(versionFormat), |
| 66 | Statement: content, |
| 67 | }) |
| 68 | } |
| 69 | return files, nil |
| 70 | } |
| 71 | |
| 72 | var files []*v1pb.Release_File |
| 73 | for _, m := range matches { |
| 74 | content, err := os.ReadFile(m) |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
no test coverage detected