This is an automated email from the ASF dual-hosted git repository. xtsong pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/flink-agents.git
commit 350c0bc307254350078d638b4425c299e1f848a8 Author: Xu Huang <zuosi...@alibaba-inc.com> AuthorDate: Tue Aug 5 16:08:37 2025 +0800 [infra] Add license check tool and integrate with CI --- .github/CONTRIBUTING.md | 2 +- .github/workflows/ci.yml | 2 +- tools/.rat-excludes | 16 +++++++++ tools/check-license.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 80750de..3e57abb 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -52,5 +52,5 @@ Run the following command to format the code: Run the following command to fix the license headers: ```shell -docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix +./tools/check-license.sh ``` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1651469..749a85e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Check License Header - uses: apache/skywalking-eyes/header@main + run: tools/check-license.sh - name: Set up JDK uses: actions/setup-java@v4 with: diff --git a/tools/.rat-excludes b/tools/.rat-excludes new file mode 100644 index 0000000..f1ab3ea --- /dev/null +++ b/tools/.rat-excludes @@ -0,0 +1,16 @@ +.github/* +.rat-excludes +build +.git +.gitignore +.*\.lock$ +.venv/* +.idea/* +.*\.iml$ +.*\.xml$ +.*\.txt$ +target/* +README.md +.pytest_cache/* +.ruff_cache/* +.*\.egg-info/* \ No newline at end of file diff --git a/tools/check-license.sh b/tools/check-license.sh new file mode 100755 index 0000000..4439458 --- /dev/null +++ b/tools/check-license.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# NOTE: This script is adapted from the Apache Spark project. + + +acquire_rat_jar () { + + URL="https://repo.maven.apache.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar" + + JAR="$rat_jar" + + # Download rat launch jar if it hasn't been downloaded yet + if [ ! -f "$JAR" ]; then + # Download + printf "Attempting to fetch rat\n" + JAR_DL="${JAR}.part" + if [ $(command -v curl) ]; then + curl -L --silent "${URL}" > "$JAR_DL" && mv "$JAR_DL" "$JAR" + elif [ $(command -v wget) ]; then + wget --quiet ${URL} -O "$JAR_DL" && mv "$JAR_DL" "$JAR" + else + printf "You do not have curl or wget installed, please install rat manually.\n" + exit -1 + fi + fi + + unzip -tq "$JAR" &> /dev/null + if [ $? -ne 0 ]; then + # We failed to download + rm "$JAR" + printf "Our attempt to download rat locally to ${JAR} failed. Please install rat manually.\n" + exit -1 + fi +} + +# Go to the project root directory +FWDIR="$(cd "`dirname "$0"`"/..; pwd)" +cd "$FWDIR" + +if test -x "$JAVA_HOME/bin/java"; then + declare java_cmd="$JAVA_HOME/bin/java" +else + declare java_cmd=java +fi + +export RAT_VERSION=0.16.1 +export rat_jar="$FWDIR"/lib/apache-rat-${RAT_VERSION}.jar +mkdir -p "$FWDIR"/lib + +[[ -f "$rat_jar" ]] || acquire_rat_jar || { + echo "Download failed. Obtain the rat jar manually and place it at $rat_jar" + exit 1 +} + +mkdir -p build +$java_cmd -jar "$rat_jar" --scan-hidden-directories -E "$FWDIR"/tools/.rat-excludes -d "$FWDIR" > build/rat-results.txt + +if [ $? -ne 0 ]; then + echo "RAT exited abnormally" + exit 1 +fi + +ERRORS="$(cat build/rat-results.txt | grep -e "??")" + +if test ! -z "$ERRORS"; then + echo "Could not find Apache license headers in the following files:" + echo "$ERRORS" + exit 1 +else + echo -e "RAT checks passed." +fi \ No newline at end of file