-
Notifications
You must be signed in to change notification settings - Fork 121
[HACK WEEK] Integrate periphery #15962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c2e4009
Setup periphery.yml
RafaelKayumov 3210c1b
Adjust periphery.yml for local runs
RafaelKayumov 0a9b0d2
Add baseline feature to ignore the snapshot of existing issues
RafaelKayumov f487cfe
git ignore Periphery install
RafaelKayumov d1f2151
Setup periphery run script
RafaelKayumov dcf8ac3
Move baseline json to Scripts/Periphery folder from root
RafaelKayumov b20a7a3
Add Periphery step in buildkite pipeline
RafaelKayumov 75c27e7
Specify debug build config in build_for_testing lane
RafaelKayumov ffff651
Add skip job type check for Periphery
RafaelKayumov a2f2593
Add gh commit status for periphery
RafaelKayumov b6eef1c
Update artifact download
RafaelKayumov 758a187
include Xcode Index Store in the build-products.tar artifact
RafaelKayumov ad13050
Exclude test targets
RafaelKayumov 5f760a8
Remove unnecessary chmod
RafaelKayumov a3ded2e
Re-generate baseline
RafaelKayumov 4b08069
Use quotes for path and version
RafaelKayumov 7916cc4
Delete -xcconfig override from run_tests call
RafaelKayumov 5f1c6f0
Add Periphery errors as Buildkite annotation
AliSoftware 55fa528
Refactor setup-and-run-periphery.sh
AliSoftware 0203b2f
🚧 TO REVERT: Introduce violations on purpose
AliSoftware 92b4934
Revert "🚧 TO REVERT: Introduce violations on purpose"
AliSoftware 147232e
Integrate periphery: add fancier reporting (#15984)
AliSoftware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/bin/bash -eu | ||
|
|
||
| if .buildkite/commands/should-skip-job.sh --job-type validation; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| ### Prepare | ||
|
|
||
| echo '--- 📦 Downloading Build Artifacts' | ||
| buildkite-agent artifact download build-products.tar . | ||
| tar -xf build-products.tar | ||
|
|
||
| ### Run the Tests | ||
|
|
||
| echo '+++ :periphery: Detecting unused code' | ||
| set +e | ||
| # This is the script in the root. | ||
| ./Scripts/Periphery/setup-and-run-periphery.sh --strict --quiet --skip-build --index-store-path 'DerivedData/Index.noindex/DataStore/' | ||
| TESTS_EXIT_STATUS=$? | ||
| set -e | ||
|
|
||
| # Handle the result of the periphery scan | ||
| if [[ "$TESTS_EXIT_STATUS" -ne 0 ]]; then | ||
| echo '😱 Unused code detected!' | ||
| echo '' | ||
| echo '💡 You can run Periphery locally by calling `setup-and-run-periphery.sh` from `./Scripts/Periphery/` in the repo.' | ||
| echo '' | ||
| echo 'If you think there is a false positive violation, please check the known issues of Periphery at https://github.com/peripheryapp/periphery/issues.' | ||
| echo 'If you think a violation is valid but it should be surpressed for any reason, please apply the `// periphery: ignore - {your-reason-here}` comment.' | ||
| echo '' | ||
| else | ||
| echo '😊 No unused code found.' | ||
| fi | ||
|
|
||
| echo '--- 🚦 Report Exit code' | ||
| exit $TESTS_EXIT_STATUS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # This option tells Periphery to not report any Swift code as unused if it's accessible from Objective-C. This includes any class that inherits from NSObject, and any method or property marked with the @objc or @objcMembers attribute. | ||
| # Woocommerce-ios, is a mixed Swift and Objective-C project. Swift code is often called from Objective-C and vice-versa. Without this flag, Periphery would incorrectly flag Swift code that is only used by Objective-C parts of the app as "unused," which would be a false positive. Setting this to true is essential for getting accurate results in a mixed-language codebase. | ||
| retain_objc_accessible: true | ||
|
|
||
| # This option prevents Periphery from flagging unused parameters in protocol method implementations. | ||
| # Often, a protocol will define a method with parameters that are needed by some, but not all, conforming types. If a specific implementation doesn't need to use a parameter, Swift still requires that the method signature matches the protocol exactly. Periphery would normally see this unused parameter and flag it. However, removing it would cause a compile error because the method signature would no longer match the protocol. This flag tells Periphery to ignore these cases, avoiding false positives. | ||
| retain_unused_protocol_func_params: true | ||
|
|
||
| # This option retains all code within a previews struct that conforms to SwiftUI's PreviewProvider protocol. | ||
| # SwiftUI Previews are a powerful feature for UI development in Xcode. The code you write for previews is often not directly called from your main application target; it's used by Xcode's canvas. Periphery would see this and incorrectly mark the preview code as unused. This flag correctly tells Periphery to always keep preview provider code, which is the desired behavior. | ||
| retain_swift_ui_previews: true | ||
|
|
||
| # This option disables the check for public declarations that are only used within their own module. | ||
| # Normally, Periphery would suggest changing public to internal or private in these cases to reduce the public API surface of a module. | ||
| disable_redundant_public_analysis: false | ||
|
|
||
| # By default, Periphery will scan all targets in your project, including test targets. | ||
| # This can lead to false positives, as test code is not part of the main application. | ||
| # This option tells Periphery to exclude all test targets from the scan, ensuring that only the application code is analyzed. | ||
| exclude_tests: true | ||
|
|
||
| schemes: | ||
| - WooCommerce | ||
|
|
||
| project: WooCommerce.xcworkspace | ||
|
|
||
| # Used for local run by `periphery scan` | ||
| # This will not conflict with CI build configuration because of build skipping by `--skip-build` and `--index-store-path` | ||
| build_arguments: | ||
| - -xcconfig | ||
| - config/WooCommerce.debug.xcconfig | ||
|
|
||
| # A baseline is used to manage the large number of warnings from a mature codebase. | ||
| # It contains a snapshot of all "existing/acceptable" warnings. Periphery will ignore all | ||
| # warnings in this file, allowing you to focus on new issues in pull requests. | ||
| # | ||
| # After fixing existing warnings, regenerate this file with: | ||
| # periphery scan --write-baseline Scripts/Periphery/periphery_baseline.json | ||
| baseline: Scripts/Periphery/periphery_baseline.json | ||
|
|
||
| exclude_targets: | ||
| - GenerateCredentials | ||
| - WooCommerceScreenshots | ||
| - WordPressAuthenticator | ||
| - WordPressAuthenticatorTests | ||
| - WooCommerceTests | ||
| - WooCommerceUITests | ||
| - NotificationExtension | ||
| - StoreWidgetsExtension | ||
| - WatchWidgetsExtension | ||
| - "Woo Watch App" | ||
| - Fakes | ||
| - XcodeTarget_WooCommerceTests | ||
| - XcodeTarget_WooCommerceUITests | ||
| - XcodeTarget_WordPressAuthenticatorTests | ||
|
|
||
| index_exclude: | ||
| - Pods/* | ||
| - vendor/** | ||
| - BuildTools/.build/** | ||
| - "**/Tests/*" | ||
| - "**/Test*/*" | ||
| - "docs/*" | ||
| - "fastlane/*" | ||
| - "config/*" | ||
| - "**/*.xib" | ||
| - "**/*.storyboard" | ||
| - "**/*.generated.swift" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Define the Periphery version | ||
| PERIPHERY_VERSION="3.2.0" | ||
|
|
||
| # Define the path to the periphery executable | ||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
| PERIPHERY_FOLDER_PATH="${REPO_ROOT}/vendor/Periphery" | ||
| PERIPHERY_PATH="${PERIPHERY_FOLDER_PATH}/periphery" | ||
|
|
||
| # Function to compare versions | ||
| version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } | ||
|
|
||
| # Function to update and run Periphery | ||
| update_and_run() { | ||
| echo "Downloading the latest version..." | ||
| # Download the zip file | ||
| curl -L "https://github.com/peripheryapp/periphery/releases/download/${PERIPHERY_VERSION}/periphery-${PERIPHERY_VERSION}.zip" -o "periphery.zip" | ||
|
|
||
| # Create target directory if it doesn't exist | ||
| mkdir -p "$PERIPHERY_FOLDER_PATH" | ||
|
|
||
| # Unzip the contents directly into the target directory, overwriting files | ||
| unzip -o periphery.zip -d "$PERIPHERY_FOLDER_PATH" | ||
|
|
||
| # Clean up the zip file | ||
| rm periphery.zip | ||
|
|
||
| # Make sure the executable is executable | ||
| chmod +x "$PERIPHERY_PATH" | ||
|
|
||
| echo "Download and setup complete. Running periphery scan..." | ||
| # Run periphery scan with additional arguments | ||
| $PERIPHERY_PATH scan "$@" | ||
AliSoftware marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| # Check if the executable exists and is executable | ||
| if [ -x "$PERIPHERY_PATH" ]; then | ||
| echo "Executable found. Checking version..." | ||
| # Get the current installed version | ||
| CURRENT_VERSION=$($PERIPHERY_PATH version) | ||
AliSoftware marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Compare the current version with the desired version | ||
| if version_gt $PERIPHERY_VERSION $CURRENT_VERSION; then | ||
AliSoftware marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Current version ($CURRENT_VERSION) is older than $PERIPHERY_VERSION. Updating..." | ||
| update_and_run "$@" | ||
| else | ||
| echo "Current version ($CURRENT_VERSION) is up-to-date. Running periphery scan..." | ||
| $PERIPHERY_PATH scan "$@" | ||
AliSoftware marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
| else | ||
| echo "Executable not found. Downloading..." | ||
| update_and_run "$@" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.