Skip to content

Commit

Permalink
feat: [#137][#138][#140] Install Regal v0.29.2 and OPA v0.70.0 and ru…
Browse files Browse the repository at this point in the history
…n those tools using Task (#139)

* feat: Install OPA v0.70.0

* feat: [#138] Install Regal v0.29.2

* feat: [#140] Run OPA and Regal in pipeline

* feat: [#140] Run OPA from GOBIN
  • Loading branch information
sbp-bvanb authored Dec 2, 2024
1 parent fffca7f commit b680e04
Showing 1 changed file with 68 additions and 7 deletions.
75 changes: 68 additions & 7 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# deps: tasks that will be run in parallel
---
version: "3"

vars:
BUILD_TAGS: component,e2e,integration
COVERPROFILE: profile.cov
GCI_VERSION: 0.13.5
GCI: "{{.GOBIN}}/gci"
GCI_SECTIONS: '{{.GCI_SECTIONS | default "-s standard -s default"}}'
GCI_VERSION: 0.13.5
GOBIN: ~/go/bin
GOLANGCI_LINT_VERSION: 1.61.0
GOLANG_PARALLEL_TESTS:
sh: |
Expand All @@ -23,6 +24,10 @@ vars:
MOCKERY_BIN: "{{.GOPATH}}/bin/mockery"
MOCKERY_MAJOR_VERSION: v2
MOCKERY_VERSION: "{{.MOCKERY_MAJOR_VERSION}}.46.0"
OPA_FMT: "{{.GOBIN}}/opa fmt ."
OPA_VERSION: v0.70.0
REGAL: "{{.GOBIN}}/regal"
REGAL_VERSION: 0.29.2
SED_INSERT_ADDITION:
sh: |
if [ "$(uname -s)" = "Darwin" ]; then
Expand Down Expand Up @@ -97,7 +102,7 @@ tasks:
silent: true
cmds:
- |
if ! ~/go/bin/gci --version | grep -q "gci version {{.GCI_VERSION}}"; then
if ! {{.GCI}} --version | grep -q "gci version {{.GCI_VERSION}}"; then
go install github.com/daixiang0/gci@v{{.GCI_VERSION}}
fi
gci:
Expand All @@ -106,18 +111,18 @@ tasks:
cmds:
- task: gci-install
- |
if ~/go/bin/gci list --skip-generated {{.GCI_SECTIONS}} . | grep "\.go$"; then
if {{.GCI}} list --skip-generated {{.GCI_SECTIONS}} . | grep "\.go$"; then
echo "One or more golang files detected with: 'incorrect import order':"
echo " * Observe: '~/go/bin/gci diff --skip-generated .'"
echo " * Resolve: '~/go/bin/gci write --skip-generated .'"
echo " * Observe: '{{.GCI}} diff --skip-generated .'"
echo " * Resolve: '{{.GCI}} write --skip-generated .'"
exit 1
fi
gci-write:
desc: fix incorrect import order with gci
silent: true
cmds:
- task: gci-install
- ~/go/bin/gci write --skip-generated {{.GCI_SECTIONS}} .
- "{{.GCI}} write --skip-generated {{.GCI_SECTIONS}} ."
golangci-lint-install:
silent: true
cmds:
Expand Down Expand Up @@ -197,6 +202,62 @@ 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:
- |
if ! regal version | grep -q {{.REGAL_VERSION}}; then
# regal version installed using `go install` does not include
# version, see: https://github.com/StyraInc/regal/issues/1275
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 b680e04

Please sign in to comment.