Skip to content

Commit 876ac69

Browse files
committed
fix: optimize ci
1 parent 2210d84 commit 876ac69

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

scripts/rat.sh

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
### Apache RAT license check script ###
2020
# This script downloads Apache RAT and runs it to check the license headers of the source files.
2121

22-
set -e # Exit immediately if a command exits with a non-zero status.
22+
set -e
2323

24-
# Some variables
2524
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
26-
TEMP_DIR="${ROOT_DIR}/temp"
25+
TMP_DIR="/tmp"
26+
2727
RAT_VERSION="0.16.1"
28-
RAT_JAR="${TEMP_DIR}/apache-rat-${RAT_VERSION}.jar"
28+
RAT_JAR="${TMP_DIR}/apache-rat-${RAT_VERSION}.jar"
2929

3030

3131
cd "${ROOT_DIR}"
32-
mkdir -p "${TEMP_DIR}"
3332

3433
# Set Java command
3534
if [ -x "${JAVA_HOME}/bin/java" ]; then
@@ -39,48 +38,43 @@ else
3938
fi
4039

4140

42-
# Download Apache RAT jar file if not exists
43-
if [ ! -f "${RAT_JAR}" ]; then
44-
RAT_URL="https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
45-
JAR_PART="${RAT_JAR}.part"
46-
47-
echo "Downloading Apache RAT ${RAT_VERSION}..."
41+
# Download Apache RAT jar
42+
echo "Downloading Apache RAT ${RAT_VERSION}..."
4843

49-
if command -v curl &> /dev/null; then
50-
curl -L --silent "${RAT_URL}" -o "${JAR_PART}"
51-
elif command -v wget &> /dev/null; then
52-
wget --quiet "${RAT_URL}" -O "${JAR_PART}"
53-
else
54-
echo "Neither curl nor wget found."
55-
exit 1
56-
fi
44+
RAT_URL="https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
45+
JAR_PART="${RAT_JAR}.part"
5746

58-
mv "${JAR_PART}" "${RAT_JAR}"
47+
if command -v curl &> /dev/null; then
48+
curl -L --silent "${RAT_URL}" -o "${JAR_PART}" && mv "${JAR_PART}" "${RAT_JAR}"
49+
elif command -v wget &> /dev/null; then
50+
wget --quiet "${RAT_URL}" -O "${JAR_PART}" && mv "${JAR_PART}" "${RAT_JAR}"
51+
else
52+
echo "Neither curl nor wget found."
53+
exit 1
54+
fi
5955

56+
unzip -tq "${RAT_JAR}" > /dev/null
57+
if [ $? -ne 0 ]; then
58+
echo "Downloaded Apache RAT jar is invalid"
59+
exit 1
60+
fi
6061

61-
# TODO: Strange phenomenon:its integrity cannot be verified, but it still works normally. (Ignore the check for now)
62-
# Check if the JAR file is valid
63-
# if ! unzip -tq "${RAT_JAR}" &> /dev/null; then
64-
# rm "${RAT_JAR}"
65-
# echo "Download ${RAT_JAR} failed or the file is not a valid JAR."
66-
# exit 1
67-
# fi
62+
echo "Downloaded Apache RAT ${RAT_VERSION} successfully."
6863

69-
echo "Downloaded Apache RAT ${RAT_VERSION} successfully."
70-
fi
7164

7265
# Run Apache RAT
7366
echo "Running Apache license check, this may take a while..."
67+
${java_cmd} -jar ${RAT_JAR} -d ${ROOT_DIR} -E "${ROOT_DIR}/.license-ignore" > "${TEMP_DIR}/rat-report.txt"
7468

75-
"${java_cmd}" -jar "${RAT_JAR}" -E "${ROOT_DIR}/.license-ignore" -d "${ROOT_DIR}" > "${TEMP_DIR}/rat-report.txt"
7669

77-
if grep -q "??" "${TEMP_DIR}/rat-report.txt"; then
70+
# Check the result
71+
if [ $? -ne 0 ]; then
72+
echo "RAT exited abnormally"
73+
exit 1
74+
elif grep -q "??" "${TEMP_DIR}/rat-report.txt"; then
7875
echo >&2 "Could not find Apache license headers in the following files:"
7976
grep "??" "${TEMP_DIR}/rat-report.txt" >&2
8077
exit 1
8178
else
8279
echo "Apache license check passed."
8380
fi
84-
85-
# Clean up
86-
rm -rf "${TEMP_DIR}"

0 commit comments

Comments
 (0)