From a7bc70fa3e246207efe9ffb1b30ae8259d267efa Mon Sep 17 00:00:00 2001 From: sbp-bvanb Date: Fri, 29 Nov 2024 23:08:40 +0100 Subject: [PATCH] feat: [#140] Run OPA and Regal in pipeline --- Taskfile.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index cf673ca..696975f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -24,6 +24,7 @@ vars: MOCKERY_BIN: "{{.GOPATH}}/bin/mockery" MOCKERY_MAJOR_VERSION: v2 MOCKERY_VERSION: "{{.MOCKERY_MAJOR_VERSION}}.46.0" + OPA_FMT: opa fmt . OPA_VERSION: v0.70.0 REGAL: "{{.GOBIN}}/regal" REGAL_VERSION: 0.29.2 @@ -201,6 +202,18 @@ tasks: --name {{.MOCK_GENERATE_INTERFACE_NAME}} \ --output {{.MOCK_GENERATE_DIR}}/mocks \ --tags {{.BUILD_TAGS}} + opa-fmt: + desc: check formatting rego files using opa + silent: true + cmds: + - task: opa-install + - "{{.OPA_FMT}}" + opa-fmt-write: + desc: apply formatting rego files using opa + silent: true + cmds: + - task: opa-install + - "{{.OPA_FMT}} --write" opa-install: silent: true cmds: @@ -208,6 +221,19 @@ tasks: if ! opa version | grep -q {{.OPA_VERSION}}; then go install github.com/open-policy-agent/opa@{{.OPA_VERSION}} fi + opa-run: + silent: true + cmds: + - | + for dir in $(find . -type f -name '*.rego' -exec dirname {} \; | sort -u); do + echo "Running opa test in directory: $dir" && (cd "$dir" && opa test . -v) + done + opa: + desc: run opa + silent: true + cmds: + - task: opa-install + - task: opa-run regal-install: silent: true cmds: @@ -218,6 +244,20 @@ tasks: curl -L -o {{.REGAL}} https://github.com/StyraInc/regal/releases/download/v{{.REGAL_VERSION}}/regal_Darwin_arm64 chmod +x {{.REGAL}} fi + regal-run: + silent: true + cmds: + - | + if ! regal lint .; then + echo "regal linting failed. Run: 'task remote:opa-fmt-write' to fix the issue" + exit 1 + fi + regal: + desc: run regal + silent: true + cmds: + - task: regal-install + - task: regal-run test: desc: run unit tests silent: true