Skip to content

Commit e6d1ea7

Browse files
committed
Add license checker
1 parent 3b0bed0 commit e6d1ea7

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: "Run License Check"
19+
on: pull_request
20+
21+
jobs:
22+
rat:
23+
runs-on: ubuntu-22.04
24+
steps:
25+
- uses: actions/checkout@v3
26+
- run: dev/check-license

dev/check-license

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
acquire_rat_jar () {
19+
20+
URL="https://repo.maven.apache.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
21+
22+
JAR="$rat_jar"
23+
24+
# Download rat launch jar if it hasn't been downloaded yet
25+
if [ ! -f "$JAR" ]; then
26+
# Download
27+
printf "Attempting to fetch rat\n"
28+
JAR_DL="${JAR}.part"
29+
if [ $(command -v curl) ]; then
30+
curl -L --silent "${URL}" > "$JAR_DL" && mv "$JAR_DL" "$JAR"
31+
elif [ $(command -v wget) ]; then
32+
wget --quiet ${URL} -O "$JAR_DL" && mv "$JAR_DL" "$JAR"
33+
else
34+
printf "You do not have curl or wget installed, please install rat manually.\n"
35+
exit -1
36+
fi
37+
fi
38+
39+
unzip -tq "$JAR" &> /dev/null
40+
if [ $? -ne 0 ]; then
41+
# We failed to download
42+
rm "$JAR"
43+
printf "Our attempt to download rat locally to ${JAR} failed. Please install rat manually.\n"
44+
exit -1
45+
fi
46+
}
47+
48+
# Go to the Spark project root directory
49+
FWDIR="$(cd "`dirname "$0"`"/..; pwd)"
50+
cd "$FWDIR"
51+
52+
if test -x "$JAVA_HOME/bin/java"; then
53+
declare java_cmd="$JAVA_HOME/bin/java"
54+
else
55+
declare java_cmd=java
56+
fi
57+
58+
export RAT_VERSION=0.16.1
59+
export rat_jar="$FWDIR"/lib/apache-rat-${RAT_VERSION}.jar
60+
mkdir -p "$FWDIR"/lib
61+
62+
[[ -f "$rat_jar" ]] || acquire_rat_jar || {
63+
echo "Download failed. Obtain the rat jar manually and place it at $rat_jar"
64+
exit 1
65+
}
66+
67+
mkdir -p build
68+
$java_cmd -jar "$rat_jar" -E "$FWDIR"/dev/rat_exclude_files.txt -d "$FWDIR" > build/rat-results.txt
69+
70+
if [ $? -ne 0 ]; then
71+
echo "RAT exited abnormally"
72+
exit 1
73+
fi
74+
75+
ERRORS="$(cat build/rat-results.txt | grep -e "??")"
76+
77+
if test ! -z "$ERRORS"; then
78+
echo "Could not find Apache license headers in the following files:"
79+
echo "$ERRORS"
80+
exit 1
81+
else
82+
echo -e "RAT checks passed."
83+
fi

dev/rat_exclude_files.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
.gitignore
19+
LICENSE
20+
NOTICE
21+
build/
22+
rat-results.txt

0 commit comments

Comments
 (0)