From fec385ec99cb99e7d52f88e27c79e7b3cd71b99f Mon Sep 17 00:00:00 2001 From: Jerens Lensun Date: Tue, 3 Jun 2025 16:33:12 +0800 Subject: [PATCH] add script for clippy annotation Signed-off-by: Jerens Lensun --- .gitignore | 3 +++ etc/ci/clippy-annotation.sh | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 etc/ci/clippy-annotation.sh diff --git a/.gitignore b/.gitignore index 630eb63b9bb..3a6c61271d8 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,6 @@ support/macos/Brewfile.lock.json # direnv .envrc + +# Temporary logs for CI +/temp diff --git a/etc/ci/clippy-annotation.sh b/etc/ci/clippy-annotation.sh new file mode 100755 index 00000000000..22f3ecc83ca --- /dev/null +++ b/etc/ci/clippy-annotation.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Usage: ./clippy-to-annotations.sh < input.json > output.json +# Will exit with an error if there are no valid annotations. + +set -euo pipefail + +output=$(jq -c ' + . as $in + | ($in.message.spans // [] | map(select(.is_primary == true)) | first) as $primarySpan + | if $primarySpan == null then + empty + else + { + path: $primarySpan.file_name, + start_line: $primarySpan.line_start, + end_line: $primarySpan.line_end, + annotation_level: ( + $in.message.level + | if . == "help" or . == "note" then "notice" + elif . == "warning" then "warning" + else "failure" + end + ), + title: $in.message.message, + message: $in.message.rendered + } + | if .start_line == .end_line then + . + { + start_column: $primarySpan.column_start, + end_column: $primarySpan.column_end + } + else + . + end + end +' | jq -s '.') + +if [[ "$output" == "[]" || -z "$output" ]]; then + echo "❌ No annotations to output." >&2 + exit 0 +fi + +# Output the final result +echo "$output"