Skip to content

Commit 5be6d12

Browse files
authored
Reload updated files from Mint directory when base is added on run. (#143)
1 parent 25dd8d9 commit 5be6d12

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

internal/cli/service.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ func (s Service) InitiateRun(cfg InitiateRunConfig) (*api.InitiateRunResult, err
167167
// Reload run definitions after modifying the file
168168
taskDefinitions, err = s.mintDirectoryEntriesFromPaths([]string{taskDefinitionYamlPath})
169169
if err != nil {
170-
return nil, errors.Wrap(err, "unable to read provided files")
170+
return nil, errors.Wrapf(err, "unable to reload %q", taskDefinitionYamlPath)
171+
}
172+
if mintDirectoryPath != "" {
173+
mintDirectoryEntries, err := s.mintDirectoryEntries(mintDirectoryPath)
174+
if err != nil && !errors.Is(err, errors.ErrFileNotExists) {
175+
return nil, errors.Wrapf(err, "unable to reload mint directory %q", mintDirectoryPath)
176+
}
177+
178+
mintDirectory = mintDirectoryEntries
171179
}
172180
}
173181

@@ -416,7 +424,6 @@ func outputLintOneLine(w io.Writer, lintedFiles []api.LintProblem) error {
416424
return nil
417425
}
418426

419-
// InitiateRun will connect to the Cloud API and start a new run in Mint.
420427
func (s Service) Login(cfg LoginConfig) error {
421428
err := cfg.Validate()
422429
if err != nil {
@@ -733,7 +740,6 @@ type baseLayerRunFile struct {
733740
type resolveBaseResult struct {
734741
ErroredRunFiles []baseLayerRunFile
735742
UpdatedRunFiles []baseLayerRunFile
736-
NoRunFilesFound bool
737743
}
738744

739745
func (r resolveBaseResult) HasChanges() bool {
@@ -778,7 +784,7 @@ func (s Service) ResolveBase(cfg ResolveBaseConfig) error {
778784
return fmt.Sprintf("%d files", len(files))
779785
}
780786

781-
if result.NoRunFilesFound {
787+
if len(yamlFiles) == 0 {
782788
fmt.Fprintf(s.Stdout, "No run files found in %q.\n", cfg.DefaultDir)
783789
} else if !result.HasChanges() {
784790
fmt.Fprintln(s.Stdout, "No run files needed to be updated.")
@@ -838,7 +844,7 @@ func (s Service) resolveBaseForFiles(mintFiles []api.MintDirectoryEntry, request
838844
}
839845

840846
if len(runFiles) == 0 {
841-
return resolveBaseResult{NoRunFilesFound: true}, nil
847+
return resolveBaseResult{}, nil
842848
}
843849

844850
specToResolved, err := s.resolveBaseSpecs(runFiles)
@@ -869,7 +875,6 @@ func (s Service) resolveBaseForFiles(mintFiles []api.MintDirectoryEntry, request
869875
return resolveBaseResult{
870876
ErroredRunFiles: erroredRunFiles,
871877
UpdatedRunFiles: updatedRunFiles,
872-
NoRunFilesFound: len(runFiles) == 0,
873878
}, nil
874879
}
875880

internal/cli/service_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,36 +288,36 @@ var _ = Describe("CLI Service", func() {
288288
Context("when 'base' is missing", func() {
289289
var originalSpecifiedFileContent string
290290
var receivedSpecifiedFileContent string
291+
var receivedMintDirectoryFileContent string
291292

292293
BeforeEach(func() {
293294
originalSpecifiedFileContent = "tasks:\n - key: foo\n run: echo 'bar'\n"
294295

295296
var err error
296297

297-
workingDir := filepath.Join(tmp, "some", "path", "to", "working", "directory")
298-
err = os.MkdirAll(workingDir, 0o755)
299-
Expect(err).NotTo(HaveOccurred())
300-
301-
err = os.Chdir(workingDir)
298+
mintDir := filepath.Join(tmp, ".mint")
299+
err = os.MkdirAll(mintDir, 0o755)
302300
Expect(err).NotTo(HaveOccurred())
303301

304-
err = os.WriteFile(filepath.Join(workingDir, "mint.yml"), []byte(originalSpecifiedFileContent), 0o644)
302+
err = os.WriteFile(filepath.Join(mintDir, "foo.yml"), []byte(originalSpecifiedFileContent), 0o644)
305303
Expect(err).NotTo(HaveOccurred())
306304

307-
runConfig.MintFilePath = "mint.yml"
308-
runConfig.MintDirectory = ""
305+
runConfig.MintFilePath = ".mint/foo.yml"
306+
runConfig.MintDirectory = ".mint"
309307

310308
mockAPI.MockInitiateRun = func(cfg api.InitiateRunConfig) (*api.InitiateRunResult, error) {
311309
Expect(cfg.TaskDefinitions).To(HaveLen(1))
312310
Expect(cfg.TaskDefinitions[0].Path).To(Equal(runConfig.MintFilePath))
313-
Expect(cfg.MintDirectory).To(HaveLen(0))
311+
Expect(cfg.MintDirectory).To(HaveLen(2))
314312
Expect(cfg.UseCache).To(BeTrue())
315313
receivedSpecifiedFileContent = cfg.TaskDefinitions[0].FileContents
314+
receivedMintDirectoryFileContent = cfg.MintDirectory[1].FileContents
315+
316316
return &api.InitiateRunResult{
317317
RunId: "785ce4e8-17b9-4c8b-8869-a55e95adffe7",
318318
RunURL: "https://cloud.rwx.com/mint/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
319319
TargetedTaskKeys: []string{},
320-
DefinitionPath: ".mint/mint.yml",
320+
DefinitionPath: ".mint/foo.yml",
321321
}, nil
322322
}
323323
})
@@ -335,8 +335,12 @@ var _ = Describe("CLI Service", func() {
335335
Expect(receivedSpecifiedFileContent).To(Equal(fmt.Sprintf("%s\n%s", baseSpec, originalSpecifiedFileContent)))
336336
})
337337

338+
It("passes the updated file content in the mint directory artifact", func() {
339+
Expect(receivedMintDirectoryFileContent).To(Equal(fmt.Sprintf("%s\n%s", baseSpec, originalSpecifiedFileContent)))
340+
})
341+
338342
It("prints a warning", func() {
339-
Expect(mockStderr.String()).To(ContainSubstring("Configured \"mint.yml\" to run on ubuntu 24.04\n"))
343+
Expect(mockStderr.String()).To(ContainSubstring("Configured \".mint/foo.yml\" to run on ubuntu 24.04\n"))
340344
})
341345
})
342346
})
@@ -1790,7 +1794,7 @@ AAAEC6442PQKevgYgeT0SIu9zwlnEMl6MF59ZgM+i0ByMv4eLJPqG3xnZcEQmktHj/GY2i
17901794

17911795
Expect(err).NotTo(HaveOccurred())
17921796
Expect(mockStderr.String()).To(Equal(""))
1793-
Expect(mockStdout.String()).To(ContainSubstring("No run files found"))
1797+
Expect(mockStdout.String()).To(ContainSubstring("No run files needed to be updated"))
17941798
})
17951799
})
17961800

0 commit comments

Comments
 (0)