Skip to content

Commit

Permalink
Grep: add skip-not-found option (#45)
Browse files Browse the repository at this point in the history
This option can be set to true to consider the test successful if the
targeted path does not exist in the grep module.

Signed-off-by: Mathieu Corbin <[email protected]>
  • Loading branch information
mcorbin authored Dec 12, 2023
1 parent d90e89c commit a49dac0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jobs:
registry-type: public
mask-password: 'true'

- name: Downgrade Helm # 1.13.0 has bug that block push charts on OCI
run: |
curl -sSLo /tmp/helm.tar.gz "https://get.helm.sh/helm-v3.12.0-linux-amd64.tar.gz" && \
tar --strip-components=1 -C /tmp -xzvf /tmp/helm.tar.gz linux-amd64/helm && \
mv /tmp/helm /usr/local/bin/helm && \
rm -f /tmp/helm.tar.gz
- name: Helm release
run: |
RELEASE_VERSION=$(jq -r .tag dist/metadata.json)
Expand Down
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ type FileRule struct {
}

type GrepRule struct {
Path string `validate:"required"`
Recursive bool
Pattern string `validate:"required"`
Match bool
Path string `validate:"required"`
Recursive bool
Pattern string `validate:"required"`
Match bool
SkipNotFound bool `yaml:"skip-not-found"`
}

type Check struct {
Expand Down
24 changes: 16 additions & 8 deletions pkg/ruler/rules/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,37 @@ import (
"context"
"errors"
"fmt"
"os"
"os/exec"

"github.com/qonto/standards-insights/config"
"github.com/qonto/standards-insights/pkg/project"
)

type GrepRule struct {
Path string
Recursive bool
Pattern string
Match bool
Path string
Recursive bool
Pattern string
Match bool
SkipNotFound bool
}

func NewGrepRule(config config.GrepRule) *GrepRule {
return &GrepRule{
Path: config.Path,
Recursive: config.Recursive,
Pattern: config.Pattern,
Match: config.Match,
Path: config.Path,
Recursive: config.Recursive,
Pattern: config.Pattern,
Match: config.Match,
SkipNotFound: config.SkipNotFound,
}
}

func (rule *GrepRule) Do(ctx context.Context, project project.Project) error {
_, err := os.Stat(project.Path)
isNotExist := os.IsNotExist(err)
if isNotExist && rule.SkipNotFound {
return nil
}
arguments := []string{}
if rule.Recursive {
arguments = append(arguments, "-r")
Expand Down
9 changes: 9 additions & 0 deletions pkg/ruler/rules/grep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func TestGrepRule(t *testing.T) {
Match: true,
},
},
{
rule: rules.GrepRule{
Path: "_testdata",
Recursive: true,
Pattern: "abcdefg",
Match: true,
SkipNotFound: true,
},
},
{
rule: rules.GrepRule{
Path: "_testdata",
Expand Down

0 comments on commit a49dac0

Please sign in to comment.