From f35889722f39c01345e95d20d48bae02a342dd42 Mon Sep 17 00:00:00 2001 From: lonelyCZ <531187475@qq.com> Date: Wed, 22 Sep 2021 11:12:33 +0800 Subject: [PATCH] feature: add check-license-header script to github action --- .github/workflows/ci.yaml | 8 +++++ hack/make-rules/build-e2e.sh | 14 ++++++++ hack/make-rules/check_license.sh | 32 +++++++++++++++++++ hack/make-rules/generate_client.sh | 14 ++++++++ hack/make-rules/genyaml.sh | 14 ++++++++ pkg/controller/apis/config/types.go | 16 ++++++++++ .../constants/yurt-app-manager-tmpl.go | 16 ++++++++++ pkg/yurthub/healthchecker/node_lease_test.go | 16 ++++++++++ pkg/yurthub/kubernetes/rest/config_test.go | 16 ++++++++++ 9 files changed, 146 insertions(+) create mode 100755 hack/make-rules/check_license.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2add7cf7731..49622456b72 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,6 +22,14 @@ env: jobs: + check-license: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run Check License + run: hack/make-rules/check_license.sh + golangci-lint: runs-on: ubuntu-18.04 steps: diff --git a/hack/make-rules/build-e2e.sh b/hack/make-rules/build-e2e.sh index 379c5a8e1f5..521818e715e 100755 --- a/hack/make-rules/build-e2e.sh +++ b/hack/make-rules/build-e2e.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# Copyright 2020 The OpenYurt 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. + YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" source "${YURT_ROOT}/hack/lib/init.sh" diff --git a/hack/make-rules/check_license.sh b/hack/make-rules/check_license.sh new file mode 100755 index 00000000000..160435adcb9 --- /dev/null +++ b/hack/make-rules/check_license.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Copyright 2020 The OpenYurt 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. + +# exit immediately when a command fails +set -e +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail +# error on unset variables +set -u + +licRes=$( + find . -type f -regex '.*\.go\|.*\.sh' ! -path '*/vendor/*' -exec \ + sh -c 'head -n4 $1 | grep -Eq "(Copyright|generated|GENERATED)" || echo -e $1' {} {} \; +) + +if [ -n "${licRes}" ]; then + echo -e "license header checking failed:\\n${licRes}" + exit 255 +fi \ No newline at end of file diff --git a/hack/make-rules/generate_client.sh b/hack/make-rules/generate_client.sh index f290c6d7403..6527a32fb44 100755 --- a/hack/make-rules/generate_client.sh +++ b/hack/make-rules/generate_client.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# Copyright 2020 The OpenYurt 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. + set -x set -e diff --git a/hack/make-rules/genyaml.sh b/hack/make-rules/genyaml.sh index 42efd9f4698..790535e095b 100755 --- a/hack/make-rules/genyaml.sh +++ b/hack/make-rules/genyaml.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# Copyright 2020 The OpenYurt 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. + YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" source "${YURT_ROOT}/hack/lib/init.sh" diff --git a/pkg/controller/apis/config/types.go b/pkg/controller/apis/config/types.go index 5310d412ed6..7ecbb56bba1 100644 --- a/pkg/controller/apis/config/types.go +++ b/pkg/controller/apis/config/types.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 The OpenYurt 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. +*/ + package config import ( diff --git a/pkg/yurtctl/constants/yurt-app-manager-tmpl.go b/pkg/yurtctl/constants/yurt-app-manager-tmpl.go index 559f342649a..2cde69af51a 100644 --- a/pkg/yurtctl/constants/yurt-app-manager-tmpl.go +++ b/pkg/yurtctl/constants/yurt-app-manager-tmpl.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 The OpenYurt 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. +*/ + package constants const ( diff --git a/pkg/yurthub/healthchecker/node_lease_test.go b/pkg/yurthub/healthchecker/node_lease_test.go index 5baa971398e..56a8e79e356 100644 --- a/pkg/yurthub/healthchecker/node_lease_test.go +++ b/pkg/yurthub/healthchecker/node_lease_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 The OpenYurt 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. +*/ + package healthchecker import ( diff --git a/pkg/yurthub/kubernetes/rest/config_test.go b/pkg/yurthub/kubernetes/rest/config_test.go index 1453e1e2bc8..cd13f5d7056 100644 --- a/pkg/yurthub/kubernetes/rest/config_test.go +++ b/pkg/yurthub/kubernetes/rest/config_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 The OpenYurt 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. +*/ + package rest import (