File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff 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.
5973func (m * Yamllint ) Check (
6074 // source is an optional argument that specifies a directory.
Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change @@ -27,11 +27,29 @@ type Yamllinttest struct{}
2727func (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.
3654func (m * Yamllinttest ) Check (ctx context.Context ) error {
3755
File renamed without changes.
You can’t perform that action at this time.
0 commit comments