Skip to content

Commit e7e2ded

Browse files
authored
chore: Add Release Audit Tool check to linter (#35)
## What's Changed Apache Rat https://creadur.apache.org/rat/ can detect license issues. Closes #34.
1 parent 466da39 commit e7e2ded

File tree

8 files changed

+164
-25
lines changed

8 files changed

+164
-25
lines changed

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,19 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
/.build/
18+
*.xcodeproj
19+
.DS_Store
20+
.build/
21+
.netrc
22+
.swiftpm/
23+
DerivedData/
24+
Packages/
25+
xcuserdata/
26+
27+
# Docker
1928
/.docker/
29+
30+
# Release Audit Tool
31+
/dev/release/apache-rat-*.jar
32+
/dev/release/filtered_rat.txt
33+
/dev/release/rat.xml

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
# under the License.
1717

1818
repos:
19+
- repo: local
20+
hooks:
21+
- id: rat
22+
name: Release Audit Tool
23+
language: system
24+
entry: |
25+
bash -c " \
26+
git archive HEAD \
27+
--prefix=apache-arrow-swift/ \
28+
--output=apache-arrow-swift.tar.gz && \
29+
dev/release/run_rat.sh apache-arrow-swift.tar.gz && \
30+
rm -f apache-arrow-swift.tar.gz"
31+
always_run: true
32+
pass_filenames: false
1933
- repo: https://github.com/realm/SwiftLint
2034
rev: 0.59.1
2135
hooks:

Arrow/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

ArrowFlight/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

CDataWGo/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

dev/release/check_rat_report.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
import fnmatch
21+
import re
22+
import sys
23+
import xml.etree.ElementTree as ET
24+
25+
if len(sys.argv) != 3:
26+
sys.stderr.write("Usage: %s exclude_globs.lst rat_report.xml\n" %
27+
sys.argv[0])
28+
sys.exit(1)
29+
30+
exclude_globs_filename = sys.argv[1]
31+
xml_filename = sys.argv[2]
32+
33+
globs = [line.strip() for line in open(exclude_globs_filename, "r")]
34+
35+
tree = ET.parse(xml_filename)
36+
root = tree.getroot()
37+
resources = root.findall('resource')
38+
39+
all_ok = True
40+
for r in resources:
41+
approvals = r.findall('license-approval')
42+
if not approvals or approvals[0].attrib['name'] == 'true':
43+
continue
44+
clean_name = re.sub('^[^/]+/', '', r.attrib['name'])
45+
excluded = False
46+
for g in globs:
47+
if fnmatch.fnmatch(clean_name, g):
48+
excluded = True
49+
break
50+
if not excluded:
51+
sys.stdout.write("NOT APPROVED: %s (%s): %s\n" % (
52+
clean_name, r.attrib['name'], approvals[0].attrib['name']))
53+
all_ok = False
54+
55+
if not all_ok:
56+
sys.exit(1)
57+
58+
print('OK')
59+
sys.exit(0)

dev/release/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+
*/*/go.sum
19+
*/Package.resolved
20+
*/go.sum
21+
.github/pull_request_template.md
22+
Package.resolved

dev/release/run_rat.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -eu
21+
22+
RELEASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23+
24+
RAT_VERSION=0.16.1
25+
26+
RAT_JAR="${RELEASE_DIR}/apache-rat-${RAT_VERSION}.jar"
27+
if [ ! -f "${RAT_JAR}" ]; then
28+
curl \
29+
--fail \
30+
--output "${RAT_JAR}" \
31+
--show-error \
32+
--silent \
33+
https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar
34+
fi
35+
36+
RAT_XML="${RELEASE_DIR}/rat.xml"
37+
java \
38+
-jar "${RAT_JAR}" \
39+
--out "${RAT_XML}" \
40+
--xml \
41+
"$1"
42+
FILTERED_RAT_TXT="${RELEASE_DIR}/filtered_rat.txt"
43+
if ${PYTHON:-python3} \
44+
"${RELEASE_DIR}/check_rat_report.py" \
45+
"${RELEASE_DIR}/rat_exclude_files.txt" \
46+
"${RAT_XML}" > \
47+
"${FILTERED_RAT_TXT}"; then
48+
echo "No unapproved licenses"
49+
else
50+
cat "${FILTERED_RAT_TXT}"
51+
N_UNAPPROVED=$(grep -c "NOT APPROVED" "${FILTERED_RAT_TXT}")
52+
echo "${N_UNAPPROVED} unapproved licenses. Check Rat report: ${RAT_XML}"
53+
exit 1
54+
fi

0 commit comments

Comments
 (0)