You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by hx...@apache.org on 2025/06/10 05:28:10 UTC
(flink-agents) branch main updated: Improves the usability of lint/ut scripts (#5)
This is an automated email from the ASF dual-hosted git repository.
hxb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git
The following commit(s) were added to refs/heads/main by this push:
new d0482d7 Improves the usability of lint/ut scripts (#5)
d0482d7 is described below
commit d0482d7af02d83f698e94bc4c787e158ea0b6f49
Author: HuangXingBo <hx...@apache.org>
AuthorDate: Tue Jun 10 13:28:05 2025 +0800
Improves the usability of lint/ut scripts (#5)
---
.github/workflows/ci.yml | 6 +-
.gitignore | 1 +
tools/lint.sh | 121 ++++++++++++++++++++++++++++++--
tools/ut.sh | 175 ++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 268 insertions(+), 35 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bc4e269..d0535ec 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -42,7 +42,7 @@ jobs:
with:
python-version: 3.12
- name: Check code style
- run: ./tools/lint.sh
+ run: ./tools/lint.sh -c
java_tests:
name: java tests on ${{ matrix.os }}
@@ -58,7 +58,7 @@ jobs:
java-version: '11'
distribution: 'adopt'
- name: Run Java Tests
- run: tools/ut.sh java
+ run: tools/ut.sh -j
python_tests:
name: python tests on ${{ matrix.os }}
@@ -79,4 +79,4 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Run Python Tests
- run: tools/ut.sh python
+ run: tools/ut.sh -p
diff --git a/.gitignore b/.gitignore
index 029ec07..5743b40 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
.idea/*
target/
*.iml
+.DS_Store
python/.idea/
python/flink_agents.egg-info/
python/flink_agents/flink_agents.egg-info/
diff --git a/tools/lint.sh b/tools/lint.sh
index 911d1a4..ef24a2a 100755
--- a/tools/lint.sh
+++ b/tools/lint.sh
@@ -16,11 +16,118 @@
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
+set -e
-echo "Install format tools"
-pip install -r python/requirements/linter_requirements.txt
-echo "Executing Python format check"
-ruff check python
-echo "Executing Java format check"
-mvn -T10 -B --no-transfer-progress spotless:check
-echo "Executing format check succeeds"
+format_code=true
+
+# Help information
+show_help() {
+ cat <<EOF
+Format/Check code files
+
+Usage: $0 [options]
+
+Options:
+ -f, --format Format code files. (default)
+ -c, --check Check code files for errors.
+ -h, --help Display this help message
+
+Examples:
+ $0 --format # Format code files
+ $0 -c # Check code files for errors
+EOF
+}
+
+# Parse command-line arguments
+while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ -f|--format)
+ format_code=true
+ ;;
+ -c|--check)
+ format_code=false
+ ;;
+ -h|--help)
+ show_help
+ exit 0
+ ;;
+ *)
+ echo "Error: Unknown option '$1'" >&2
+ show_help
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Function to format files
+format_files() {
+ set +e
+ echo "Install format tools"
+ pip install -r python/requirements/linter_requirements.txt
+ echo "Executing Python format"
+ ruff format python
+ testcode=$?
+ if [[ $testcode -ne 0 ]]; then
+ echo "Python format failed" >&2
+ return 2
+ fi
+ echo "Executing Java format"
+ mvn -T10 -B --no-transfer-progress spotless:apply
+ testcode=$?
+ if [[ $testcode -ne 0 ]]; then
+ echo "Java format failed" >&2
+ return 2
+ fi
+ echo "Executing format succeeds"
+ return 0
+}
+
+# Function to check files for issues
+check_files() {
+ set +e
+ echo "Install format tools"
+ pip install -r python/requirements/linter_requirements.txt
+ echo "Executing Python format check"
+ ruff check python
+ testcode=$?
+ if [[ $testcode -ne 0 ]]; then
+ echo "Python format check failed" >&2
+ return 2
+ fi
+ echo "Executing Java format check"
+ mvn -T10 -B --no-transfer-progress spotless:check
+ testcode=$?
+ if [[ $testcode -ne 0 ]]; then
+ echo "Java format check failed" >&2
+ return 2
+ fi
+ echo "Executing format check succeeds"
+ return 0
+}
+
+# Main command dispatcher
+# shellcheck disable=SC2120
+main() {
+ local result=0
+ if $format_code; then
+ format_files "$@"
+ result=$?
+ else
+ check_files "$@"
+ result=$?
+ fi
+ if [[ $result -ne 0 ]]; then
+ echo "### FORMAT CHECK FAILED ###" >&2
+ return 2
+ else
+ echo "### FORMAT CHECK PASSED ###"
+ return 0
+ fi
+}
+
+# Execute main function and capture exit code
+main
+exit_code=$?
+
+exit $exit_code
diff --git a/tools/ut.sh b/tools/ut.sh
index da3098e..534d613 100755
--- a/tools/ut.sh
+++ b/tools/ut.sh
@@ -17,36 +17,161 @@
# limitations under the License.
################################################################################
set -e
-set -x
-ROOT="$(git rev-parse --show-toplevel)"
-echo "Root path: $ROOT, home path: $HOME"
-cd "$ROOT"
+ROOT="$(cd "$( dirname "$0" )" && pwd)/.."
-case $1 in
- java)
- echo "Executing java tests"
+# Default values
+run_java=true
+run_python=true
+verbose=false
+
+# Help information
+show_help() {
+ cat <<EOF
+Run Java and Python test suites
+
+Usage: $0 [options]
+
+Options:
+ -j, --java Run only Java tests
+ -p, --python Run only Python tests
+ -b, --both Run both Java and Python tests (default)
+ -v, --verbose Show verbose output
+ -h, --help Display this help message
+
+Examples:
+ $0 --java # Run only Java tests
+ $0 -p # Run only Python tests
+ $0 -v # Run all tests with verbose output
+
+Exit codes:
+ 0 All tests passed
+ 1 Java tests failed
+ 2 Python tests failed
+ 3 All tests failed
+EOF
+}
+
+# Parse command-line arguments
+while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ -j|--java)
+ run_java=true
+ run_python=false
+ ;;
+ -p|--python)
+ run_python=true
+ run_java=false
+ ;;
+ -b|--both)
+ run_java=true
+ run_python=true
+ ;;
+ -v|--verbose)
+ verbose=true
+ ;;
+ -h|--help)
+ show_help
+ exit 0
+ ;;
+ *)
+ echo "Error: Unknown option '$1'" >&2
+ show_help
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+java_tests() {
+ if $verbose; then
+ echo "Running Java tests..."
+ fi
set +e
+ echo "Executing Java test suite..."
+ pushd "${ROOT}"
mvn -T16 --batch-mode --no-transfer-progress test
- testcode=$?
- if [[ $testcode -ne 0 ]]; then
- exit $testcode
+ echo "Java tests completed"
+}
+
+python_tests() {
+ if $verbose; then
+ echo "Running Python tests..."
fi
- echo "Executing java tests succeeds"
- ;;
- python)
- echo "Executing python tests"
+
set +e
- pip install -r python/requirements/test_requirements.txt
- pytest python/flink_agents
+ pushd "${ROOT}"/python
+ pip install -r requirements/test_requirements.txt
+ pytest flink_agents
testcode=$?
- if [[ $testcode -ne 0 && testcode -ne 5 ]]; then
- exit $testcode
+ popd
+
+ # Handle pytest exit codes
+ case $testcode in
+ 0) # All tests passed
+ if $verbose; then
+ echo "All Python tests passed"
+ fi
+ return 0
+ ;;
+ 1) # Tests failed
+ echo "Python tests failed" >&2
+ return 2
+ ;;
+ 2) # Test execution interrupted
+ echo "Python tests interrupted" >&2
+ return 2
+ ;;
+ 5) # No tests collected
+ echo "Warning: No Python tests collected" >&2
+ return 0 # Treat as success
+ ;;
+ *) # Unknown error
+ echo "Python tests encountered unknown error (exit code: $testcode)" >&2
+ return 2
+ ;;
+ esac
+}
+
+main() {
+ local java_result=0
+ local python_result=0
+
+ # Execute Java tests if enabled
+ if $run_java; then
+ java_tests
+ java_result=$?
+ fi
+
+ # Execute Python tests if enabled
+ if $run_python; then
+ python_tests
+ python_result=$?
fi
- echo "Executing python tests succeeds"
- ;;
- *)
- echo "Execute command $*"
- "$@"
- ;;
-esac
+
+ # Aggregate results
+ if [[ $java_result -ne 0 && $python_result -ne 0 ]]; then
+ echo "### ALL TESTS FAILED ###" >&2
+ return 3
+ elif [[ $java_result -ne 0 ]]; then
+ echo "### JAVA TESTS FAILED ###" >&2
+ return 1
+ elif [[ $python_result -ne 0 ]]; then
+ echo "### PYTHON TESTS FAILED ###" >&2
+ return 2
+ else
+ echo "### ALL TESTS PASSED ###"
+ return 0
+ fi
+}
+
+# Execute main function and capture exit code
+main
+exit_code=$?
+
+# Show final exit code in verbose mode
+if $verbose; then
+ echo "Final exit code: $exit_code"
+fi
+
+exit $exit_code