File: check_copyright.sh

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (97 lines) | stat: -rwxr-xr-x 2,067 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

if [[ ! -e tools/check_copyright.sh ]]; then
  echo "This tool must be run from the topmost directory." >&2
  exit 1
fi

set -e

#
# Process input file .copyright-ignore,
# - remove comments
# - remove blank lines
# to create file /tmp/all_ignored
#

grep -v "^#" < .copyright-ignore | \
grep -v "^[[:space:]]*$" > /tmp/all_ignored

#
# Find all files from the repository
# to create file /tmp/all_checked
#

find . -type f -print | sort -u > /tmp/all_checked

#
# Filter out /tmp/all_checked,
# remove all ignored patterns from /tmp/all_ignored
# When the pattern is *.md,
# make sure to filter *\.md to avoid hiding *.cmd
# Then, *\.md needs to be escaped to *\\.md,
# to be given to egrep, hence the sed.
# 

while IFS= read -r PATTERN; do
  SAFE_PATTERN=`echo "${PATTERN}" | sed "s!\.!\\\\\.!g"`
  echo "Filtering out ${SAFE_PATTERN}"
  egrep -v "${SAFE_PATTERN}" < /tmp/all_checked > /tmp/all_checked-tmp
  mv /tmp/all_checked-tmp /tmp/all_checked
done < /tmp/all_ignored

#
# For all files in /tmp/all_checked
# - verify there is copyright
# - verify there is a license
# and append to /tmp/all_missing
#
# Valid copyright strings are:
# - Copyright The OpenTelemetry Authors
#
# Valid license strings are:
# - SPDX-License-Identifier: Apache-2.0
#

rm -rf /tmp/all_missing
touch /tmp/all_missing

for FILE in `cat /tmp/all_checked`
do
  echo "Checking ${FILE}"
  export COPYRIGHT=`head -10 ${FILE} | grep -c "Copyright The OpenTelemetry Authors"`
  export LICENSE=`head -10 ${FILE} | grep -c "SPDX-License-Identifier: Apache-2.0"`
  if [ "$COPYRIGHT" == "0" ]; then
    echo "Missing copyright in ${FILE}" >> /tmp/all_missing
  fi;
  if [ "${LICENSE}" == "0" ]; then
    echo "Missing license in ${FILE}" >> /tmp/all_missing
  fi;
done

#
# Final report
#

FAIL_COUNT=`wc -l < /tmp/all_missing`

if [ ${FAIL_COUNT} != "0" ]; then
  #
  # CI FAILED
  #

  cat /tmp/all_missing

  echo "Total number of failed checks: ${FAIL_COUNT}"
  exit 1
fi;

#
# CI PASSED
#

exit 0