diff --git a/.buildkite/commands/run-periphery.sh b/.buildkite/commands/run-periphery.sh index 8af4db882be..3afff80246e 100755 --- a/.buildkite/commands/run-periphery.sh +++ b/.buildkite/commands/run-periphery.sh @@ -12,10 +12,14 @@ tar -xf build-products.tar ### Run the Tests -echo '+++ :periphery: Detecting unused code' +PERIPHERY_OUTPUT_FILE="periphery-errors.txt" + +echo '+++ :zombie: 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/' +./Scripts/Periphery/setup-and-run-periphery.sh \ + --strict --quiet --skip-build --index-store-path 'DerivedData/Index.noindex/DataStore/' \ + --write-results "$PERIPHERY_OUTPUT_FILE" TESTS_EXIT_STATUS=$? set -e @@ -28,8 +32,12 @@ if [[ "$TESTS_EXIT_STATUS" -ne 0 ]]; then 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 '' + # Add the periphery errors as a Buildkite annotation + (echo "### Periphery found unused code"; echo ''; echo '```'; cat "$PERIPHERY_OUTPUT_FILE"; echo ''; echo '```') \ + | buildkite-agent annotate --context periphery --style error else echo '😊 No unused code found.' + buildkite-agent annotate --context periphery --style success 'No unused code found by Periphery :tada:' fi echo '--- 🚦 Report Exit code' diff --git a/Scripts/Periphery/setup-and-run-periphery.sh b/Scripts/Periphery/setup-and-run-periphery.sh index c01755fcb28..f39d0ddd47b 100755 --- a/Scripts/Periphery/setup-and-run-periphery.sh +++ b/Scripts/Periphery/setup-and-run-periphery.sh @@ -12,8 +12,8 @@ PERIPHERY_PATH="${PERIPHERY_FOLDER_PATH}/periphery" 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..." +update_periphery() { + echo "Downloading version $PERIPHERY_VERSION..." # Download the zip file curl -L "https://github.com/peripheryapp/periphery/releases/download/${PERIPHERY_VERSION}/periphery-${PERIPHERY_VERSION}.zip" -o "periphery.zip" @@ -29,9 +29,7 @@ update_and_run() { # 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 "$@" + echo "Download and setup complete." } # Check if the executable exists and is executable @@ -43,12 +41,15 @@ if [ -x "$PERIPHERY_PATH" ]; then # Compare the current version with the desired version if version_gt "$PERIPHERY_VERSION" "$CURRENT_VERSION"; then echo "Current version ($CURRENT_VERSION) is older than $PERIPHERY_VERSION. Updating..." - update_and_run "$@" + update_periphery else - echo "Current version ($CURRENT_VERSION) is up-to-date. Running periphery scan..." - $PERIPHERY_PATH scan "$@" + echo "Current version ($CURRENT_VERSION) is up-to-date." fi else echo "Executable not found. Downloading..." - update_and_run "$@" + update_periphery fi + +echo "Running periphery scan..." +# Run periphery scan with additional arguments +"$PERIPHERY_PATH" scan --disable-update-check --relative-results "$@"