Skip to content

Commit

Permalink
Switch from JQ to itchyny/gojq
Browse files Browse the repository at this point in the history
Signed-off-by: Moulick Aggarwal <[email protected]>
  • Loading branch information
Moulick committed Feb 12, 2023
1 parent f06591c commit c253dcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ jobs:
go-version: '1.20'
check-latest: true
cache: true
- run: go mod tidy && git diff --exit-code go.mod go.sum
- run: make generate manifests && git diff --exit-code api/ config/ controllers/
- run: make bundle && git diff --exit-code jsonnet/
- run: make envtest
- run: make test COVER_FILE=cover.out
- name: Check go mod tidy
run: go mod tidy && git diff --exit-code go.mod go.sum
- name: Check missing auto-generated manifests
run: make generate manifests && git diff --exit-code api/ config/ controllers/
- name: Download envtest-setup
run: make envtest
- name: Run tests
run: make test COVER_FILE=cover.out
- name: Check missing changes to jsonnet-crd
run: make jsonnet-crd && git diff --exit-code jsonnet/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
YQ ?= $(LOCALBIN)/yq
GOJQ ?= $(LOCALBIN)/gojq
GINKGO ?= $(LOCALBIN)/ginkgo
JSONNET ?= $(LOCALBIN)/jsonnet
JSONNET_FMT ?= $(LOCALBIN)/jsonnetfmt
Expand All @@ -40,6 +41,7 @@ CONTROLLER_GEN_VERSION ?= v0.7.0
JSONNET_VERSION ?= v0.19.1
YQ_VERSION ?= v4.30.8
GINKGO_VERSION ?= v2.8.0
GOJQ_VERSION ?= v0.12.11

.PHONY: all
all: build
Expand Down Expand Up @@ -86,7 +88,6 @@ test: manifests generate fmt vet envtest ginkgo ## Run tests.
##@ Build

.PHONY: build
# build: generate fmt vet jsonnet-crd ## Build manager binary.
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager main.go

Expand Down Expand Up @@ -120,8 +121,8 @@ crds: manifests kustomize ## Generate CRDs into the bin directory.
$(KUSTOMIZE) build config/crd > $(CRD_OUT)

.PHONY: jsonnet-crd
jsonnet-crd: yq jsonnet crds ## Generate CRDs in the form of jsonnet files.
$(YQ) eval -I=0 $(CRD_OUT) -o=json | jq -s . | $(JSONNET) - | $(JSONNET_FMT) --max-blank-lines 1 - -o jsonnet/crds.libsonnet
jsonnet-crd: yq gojq jsonnet crds ## Generate CRDs in the form of jsonnet files.
$(YQ) eval -I=0 $(CRD_OUT) -o=json | $(GOJQ) -s . | $(JSONNET) - | $(JSONNET_FMT) --max-blank-lines 1 - -o jsonnet/crds.libsonnet

.PHONY: bundle
bundle: jsonnet-crd ## Generate deployment files into the bin directory.
Expand Down Expand Up @@ -174,7 +175,7 @@ jsonnet: $(LOCALBIN) ## Download jsonnet locally if necessary.
if [ $(JSONNET_VERSION) = $(word 6,$(shell $(JSONNET) --version)) ]; then \
echo "Correct version of Jsonnet is already installed"; \
else \
echo "Wrong version of Jsonnet is installed, reinstalling new"; \
echo "Wrong version of Jsonnet is installed, reinstalling version $(JSONNET_VERSION)"; \
GOBIN=$(LOCALBIN) go install github.com/google/go-jsonnet/cmd/...@$(JSONNET_VERSION); \
echo "Jsonnet installed"; \
fi \
Expand All @@ -190,7 +191,7 @@ yq: $(LOCALBIN) ## Download yq locally if necessary.
if [ $(YQ_VERSION) = $(word 4,$(shell $(YQ) --version)) ]; then \
echo "Correct version of yq is already installed"; \
else \
echo "Wrong version of yq is installed, reinstalling new"; \
echo "Wrong version of yq is installed, reinstalling version $(YQ_VERSION)"; \
GOBIN=$(shell pwd)/bin go install github.com/mikefarah/yq/v4@$(YQ_VERSION); \
echo "yq installed"; \
fi \
Expand All @@ -200,6 +201,22 @@ yq: $(LOCALBIN) ## Download yq locally if necessary.
echo "yq installed"; \
fi

.PHONY: gojq
gojq: $(LOCALBIN) ## Download gojq locally if necessary.
if test -s $(JQ); then \
if [ $(GOJQ_VERSION) = v$(word 2,$(shell $(GOJQ) --version)) ]; then \
echo "Correct version of gojq is already installed"; \
else \
echo "Wrong version of gojq is installed, reinstalling version $(GOJQ_VERSION)"; \
GOBIN=$(shell pwd)/bin go install github.com/itchyny/gojq/cmd/gojq@$(GOJQ_VERSION); \
echo "gojq installed"; \
fi \
else \
echo "gojq not installed, installing version $(YQ_VERSION)"; \
GOBIN=$(shell pwd)/bin go install github.com/itchyny/gojq/cmd/gojq@$(GOJQ_VERSION); \
echo "gojq installed"; \
fi

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
Expand Down

0 comments on commit c253dcd

Please sign in to comment.