diff --git a/Makefile b/Makefile index 54f2db53..c694dedb 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,7 @@ reporter-multiarch-img: cmd/reporter/Dockerfile.reporter ### Codegen codegen: - @./hack/codegen.sh + @./hack/update-codegen.sh ### CRDs generate-crds: @@ -142,7 +142,7 @@ clean: ### Misc generate-swagger-doc: - @cd pkg/apis/core/v1/tool && ./update-generated-swagger-docs.sh + @./hack/update-swagger-docs.sh all-generators: codegen generate-crds generate-swagger-doc diff --git a/pkg/apis/boilerplate.txt b/hack/boilerplate.txt similarity index 100% rename from pkg/apis/boilerplate.txt rename to hack/boilerplate.txt diff --git a/hack/codegen.sh b/hack/codegen.sh deleted file mode 100755 index 38f38bb3..00000000 --- a/hack/codegen.sh +++ /dev/null @@ -1,10 +0,0 @@ -if [ ! -d "../code-generator" ]; then - echo "Please get code-generator from fission org" - exit 1 -fi - -export GOPATH=$(go env GOPATH) -../code-generator/generate-groups.sh all \ - github.com/fission/fission/pkg/generated \ - github.com/fission/fission/pkg/apis "core:v1" \ - --go-header-file ./pkg/apis/boilerplate.txt diff --git a/hack/lib/init.sh b/hack/lib/init.sh new file mode 100644 index 00000000..9181abff --- /dev/null +++ b/hack/lib/init.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +API_GROUP_VERSIONS=" +core/v1 +" +API_PACKAGES=" +" \ No newline at end of file diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh new file mode 100755 index 00000000..6a2a8465 --- /dev/null +++ b/hack/update-codegen.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +if [ ! -d "../code-generator" ]; then + echo "Please get code-generator from fission org" + exit 1 +fi + +SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} + +bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \ + github.com/fission/fission/pkg/generated \ + github.com/fission/fission/pkg/apis \ + "core:v1" \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \ + --go-header-file "$(dirname "${BASH_SOURCE[0]}")/boilerplate.txt" diff --git a/hack/update-swagger-docs.sh b/hack/update-swagger-docs.sh new file mode 100755 index 00000000..7105a1e6 --- /dev/null +++ b/hack/update-swagger-docs.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +source "$(dirname "${BASH_SOURCE}")/lib/init.sh" + +SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. + +# Generates types_swagger_doc_generated file for the given group version. +# $1: Name of the group version +# $2: Path to the directory where types.go for that group version exists. This +# is the directory where the file will be generated. +kube::swagger::gen_types_swagger_doc() { + local group_version=$1 + local gv_dir=$2 + local TMPFILE="${TMPDIR:-/tmp}/zz_generated.swagger_doc_generated.$(date +%s).go" + + echo "Generating swagger type docs for ${group_version} at ${gv_dir}" + + sed 's/YEAR/2017/' hack/boilerplate.txt > "$TMPFILE" + echo "package ${group_version##*/}" >> "$TMPFILE" + cat >> "$TMPFILE" <> "$TMPFILE" + + echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "$TMPFILE" + + gofmt -w -s "$TMPFILE" + mv "$TMPFILE" ""${gv_dir}"/zz_generated.swagger_doc_generated.go" +} + +util::group-version-to-pkg-path() { + local group_version="$1" + echo "pkg/apis/${group_version}" +} + +for gv in ${API_GROUP_VERSIONS}; do + rm -f "${SCRIPT_ROOT}/${gv}/zz_generated.swagger_doc_generated.go" + util::group-version-to-pkg-path "${gv}" + kube::swagger::gen_types_swagger_doc "${gv}" "$(util::group-version-to-pkg-path "${gv}")" +done diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh deleted file mode 100755 index 5577d1b9..00000000 --- a/hack/verify-gofmt.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -find_files() { - find . -not \( \ - \( \ - -wholename '*/vendor/*' \ - \) -prune \ - \) -name '*.go' -} - -GOFMT="gofmt -s" -bad_files=$(find_files | xargs $GOFMT -l) -if [[ -n "${bad_files}" ]]; then - echo "!!! '$GOFMT' needs to be run on the following files: " - echo "${bad_files}" - exit 1 -fi diff --git a/hack/verify-govet.sh b/hack/verify-govet.sh deleted file mode 100755 index 8e8c2af2..00000000 --- a/hack/verify-govet.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -go vet -v $(go list ./...| grep -v "vendor" | grep -v "examples" | grep -v "genclient" | grep -v "demos" | grep -v "test") diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh deleted file mode 100755 index 398d0a93..00000000 --- a/hack/verify-staticcheck.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -go list ./...| grep -v vendor | grep -v "examples" | grep -v "demos" | grep -v "genclient" | grep -v "test" | xargs -I@ staticcheck @ diff --git a/pkg/apis/core/v1/tool/README.md b/pkg/apis/core/v1/tool/README.md deleted file mode 100644 index f3f4092d..00000000 --- a/pkg/apis/core/v1/tool/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# How to update swagger (OpenAPI) struct description - -Run `update-generated-swagger-docs.sh` and it will parse all comments in `types.go`. - -```bash -./update-generated-swagger-docs.sh -``` diff --git a/pkg/apis/core/v1/tool/boilerplate.generatego.txt b/pkg/apis/core/v1/tool/boilerplate.generatego.txt deleted file mode 100644 index ebeae43a..00000000 --- a/pkg/apis/core/v1/tool/boilerplate.generatego.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* -Copyright 2019 The Fission Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ diff --git a/pkg/apis/core/v1/tool/swagger.sh b/pkg/apis/core/v1/tool/swagger.sh deleted file mode 100755 index d8e83387..00000000 --- a/pkg/apis/core/v1/tool/swagger.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2016 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -# Please refer https://github.com/kubernetes/kubernetes/tree/master/hack for original file -# - -# Contains swagger related util functions. -# -set -o errexit -set -o nounset -set -o pipefail - -# Generates types_swagger_doc_generated file for the given group version. -# $1: Name of the group version -# $2: Path to the directory where types.go for that group version exists. This -# is the directory where the file will be generated. -kube::swagger::gen_types_swagger_doc() { - local group_version=$1 - local gv_dir=$2 - local TMPFILE - TMPFILE="${TMPDIR:-/tmp}/types_swagger_doc_generated.$(date +%s).go" - - echo "Generating swagger type docs for ${group_version} at ${gv_dir}" - - { - echo -e "$(cat boilerplate.generatego.txt)\n" - echo "package ${group_version##*/}" - cat < "${TMPFILE}" - - go run ./swagger_type_docs.go -s \ - "${gv_dir}/types.go" \ - -f - \ - >> "${TMPFILE}" - - echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${TMPFILE}" - - gofmt -w -s "${TMPFILE}" - mv "${TMPFILE}" "${gv_dir}/types_swagger_doc_generated.go" -} diff --git a/pkg/apis/core/v1/tool/update-generated-swagger-docs.sh b/pkg/apis/core/v1/tool/update-generated-swagger-docs.sh deleted file mode 100755 index 783ef719..00000000 --- a/pkg/apis/core/v1/tool/update-generated-swagger-docs.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2015 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generates `types_swagger_doc_generated.go` files for API group -# versions. That file contains functions on API structs that return -# the comments that should be surfaced for the corresponding API type -# in our API docs. - - -# -# Please refer https://github.com/kubernetes/kubernetes/tree/master/hack for original file -# - -set -o errexit -set -o nounset -set -o pipefail - -FISSION_CRD_VERSION=v1 - -source "swagger.sh" - -# To avoid compile errors, remove the currently existing files. - -for group_version in "${FISSION_CRD_VERSION}"; do - kube::swagger::gen_types_swagger_doc "${group_version}" ../../${FISSION_CRD_VERSION} -done diff --git a/pkg/apis/core/v1/types_swagger_doc_generated.go b/pkg/apis/core/v1/zz_generated.swagger_doc_generated.go similarity index 99% rename from pkg/apis/core/v1/types_swagger_doc_generated.go rename to pkg/apis/core/v1/zz_generated.swagger_doc_generated.go index 14641190..27e85bab 100644 --- a/pkg/apis/core/v1/types_swagger_doc_generated.go +++ b/pkg/apis/core/v1/zz_generated.swagger_doc_generated.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Fission Authors. +Copyright The Fission Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - package v1 // This file contains a collection of methods that can be used from go-restful to @@ -24,9 +23,8 @@ package v1 // they are on one line! For multiple line or blocks that you want to ignore use ---. // Any context after a --- is ignored. // -// Those methods can be generated by using hack/update-generated-swagger-docs.sh - -// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT. +// Those methods can be generated by using hack/update-swagger-docs.sh +// AUTO-GENERATED FUNCTIONS START HERE var map_Archive = map[string]string{ "": "Archive contains or references a collection of source or binary files.", "type": "Type defines how the package is specified: literal or URL. Available value:\n - literal\n - url", diff --git a/pkg/apis/core/v1/tool/swagger_type_docs.go b/tools/genswaggertypedocs/swagger_type_docs.go similarity index 93% rename from pkg/apis/core/v1/tool/swagger_type_docs.go rename to tools/genswaggertypedocs/swagger_type_docs.go index 184c3d18..49215ff9 100644 --- a/pkg/apis/core/v1/tool/swagger_type_docs.go +++ b/tools/genswaggertypedocs/swagger_type_docs.go @@ -1,12 +1,9 @@ /* Copyright 2015 The Kubernetes Authors. - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,10 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// -// Please refer https://github.com/kubernetes/kubernetes/blob/master/cmd/genswaggertypedocs/swagger_type_docs.go for original file -// - +// lifted from k8s.io/kubernetes so we can add methods to types package main import (