Skip to content

Commit

Permalink
Update document, build-ios support limit warning count. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z authored Jan 21, 2024
1 parent 0d0b083 commit 1036136
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 54 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,38 @@

### 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

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:

Expand All @@ -50,12 +49,12 @@ Environment variables:

<!-- Link here: xccommand.sh -->

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`.
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build-ios
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
17 changes: 11 additions & 6 deletions check-result
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ func printUsage() {
print("""
Usage: \(name) <action>...

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<T: Decodable>: Decodable, CustomStringConvertible {
let _values: [T]
Expand Down
5 changes: 0 additions & 5 deletions lib/xccommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ readonly _xcParameterList=(
"XC_DESTINATION"
"XC_DISABLE_CODE_SIGNING"
"XC_RESULT_BUNDLE"
"XC_REDIRECT_STDERR"
"XC_LOG_FILE"
"XC_BEAUTIFY"
)
Expand All @@ -48,10 +47,6 @@ xcCommand() {
fi
export _xcAction="$1"

# if [[ $(checkVar "${XC_REDIRECT_STDERR:-}") == 0 ]]; then
# xcParts+=("2>&1")
# fi

_xcChain3
}

Expand Down
39 changes: 19 additions & 20 deletions tests/test_build_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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"
}

0 comments on commit 1036136

Please sign in to comment.