Skip to content

Commit

Permalink
feat: [#140] Run OPA and Regal in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-bvanb committed Nov 29, 2024
1 parent 61384d0 commit a7bc70f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -201,13 +202,38 @@ 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:
- |
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:
Expand All @@ -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
Expand Down

0 comments on commit a7bc70f

Please sign in to comment.