Skip to content

Commit 3394f21

Browse files
committed
fix: optimize ci
1 parent 82d9888 commit 3394f21

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

scripts/rat.sh

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ fi
3737

3838

3939
# Download Apache RAT jar
40-
RAT_URL="https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
41-
JAR_PART="${RAT_JAR}.part"
42-
4340
echo "Downloading Apache RAT ${RAT_VERSION}..."
4441

42+
RAT_URL="https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
43+
JAR_PART="${RAT_JAR}.part"
4544

4645
if command -v curl &> /dev/null; then
4746
curl -L --silent "${RAT_URL}" -o "${JAR_PART}" && mv "${JAR_PART}" "${RAT_JAR}"
@@ -52,34 +51,29 @@ else
5251
exit 1
5352
fi
5453

55-
56-
# Check if the JAR file is valid
57-
unzip -tq "${RAT_JAR}" &> /dev/null
54+
unzip -tq "${RAT_JAR}" > /dev/null
5855
if [ $? -ne 0 ]; then
59-
rm "${RAT_JAR}"
60-
echo "Download ${RAT_JAR} failed or the file is not a valid JAR."
61-
exit -1
56+
echo "Downloaded Apache RAT jar is invalid"
57+
exit 1
6258
fi
6359

6460
echo "Downloaded Apache RAT ${RAT_VERSION} successfully."
6561

62+
6663
# Run Apache RAT
6764
echo "Running Apache license check, this may take a while..."
65+
${java_cmd} -jar ${RAT_JAR} -d ${ROOT_DIR} -E "${ROOT_DIR}/.license-ignore" > "${TEMP_DIR}/rat-report.txt"
6866

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

68+
# Check the result
7169
if [ $? -ne 0 ]; then
7270
echo "RAT exited abnormally"
7371
exit 1
72+
elif grep -q "??" "${TEMP_DIR}/rat-report.txt"; then
73+
echo >&2 "Could not find Apache license headers in the following files:"
74+
grep "??" "${TEMP_DIR}/rat-report.txt" >&2
75+
exit 1
76+
else
77+
echo "Apache license check passed."
7478
fi
7579

76-
ERRORS="$(grep "??" "${TEMP_DIR}/rat-report.txt")"
77-
78-
79-
if [ -n "$ERRORS" ]; then
80-
echo "Could not find Apache license headers in the following files:"
81-
echo "$ERRORS"
82-
exit 1
83-
else
84-
echo "Apache license check passed."
85-
fi

0 commit comments

Comments
 (0)