Skip to content

Commit

Permalink
Merge pull request #561 from LiZhenCheng9527/copyright-check
Browse files Browse the repository at this point in the history
add Copyright check
  • Loading branch information
kmesh-bot authored Jul 11, 2024
2 parents 86ee8e1 + 9360353 commit 9ad7cac
Show file tree
Hide file tree
Showing 101 changed files with 256 additions and 99 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
run: |
make gen-check
- name: Run Copyright-check
run : |
make ./hack/copyright-check.sh
- name: Build Kmesh
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion bpf/kmesh/bpf2go/bpf2go.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions bpf/kmesh/probes/access_log.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Kmesh */

#ifndef __KMESH_BPF_ACCESS_LOG_H__
#define __KMESH_BPF_ACCESS_LOG_H__

Expand Down
3 changes: 3 additions & 0 deletions bpf/kmesh/probes/metrics.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Kmesh */

#ifndef __KMESH_BPF_METRICS_H__
#define __KMESH_BPF_METRICS_H__
#include "bpf_common.h"
Expand Down
3 changes: 3 additions & 0 deletions bpf/kmesh/probes/probe.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Kmesh */

#ifndef __KMESH_BPF_PROBE_H__
#define __KMESH_BPF_PROBE_H__

Expand Down
127 changes: 127 additions & 0 deletions hack/copyright-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash

ROOT_DIR=$(git rev-parse --show-toplevel)

go_copyright_path=$ROOT_DIR/hack/copyright/apache.txt

c_copyright_path1=$ROOT_DIR/hack/copyright/BSDandGPL1.txt
c_copyright_path2=$ROOT_DIR/hack/copyright/BSDandGPL2.txt

go_dirs="$ROOT_DIR/pkg"
c_dirs="$ROOT_DIR/bpf"

function check_go_copyright() {
target_file=$1
copyright_file=$go_copyright_path

if [ ! -f "$target_file" ]; then
echo "Target file $target_file does not exist."
exit 1
fi

if [ ! -f "$copyright_file" ]; then
echo "Copyright file $copyright_file does not exist."
exit 1
fi

all_lines_present=true
while IFS= read -r line; do
if ! grep -qF -- "$line" "$target_file"; then
all_lines_present=false
break
fi
done < "$copyright_file"

if [ "$all_lines_present" != true ]; then
echo "The target file does not contain all lines from the copyright file."
echo $target_file
fi
}

function check_c_copyright() {
target_file=$1
copyright_file1=$c_copyright_path1
copyright_file2=$c_copyright_path2

if [ ! -f "$target_file" ]; then
echo "Target file $target_file does not exist."
exit 1
fi

if [ ! -f "$copyright_file1" ]; then
echo "Copyright file $copyright_file1 does not exist."
exit 1
fi

if [ ! -f "$copyright_file2" ]; then
echo "Copyright file $copyright_file2 does not exist."
exit 1
fi

all_lines_present1=true
while IFS= read -r line; do
if ! grep -qF -- "$line" "$target_file"; then
all_lines_present1=false
break
fi
done < "$copyright_file1"

all_lines_present2=true
while IFS= read -r line; do
if ! grep -qF -- "$line" "$target_file"; then
all_lines_present2=false
break
fi
done < "$copyright_file2"

if [ "$all_lines_present1" != true ] && [ "$all_lines_present2" != true ]; then
echo "The target file does not contain all lines from the copyright file."
echo $target_file
fi
}

function go_check_dir() {
dir=$1
find $dir -type f -name "*.go" | while read file; do
# echo $file
if ! echo $exclude_dirs | grep -q $(dirname $file); then
check_go_copyright $file
fi
done
}

function c_check_dir() {
dir=$1
find $dir -type f -name "*.c" -o -name "*.h" | while read file; do
# echo $file
if ! echo $exclude_dirs | grep -q $(dirname $file); then
check_c_copyright $file
fi
done
}

function copyright_check() {
for dir in ${go_dirs}; do
go_check_dir $dir
done

for dir in ${c_dirs}; do
c_check_dir $dir
done
}

# Confirmation of whether there are files with wrong copyright
if [ -z "$1" -o "$1" == "-c" -o "$1" == "--check" ]; then
result=$(copyright_check | grep -c 'not contain')
if [ "$result" != 0 ]; then
echo "ERROR: Some files need to be update copyright, please run "./hack/copyright-check -g" and update and include any changed files in your PR"
exit 1
else
echo "pass copyright check"
fi
fi

# Obtaining the name of a file that with wrong copyright
if [ "$1" == "-g" -o "$1" == "--get" ]; then
copyright_check
fi
2 changes: 2 additions & 0 deletions hack/copyright/BSDandGPL1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Kmesh */
2 changes: 2 additions & 0 deletions hack/copyright/BSDandGPL2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
/* Copyright Authors of Kmesh */
15 changes: 15 additions & 0 deletions hack/copyright/apache.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright The Kmesh 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.
*/
2 changes: 1 addition & 1 deletion pkg/auth/policy_store.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/policy_store_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/rbac.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/rbac_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/xdp_auth_handler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build enhanced

/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh_common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh_l4.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !enhanced

/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh_l4_workload.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh_workload.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/pin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/listener.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/listener_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/maps/cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/maps/common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/maps/listener.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/maps/route.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/route.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v2/route_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/chained.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/chained_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/install.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/kubeconfig.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cni/plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Kmesh Authors.
* Copyright The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 9ad7cac

Please sign in to comment.