Skip to content

Commit

Permalink
linters+testdata: Reformat all yaml testcases for linting. (open-poli…
Browse files Browse the repository at this point in the history
…cy-agent#6511)

This commit adds a config for yamllint, mass-reformats all of
the existing Yaml testcases to pass linting, and adds a Yaml
linting job to the pull-request Github Actions workflow. A few 
careful exceptions and ignores were added to the linter's
config to allow keeping our existing Yaml files with minimal
reformatting.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Jan 10, 2024
1 parent 018b8ad commit 63e1877
Show file tree
Hide file tree
Showing 1,140 changed files with 31,838 additions and 30,597 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/pull-request.yaml
Expand Up @@ -128,6 +128,19 @@ jobs:
run: make check
timeout-minutes: 30

yaml-lint:
name: YAML Lint
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4

- name: YAML Style and Lint Check
run: make check-yaml-tests
timeout-minutes: 30
env:
YAML_LINT_FORMAT: github

wasm:
name: WASM
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -291,7 +304,6 @@ jobs:
env:
DOCKER_RUNNING: 0


# Run PR metadata against Rego policies
rego-check-pr:
name: Rego PR checks
Expand All @@ -315,7 +327,7 @@ jobs:
run: |
curl --silent --fail --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -o files.json \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files
opa eval -d build/policy/files.rego -d build/policy/helpers.rego --format values --input files.json \
--fail-defined 'data.files.deny[message]'
env:
Expand Down
12 changes: 12 additions & 0 deletions .yamllint.yaml
@@ -0,0 +1,12 @@
extends: default

rules:
# Some of our testcases end up going past the default 80 character limit.
line-length: false
braces:
max-spaces-inside: 1
comments:
min-spaces-from-content: 1
indentation:
ignore:
- test-time-*
10 changes: 10 additions & 0 deletions Makefile
Expand Up @@ -29,6 +29,8 @@ GO_TAGS = -tags=opa_wasm
endif

GOLANGCI_LINT_VERSION := v1.51.0
YAML_LINT_VERSION := 0.29.0
YAML_LINT_FORMAT ?= auto

DOCKER_RUNNING ?= $(shell docker ps >/dev/null 2>&1 && echo 1 || echo 0)

Expand Down Expand Up @@ -474,6 +476,14 @@ check-go-module:
$(RELEASE_BUILD_IMAGE) \
/bin/bash -c "git config --system --add safe.directory /src && go mod vendor -v"

.PHONY: check-yaml-tests
check-yaml-tests:
ifeq ($(DOCKER_RUNNING), 1)
docker run --rm -v $(shell pwd):/data:ro,Z -w /data pipelinecomponents/yamllint:${YAML_LINT_VERSION} yamllint -f $(YAML_LINT_FORMAT) test/cases/testdata
else
@echo "Docker not installed or running. Skipping yamllint run."
endif

######################################################
#
# Release targets
Expand Down
5 changes: 5 additions & 0 deletions docs/content/contrib-development.md
Expand Up @@ -15,6 +15,7 @@ Requirements:
- GitHub account (if you are contributing)
- Go (version 1.15+ is supported though older versions are likely to work)
- GNU Make
- Python3, pip, yamllint (if linting YAML files manually)

## Getting Started

Expand Down Expand Up @@ -71,6 +72,10 @@ git rebase upstream/main
> Be sure to run `make check` before submitting your pull request. You
> may need to run `go fmt` on your code to make it comply with standard Go
> style.
> For YAML files, you may need to run the `yamllint` tool on the
> `test/cases/testdata` folder to make sure any new tests are well-formatted.
> If you have Docker available, you can run `make check-yaml-tests` to
> run `yamllint` on the tests without installing any Python dependencies.

### Submission
Expand Down
39 changes: 20 additions & 19 deletions test/cases/testdata/aggregates/test-aggregates-0001.yaml
@@ -1,21 +1,22 @@
---
cases:
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
p[x] {
__local0__ = data.a
count(__local0__, x)
}
note: aggregates/count
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 4
p[x] {
__local0__ = data.a
count(__local0__, x)
}
note: aggregates/count
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 4
45 changes: 23 additions & 22 deletions test/cases/testdata/aggregates/test-aggregates-0002.yaml
@@ -1,25 +1,26 @@
---
cases:
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
p[x] {
__local0__ = [y | data.generated.q[y]]
count(__local0__, x)
}
p[x] {
__local0__ = [y | data.generated.q[y]]
count(__local0__, x)
}
q[x] {
x = data.a[_]
}
note: aggregates/count virtual
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 4
q[x] {
x = data.a[_]
}
note: aggregates/count virtual
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 4
35 changes: 18 additions & 17 deletions test/cases/testdata/aggregates/test-aggregates-0003.yaml
@@ -1,19 +1,20 @@
---
cases:
- data:
b:
v1: hello
v2: goodbye
modules:
- |
package generated
- data:
b:
v1: hello
v2: goodbye
modules:
- |
package generated
p[x] {
__local0__ = data.b
count(__local0__, x)
}
note: aggregates/count keys
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 2
p[x] {
__local0__ = data.b
count(__local0__, x)
}
note: aggregates/count keys
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 2
41 changes: 21 additions & 20 deletions test/cases/testdata/aggregates/test-aggregates-0004.yaml
@@ -1,23 +1,24 @@
---
cases:
- data:
b:
v1: hello
v2: goodbye
modules:
- |
package generated
- data:
b:
v1: hello
v2: goodbye
modules:
- |
package generated
p[x] {
__local0__ = [k | data.generated.q[k] = _]
count(__local0__, x)
}
p[x] {
__local0__ = [k | data.generated.q[k] = _]
count(__local0__, x)
}
q[k] = v {
data.b[k] = v
}
note: aggregates/count keys virtual
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 2
q[k] = v {
data.b[k] = v
}
note: aggregates/count keys virtual
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 2
41 changes: 21 additions & 20 deletions test/cases/testdata/aggregates/test-aggregates-0005.yaml
@@ -1,23 +1,24 @@
---
cases:
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
- data:
a:
- 1
- 2
- 3
- 4
modules:
- |
package generated
p = x {
__local0__ = data.generated.q
count(__local0__, x)
}
p = x {
__local0__ = data.generated.q
count(__local0__, x)
}
q[x] {
x = data.a[_]
}
note: aggregates/count set
query: data.generated.p = x
want_result:
- x: 4
q[x] {
x = data.a[_]
}
note: aggregates/count set
query: data.generated.p = x
want_result:
- x: 4
27 changes: 14 additions & 13 deletions test/cases/testdata/aggregates/test-aggregates-0006.yaml
@@ -1,15 +1,16 @@
---
cases:
- data: {}
modules:
- |
package generated
- data: {}
modules:
- |
package generated
p[x] {
sum([1, 2, 3, 4], x)
}
note: aggregates/sum
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 10
p[x] {
sum([1, 2, 3, 4], x)
}
note: aggregates/sum
query: data.generated.p = x
sort_bindings: true
want_result:
- x:
- 10
23 changes: 12 additions & 11 deletions test/cases/testdata/aggregates/test-aggregates-0007.yaml
@@ -1,13 +1,14 @@
---
cases:
- data: {}
modules:
- |
package generated
- data: {}
modules:
- |
package generated
p = x {
sum({1, 2, 3, 4}, x)
}
note: aggregates/sum set
query: data.generated.p = x
want_result:
- x: 10
p = x {
sum({1, 2, 3, 4}, x)
}
note: aggregates/sum set
query: data.generated.p = x
want_result:
- x: 10

0 comments on commit 63e1877

Please sign in to comment.