Feat: add gen-cue to Makefile (#6009)

Signed-off-by: iyear <ljyngup@gmail.com>
This commit is contained in:
iyear
2023-05-19 14:44:10 +08:00
committed by GitHub
parent 933d85c735
commit ff79438c8f
2 changed files with 46 additions and 1 deletions

40
hack/cuegen/cuegen.sh Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -e
# Usage: cuegen.sh dir [flagsToVela]
# Example: cuegen.sh references/cuegen/generators/provider/testdata/ \
# -t provider \
# --types *k8s.io/apimachinery/pkg/apis/meta/v1/unstructured.Unstructured=ellipsis
# check vela binary
if ! [ -x "$(command -v vela)" ]; then
echo "Please put vela binary in the PATH"
exit 1
fi
# get dir from first arg
dir="$1"
if [ -z "$dir" ]; then
echo "Please provide a directory"
exit 1
fi
echo "Generating CUE files from go files in $dir"
echo "========"
find "$dir" -name "*.go" | while read -r file; do
echo "- Generating CUE file for $file"
# redirect output if command exits successfully
(out=$(vela def gen-cue ${*:2} "$file") && echo "$out" > "${file%.go}".cue) &
done
echo "========"
echo "Waiting for all background processes to finish"
wait
sleep 5s # wait for all stderr to be printed
echo "Done"

View File

@@ -24,4 +24,9 @@ core-debug-run: fmt vet manifests
# Run against the configured Kubernetes cluster in ~/.kube/config # Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: core-run .PHONY: core-run
core-run: fmt vet manifests core-run: fmt vet manifests
go run ./cmd/core/main.go go run ./cmd/core/main.go
## gen-cue: Generate CUE files from Go files. Variable DIR is the directory of the Go files, FLAGS is the flags for vela def gen-cue command.
.PHONY: gen-cue
gen-cue:
./hack/cuegen/cuegen.sh $(DIR) $(FLAGS)