From 7abfc0bb569547374374e4cce0089b41e1efabf3 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 21 Sep 2021 10:18:10 +1200 Subject: [PATCH] Improve taskfile slightly (#1742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Slight simplification of Taskfile * Don't output RBAC for Crossplane * Disambiguate variables go-task doesn’t work properly with dynamic variables in different directories, see: https://github.com/go-task/task/issues/524 Co-authored-by: Bevan Arps --- Taskfile.yml | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 87e913aa75e..d28c67a0781 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -265,11 +265,19 @@ tasks: cmds: - mkdir -p ./apis - find ./apis -type f -name "zz_generated.*" -delete - - if [ -d "./config/crd/bases" ]; then find "./config/crd/bases" -type f -delete; fi - - cd apis && controller-gen object:headerFile=../../boilerplate.go.txt paths="./..." || true - - cd apis && controller-gen {{.CRD_OPTIONS}} rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=../config/crd/bases output:webhook:artifacts:config=../config/webhook output:rbac:artifacts:config=../config/rbac + - if [ -d "{{.OUTPUT}}/crd/bases" ]; then find "{{.OUTPUT}}/crd/bases" -type f -delete; fi + - cd apis && controller-gen {{.OBJECT_OPTIONS}} paths=./... + - cd apis && controller-gen {{.CRD_OPTIONS}} {{.WEBHOOK_OPTIONS}} {{.RBAC_OPTIONS}} paths=./... vars: - CRD_OPTIONS: "crd:crdVersions=v1,allowDangerousTypes=true" + HEADER_FILE: + sh: 'realpath ../boilerplate.go.txt #controller:generate-crds' + OBJECT_OPTIONS: object:headerFile={{.HEADER_FILE}} + + OUTPUT: + sh: 'realpath config #controller:generate-crds' + CRD_OPTIONS: crd:crdVersions=v1,allowDangerousTypes=true output:crd:artifacts:config={{.OUTPUT}}/crd/bases + WEBHOOK_OPTIONS: webhook output:webhook:artifacts:config={{.OUTPUT}}/webhook + RBAC_OPTIONS: rbac:roleName=manager-role output:rbac:artifacts:config={{.OUTPUT}}/rbac controller:generate-genruntime-deepcopy: desc: Run controller-gen to generate {{.CONTROLLER_APP}} CRD files. @@ -278,8 +286,12 @@ tasks: - "pkg/genruntime/**/*.go" cmds: - find ./pkg/genruntime -type f -name "zz_generated.*" -delete - - cd pkg/genruntime && controller-gen object:headerFile=../../../boilerplate.go.txt paths="./..." || true + - cd pkg/genruntime && controller-gen {{.OBJECT_OPTIONS}} paths=./... - cd pkg/genruntime && gofmt -l -s -w . # We do this because controller-gen can generate these files in a way that isn't gofmt'ed which can break things down the line + vars: + HEADER_FILE: + sh: 'realpath ../boilerplate.go.txt #controller:generate-genruntime-deepcopy' + OBJECT_OPTIONS: object:headerFile={{.HEADER_FILE}} controller:generate-kustomize: desc: Run {{.GENERATOR_APP}} to generate the Kustomize file for registering CRDs. @@ -359,11 +371,19 @@ tasks: cmds: - mkdir -p ./apis - find ./apis -type f -name "zz_generated.*" -delete - - if [ -d "./config/crd/bases" ]; then find "./config/crd/bases" -type f -delete; fi - - cd apis && controller-gen object:headerFile=../../boilerplate.go.txt paths="./..." || true - - cd apis && controller-gen {{.CRD_OPTIONS}} rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=../config/crd/bases output:webhook:artifacts:config=../config/webhook + - if [ -d "{{.OUTPUT}}/crd/bases" ]; then find "{{.OUTPUT}}/crd/bases" -type f -delete; fi + - cd apis && controller-gen {{.OBJECT_OPTIONS}} paths=./... + - cd apis && controller-gen {{.CRD_OPTIONS}} {{.WEBHOOK_OPTIONS}} {{.RBAC_OPTIONS}} paths=./... vars: - CRD_OPTIONS: "crd:crdVersions=v1,allowDangerousTypes=true" + HEADER_FILE: + sh: 'realpath ../boilerplate.go.txt #crossplane:generate-crds' + OBJECT_OPTIONS: object:headerFile={{.HEADER_FILE}} + + OUTPUT: + sh: 'realpath config #crossplane:generate-crds' + CRD_OPTIONS: crd:crdVersions=v1,allowDangerousTypes=true output:crd:artifacts:config={{.OUTPUT}}/crd/bases + WEBHOOK_OPTIONS: webhook output:webhook:artifacts:config={{.OUTPUT}}/webhook + RBAC_OPTIONS: rbac:roleName=manager-role # output:rbac:artifacts:config={{.OUTPUT}}/rbac # not output currently? crossplane:generate-types: desc: Run {{.GENERATOR_APP}} to generate input files for controller-gen for {{.CROSSPLANE_APP}}.