Skip to content

Commit d98790b

Browse files
feat: Add CheckWithConfig functions
1 parent b75d061 commit d98790b

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

yamllint/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ func (m *Yamllint) Container() *dagger.Container {
5555
return m.Ctr
5656
}
5757

58+
// CheckWithConfig runs the yamllint command with a configuration file.
59+
func (m *Yamllint) CheckWithConfig(
60+
// source is an optional argument that specifies a directory.
61+
source *dagger.Directory,
62+
// file is an optional argument that specifies yamllint configuration file.
63+
file *dagger.File,
64+
) *dagger.Container {
65+
return m.Container().
66+
WithMountedDirectory("/tmp", source).
67+
WithWorkdir("/tmp").
68+
WithFile("/.config/.yamllint", file).
69+
WithExec([]string{"sh", "-c", "find . -type f \\( -name '*.yaml' -o -name '*.yml' \\) -print0 | xargs -0 yamllint -c /.config/.yamllint"})
70+
}
71+
5872
// Check runs yamllint on the provided source directory.
5973
func (m *Yamllint) Check(
6074
// source is an optional argument that specifies a directory.

yamllint/main_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ func Test_yamllint(t *testing.T) {
3737
_, err := container.
3838
WithMountedDirectory("/tmp", c.Host().Directory("./test/testdata")).
3939
WithWorkdir("/tmp").
40-
WithExec([]string{"yamllint",
41-
"--config-file",
42-
".yamllint",
43-
"."}).
40+
WithExec([]string{"sh", "-c", "find . -type f \\( -name '*.yaml' -o -name '*.yml' \\) -print0 | xargs -0 yamllint -c /tmp/.config/.yamllint"}).
4441
Stderr(ctx)
4542
require.Error(t, err)
4643
require.Contains(t, err.Error(), "exit code: 1")

yamllint/test/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,29 @@ type Yamllinttest struct{}
2727
func (m *Yamllinttest) All(ctx context.Context) error {
2828
p := pool.New().WithErrors().WithContext(ctx)
2929

30+
p.Go(m.CheckWithConfig)
3031
p.Go(m.Check)
3132

3233
return p.Wait()
3334
}
3435

36+
// CheckWithConfig runs the yamllint command with a configuration file.
37+
func (m *Yamllinttest) CheckWithConfig(ctx context.Context) error {
38+
39+
dir := dag.CurrentModule().Source().Directory("./testdata")
40+
file := dag.CurrentModule().Source().File("./testdata/.config/.yamllint")
41+
_, err := dag.Yamllint().CheckWithConfig(dir, file).Stderr(ctx)
42+
43+
if err != nil {
44+
re := regexp.MustCompile("exit code: 123")
45+
if re.MatchString(err.Error()) {
46+
return nil
47+
}
48+
}
49+
50+
return err
51+
}
52+
3553
// Check runs the revive command.
3654
func (m *Yamllinttest) Check(ctx context.Context) error {
3755

File renamed without changes.

0 commit comments

Comments
 (0)