From 10361361656e9fa1ea4c295209807e99a844ebfe Mon Sep 17 00:00:00 2001 From: BB9z Date: Sun, 21 Jan 2024 23:16:45 +0800 Subject: [PATCH] Update document, build-ios support limit warning count. (#7) --- README.md | 37 ++++++++++++++++++------------------- build-ios | 8 ++++---- check-result | 17 +++++++++++------ lib/xccommand.sh | 5 ----- tests/test_build_ios.sh | 39 +++++++++++++++++++-------------------- 5 files changed, 52 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index e51310a..e9d1ca1 100644 --- a/README.md +++ b/README.md @@ -6,26 +6,25 @@ ### build-ios -Build iOS target. +Build an iOS target. Environment variables: * Supports [xcCommand](#xcCommand) variables. * `CI_CHECK_STYLE_FILE`: Export checkstyle.xml to this path. -* `XC_ANALYZE`, set to `true` or `1` to perform static analysis during build. Default is disabled. +* `XC_ANALYZE`, set to `true` or `1` to perform static analysis during the build. By default, this is disabled. ### check-result -Parse xcresult bundle, it can: +This tool parses the Xcode result bundle and performs certain actions. It can: -* Print build warnings and summary. -* Export checkstyle.xml. +* List build warnings and errors, including support for static analysis results. +* Limit build warnings to a specified threshold. +* Provide a view of issue category statistics. +* Print a summary of the tests. +* Export build issues to a checkstyle.xml report file. -Environment variables: - -* `CI_XCODE_WARNING_IGNORE_TYPES`: Ignore warning types, separated by comma. eg. `"No-usage,Deprecations,Documentation Issue"` -* `CI_XCODE_WARNING_LIMIT`: Limit warning count. eg. `100`. -* `CI_XCODE_ERROR_LIMIT`: Limit error count. Default is `0`. +See [command usage](https://github.com/b9swift/CI-System/blob/main/check-result#L10) for more details. ### fetch-mr @@ -33,12 +32,12 @@ Fetch merge request. Environment variables: -* `CI_CHANGE_LIST_PATH`: Save changed files list to this path. -* `CI_GIT_MR_BRANCH`: Merge request branch name. +* `CI_CHANGE_LIST_PATH`: Saves the list of changed files to this path. +* `CI_GIT_MR_BRANCH`: The name of the merge request branch. ### pod-install -Smart CocoaPods install. +Performs a smart CocoaPods installation. Environment variables: @@ -50,12 +49,12 @@ Environment variables: -Inputs: +Inputs environment variables: -- `XC_WORKSPACE`, workspace file path. -- `XC_PROJECT`, project file path. -- `XC_SCHEME`, scheme name. -- `XC_CLEAN`, set to `true` to clean before executing the action. +- `XC_WORKSPACE`, the path to the workspace file. +- `XC_PROJECT`, the path to the project file. +- `XC_SCHEME`, the name of the scheme. +- `XC_CLEAN`, set to `true` or `1` to clean before executing the action. - `XC_CONFIGURATION`, build configuration, eg. `Debug`/`Release`/... - `XC_DERIVED_DATA`, the xcodebuild command derivedDataPath parameter, defaults to `build/DerivedData`, set to an empty string or `0` or `false` to disable customization. - `XC_DESTINATION`, target device, value can be the full parameter or abbreviations like `mac`, `ios`, `watchos`, `tvos`. @@ -66,7 +65,7 @@ Inputs: ## Run Tests -[shunit2](https://github.com/kward/shunit2) required. You can install it via Homebrew. +[shunit2](https://github.com/kward/shunit2) is required. You can install it via Homebrew. ```zsh $ ./run_tests diff --git a/build-ios b/build-ios index ca770e9..e102c05 100755 --- a/build-ios +++ b/build-ios @@ -13,9 +13,6 @@ fi if [[ ! -v XC_BEAUTIFY ]]; then XC_BEAUTIFY=1 fi -if [[ ! -v XC_REDIRECT_STDERR ]]; then - XC_REDIRECT_STDERR=1 -fi if [[ -z ${XC_RESULT_BUNDLE-} ]]; then export XC_RESULT_BUNDLE="build/xc-build.xcresult" @@ -47,10 +44,13 @@ else logInfo "[Xcode] Building completed." fi -resultCommands=("$(dirname $0)/check-result" listIssues summary) +resultCommands=("$(dirname $0)/check-result" listIssues) if [[ -n "${CI_CHECK_STYLE_FILE:-}" ]]; then resultCommands+=("checkstyle") fi +if [[ -n "${CI_XCODE_WARNING_LIMIT:-}" ]]; then + resultCommands+=("limitWarning") +fi "${resultCommands[@]}" exit $code diff --git a/check-result b/check-result index e978b71..7417634 100755 --- a/check-result +++ b/check-result @@ -9,16 +9,21 @@ func printUsage() { print(""" Usage: \(name) ... +Parse the Xcode result bundle and execute certain actions. + Actions: - checkstyle: Generate checkstyle report to CI_CHECK_STYLE_FILE. - limitWarning: Limit the number of warnings to the given limit, if the number exceeds, the script exit status code is the number of warnings. - listIssues: Print all warnings. - summary: Statistical information of the results. + checkstyle: Generate a checkstyle report to CI_CHECK_STYLE_FILE. + limitWarning: Set a limit to the number of warnings. If the number exceeds the limit, the script's exit status code will be the number of warnings. + listIssues: Display build warnings, errors, and analyzer issues. + summary: Provide statistical information about the results. + +Environment variables: -Options: - -h, --help: print this message +* CI_XCODE_WARNING_IGNORE_TYPES: Ignore specific types of warnings, separated by commas. For example, `"No-usage,Deprecations,Documentation Issue"`. +* CI_XCODE_WARNING_LIMIT: Set a limit to the warning count. For example, `100`. """) } +// * `CI_XCODE_ERROR_LIMIT`: Limit error count. Default is `0`. struct XCArray: Decodable, CustomStringConvertible { let _values: [T] diff --git a/lib/xccommand.sh b/lib/xccommand.sh index 71f2c7d..ac0995d 100644 --- a/lib/xccommand.sh +++ b/lib/xccommand.sh @@ -27,7 +27,6 @@ readonly _xcParameterList=( "XC_DESTINATION" "XC_DISABLE_CODE_SIGNING" "XC_RESULT_BUNDLE" - "XC_REDIRECT_STDERR" "XC_LOG_FILE" "XC_BEAUTIFY" ) @@ -48,10 +47,6 @@ xcCommand() { fi export _xcAction="$1" - # if [[ $(checkVar "${XC_REDIRECT_STDERR:-}") == 0 ]]; then - # xcParts+=("2>&1") - # fi - _xcChain3 } diff --git a/tests/test_build_ios.sh b/tests/test_build_ios.sh index d6a448e..1bbd8b5 100644 --- a/tests/test_build_ios.sh +++ b/tests/test_build_ios.sh @@ -99,8 +99,8 @@ testAnalyzEnvFlagNotSet() { } assertEquals "return code" 0 $code - assertContains "No issues." "$output" - assertNotContains "[A]" "$output" + assertContains "$output" "No issues." + assertNotContains "$output" "[A]" } testAnalyzNoIssues() { @@ -114,8 +114,8 @@ testAnalyzNoIssues() { } assertEquals "return code" 0 $code - assertContains "No issues." "$output" - assertNotContains "[A]" "$output" + assertContains "$output" "No issues." + assertNotContains "$output" "[A]" } testAnalyzHasIssues() { @@ -129,22 +129,21 @@ testAnalyzHasIssues() { } assertEquals "return code" 0 $code - assertContains "[A]" "$output" + assertContains "$output" "[A]" # echo ">> $output" } -# testAnalyzWithWarningLimit() { -# export XC_PROJECT="tests/samples/BuildTests.xcodeproj" -# export XC_SCHEME="ClangAnalyz" -# export XC_DESTINATION=mac -# export XC_ANALYZE=1 -# export CI_XCODE_WARNING_LIMIT=2 -# code=0 -# output=$(./build-ios) || { -# code=$? -# } - -# assertEquals "return code" 0 $code -# assertContains "[A]" "$output" -# echo ">> $output" -# } +testAnalyzWithWarningLimit() { + export XC_PROJECT="tests/samples/BuildTests.xcodeproj" + export XC_SCHEME="HasWarning" + export XC_DESTINATION=mac + export CI_XCODE_WARNING_LIMIT=2 + code=0 + output=$(./build-ios) || { + code=$? + } + + assertEquals "return code is warning count" 3 $code + assertContains "$output" "[!]" + assertContains "$output" "Warning count 3 exceed limit 2" +}