Skip to content

Commit bde72d9

Browse files
author
Franck Rupin
committed
Update the license check
- The current license check script works only for a single year - This commit modifies the script to being able to validate headers with a different date.
1 parent d2dee0e commit bde72d9

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

scripts/licensecheck.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
#!/bin/bash
1+
#!/bin/bash
22

33
# Verify that the correct license block is present in all Go source
44
# files.
5-
EXPECTED=$(cat ./scripts/license.txt)
5+
LICENSE=./scripts/license.txt
6+
NB_LINES=$(cat $LICENSE| wc -l)
7+
EXPECTED=$(head -$NB_LINES $LICENSE | tail +2)
8+
9+
# Update the string if there is a new year to consider
10+
COPYRIGHT_YEARS="2017 2021"
611

712
# Scan each Go source file for license.
813
EXIT=0
914
GOFILES=$(find . -name "*.go")
1015

1116
for FILE in $GOFILES; do
12-
BLOCK=$(head -n 14 $FILE)
17+
# Start validating the Copyright line of for each header.
18+
# Years can change from a source file to another.
19+
read -r -a COPYRIGHT_TOKENS <<< $(head -n 1 $FILE |awk '{print $2 " " $3 " " $4}')
20+
if [ "${COPYRIGHT_TOKENS[0]}" != "Copyright" ]; then
21+
echo "Bad Copyright token ${COPYRIGHT_TOKENS[0]} in $FILE"
22+
EXIT=1
23+
elif [ $(echo $COPYRIGHT_YEARS | grep -c ${COPYRIGHT_TOKENS[1]}) != "1" ]; then
24+
echo "Bad Year token ${COPYRIGHT_TOKENS[1]} in $FILE"
25+
EXIT=1
26+
elif [ "${COPYRIGHT_TOKENS[2]}" != "DigitalOcean." ]; then
27+
echo "Bad DigitalOcean token ${COPYRIGHT_TOKENS[2]} in $FILE"
28+
EXIT=1
29+
fi
30+
31+
BLOCK=$(head -n 14 $FILE|tail +2)
1332

1433
if [ "$BLOCK" != "$EXPECTED" ]; then
1534
echo "file missing license: $FILE"

0 commit comments

Comments
 (0)