Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions yamllint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ func (m *Yamllint) Container() *dagger.Container {
return m.Ctr
}

// CheckWithConfig runs the yamllint command with a configuration file.
func (m *Yamllint) CheckWithConfig(
// source is an optional argument that specifies a directory.
source *dagger.Directory,
// file is an optional argument that specifies yamllint configuration file.
file *dagger.File,
) *dagger.Container {
return m.Container().
WithMountedDirectory("/tmp", source).
WithWorkdir("/tmp").
WithFile("/.config/.yamllint", file).
WithExec([]string{"sh", "-c", "find . -type f \\( -name '*.yaml' -o -name '*.yml' \\) -print0 | xargs -0 yamllint -c /.config/.yamllint"})
}

// Check runs yamllint on the provided source directory.
func (m *Yamllint) Check(
// source is an optional argument that specifies a directory.
Expand Down
5 changes: 1 addition & 4 deletions yamllint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func Test_yamllint(t *testing.T) {
_, err := container.
WithMountedDirectory("/tmp", c.Host().Directory("./test/testdata")).
WithWorkdir("/tmp").
WithExec([]string{"yamllint",
"--config-file",
".yamllint",
"."}).
WithExec([]string{"sh", "-c", "find . -type f \\( -name '*.yaml' -o -name '*.yml' \\) -print0 | xargs -0 yamllint -c /tmp/.config/.yamllint"}).
Stderr(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "exit code: 1")
Expand Down
18 changes: 18 additions & 0 deletions yamllint/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,29 @@ type Yamllinttest struct{}
func (m *Yamllinttest) All(ctx context.Context) error {
p := pool.New().WithErrors().WithContext(ctx)

p.Go(m.CheckWithConfig)
p.Go(m.Check)

return p.Wait()
}

// CheckWithConfig runs the yamllint command with a configuration file.
func (m *Yamllinttest) CheckWithConfig(ctx context.Context) error {

dir := dag.CurrentModule().Source().Directory("./testdata")
file := dag.CurrentModule().Source().File("./testdata/.config/.yamllint")
_, err := dag.Yamllint().CheckWithConfig(dir, file).Stderr(ctx)

if err != nil {
re := regexp.MustCompile("exit code: 123")
if re.MatchString(err.Error()) {
return nil
}
}

return err
}

// Check runs the revive command.
func (m *Yamllinttest) Check(ctx context.Context) error {

Expand Down
Loading