From 77b5cbb306994dde6da09d71b409717f7306caa6 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 08:19:39 +0300 Subject: [PATCH 1/9] wip: service tags script --- .../services/accommodation/v1/search.proto | 2 + scripts/analyze-proto-tags.sh | 115 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 scripts/analyze-proto-tags.sh diff --git a/proto/cmp/services/accommodation/v1/search.proto b/proto/cmp/services/accommodation/v1/search.proto index 7fcad4a..fe381d4 100644 --- a/proto/cmp/services/accommodation/v1/search.proto +++ b/proto/cmp/services/accommodation/v1/search.proto @@ -117,6 +117,8 @@ message AccommodationSearchResponse { // ![Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/search.proto.dot.xs.svg) // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/search.proto.dot.svg) +// +/// @custom:cmp-service type:product routing:p2p service AccommodationSearchService { // Accommodation Search method rpc AccommodationSearch(AccommodationSearchRequest) returns (AccommodationSearchResponse); diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-proto-tags.sh new file mode 100644 index 0000000..9b61f94 --- /dev/null +++ b/scripts/analyze-proto-tags.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Colors for output +RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Valid values +valid_types=("core" "product" "system") +valid_routing=("p2p" "local") +valid_onchain=("true" "false") + +# Initialize arrays for different categories +declare -a no_tag_services +declare -a invalid_tag_services +declare -a valid_tag_services + +check_service() { + local file="$1" + local service_name="$2" + local tag="$3" + local filepath="$4" + + # If no tag is present + if [ -z "$tag" ]; then + no_tag_services+=("$filepath:$service_name") + return + fi + + # Check if the tag matches the expected format + if ! [[ $tag =~ @custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:(true|false))? ]]; then + invalid_tag_services+=("$filepath:$service_name - Malformed tag format") + return + fi + + # Extract values + type="${BASH_REMATCH[1]}" + routing="${BASH_REMATCH[2]}" + onchain="${BASH_REMATCH[4]:-false}" + + # Validate type + if [[ ! " ${valid_types[@]} " =~ " ${type} " ]]; then + invalid_tag_services+=("$filepath:$service_name - Invalid type: $type") + return + fi + + # Validate routing + if [[ ! " ${valid_routing[@]} " =~ " ${routing} " ]]; then + invalid_tag_services+=("$filepath:$service_name - Invalid routing: $routing") + return + fi + + # Validate on-chain if present + if [ ! -z "$onchain" ] && [[ ! " ${valid_onchain[@]} " =~ " ${onchain} " ]]; then + invalid_tag_services+=("$filepath:$service_name - Invalid on-chain value: $onchain") + return + fi + + # If we get here, the tag is valid + valid_tag_services+=("$filepath:$service_name") +} + +scan_proto_files() { + local dir="$1" + + # Find all .proto files recursively + while IFS= read -r -d '' file; do + while IFS= read -r line; do + # Check for service definition + if [[ $line =~ ^[[:space:]]*service[[:space:]]+([[:alnum:]]+)[[:space:]]*\{ ]]; then + service_name="${BASH_REMATCH[1]}" + # Get the line before service definition + prev_line=$(grep -B 1 "^[[:space:]]*service[[:space:]]\+${service_name}[[:space:]]*{" "$file" | head -n 1) + + # Check if previous line contains the custom tag + if [[ $prev_line =~ ///[[:space:]]*(@custom:cmp-service.*) ]]; then + check_service "$file" "$service_name" "${BASH_REMATCH[1]}" "$file" + else + check_service "$file" "$service_name" "" "$file" + fi + fi + done <"$file" + done < <(find "$dir" -type f -name "*.proto" -print0) +} + +# Main execution +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -d "$1" ]; then + echo "Error: Directory $1 does not exist" + exit 1 +fi + +# Scan the directory +scan_proto_files "$1" + +# Print results +echo -e "\n${RED}Services without @custom:cmp-service tag:${NC}" +printf '%s\n' "${no_tag_services[@]}" | sort + +echo -e "\n${YELLOW}Services with invalid @custom:cmp-service tag:${NC}" +printf '%s\n' "${invalid_tag_services[@]}" | sort + +echo -e "\n${GREEN}Services with valid @custom:cmp-service tag:${NC}" +printf '%s\n' "${valid_tag_services[@]}" | sort + +# Print summary +echo -e "\nSummary:" +echo "Total services without tag: ${#no_tag_services[@]}" +echo "Total services with invalid tag: ${#invalid_tag_services[@]}" +echo "Total services with valid tag: ${#valid_tag_services[@]}" From 6da10b2927acc11926cefb585fa07c15bdccaff9 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 08:33:04 +0300 Subject: [PATCH 2/9] wip: update 2 --- .../cmp/services/accommodation/v1/list.proto | 2 + .../services/accommodation/v1/search.proto | 2 +- scripts/analyze-proto-tags.sh | 93 +++++++++++++++---- 3 files changed, 79 insertions(+), 18 deletions(-) diff --git a/proto/cmp/services/accommodation/v1/list.proto b/proto/cmp/services/accommodation/v1/list.proto index 646edb0..00fc348 100644 --- a/proto/cmp/services/accommodation/v1/list.proto +++ b/proto/cmp/services/accommodation/v1/list.proto @@ -31,6 +31,8 @@ message AccommodationProductListResponse { // ![Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/list.proto.dot.xs.svg) // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/list.proto.dot.svg) +// +/// @custom:cmp-service type:product roting:p2p on-chain:falsa service AccommodationProductListService { // Returns product list for accommodation (properties) rpc AccommodationProductList(AccommodationProductListRequest) returns (AccommodationProductListResponse); diff --git a/proto/cmp/services/accommodation/v1/search.proto b/proto/cmp/services/accommodation/v1/search.proto index fe381d4..8227173 100644 --- a/proto/cmp/services/accommodation/v1/search.proto +++ b/proto/cmp/services/accommodation/v1/search.proto @@ -118,7 +118,7 @@ message AccommodationSearchResponse { // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/search.proto.dot.svg) // -/// @custom:cmp-service type:product routing:p2p +/// @custom:cmp-service type:product routing:p2p on-chain:false service AccommodationSearchService { // Accommodation Search method rpc AccommodationSearch(AccommodationSearchRequest) returns (AccommodationSearchResponse); diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-proto-tags.sh index 9b61f94..b56d509 100644 --- a/scripts/analyze-proto-tags.sh +++ b/scripts/analyze-proto-tags.sh @@ -4,8 +4,19 @@ RED='\033[0;31m' YELLOW='\033[1;33m' GREEN='\033[0;32m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +BOLD='\033[1m' NC='\033[0m' # No Color +# Emojis +WARNING="⚠️ " +ERROR="❌" +SUCCESS="✅" +INFO="ℹ️ " +FOLDER="📁" +MAGNIFIER="🔍" + # Valid values valid_types=("core" "product" "system") valid_routing=("p2p" "local") @@ -30,7 +41,7 @@ check_service() { # Check if the tag matches the expected format if ! [[ $tag =~ @custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:(true|false))? ]]; then - invalid_tag_services+=("$filepath:$service_name - Malformed tag format") + invalid_tag_services+=("$filepath:$service_name|$tag - Malformed tag format") return fi @@ -41,29 +52,32 @@ check_service() { # Validate type if [[ ! " ${valid_types[@]} " =~ " ${type} " ]]; then - invalid_tag_services+=("$filepath:$service_name - Invalid type: $type") + invalid_tag_services+=("$filepath:$service_name|$tag - Invalid type: $type") return fi # Validate routing if [[ ! " ${valid_routing[@]} " =~ " ${routing} " ]]; then - invalid_tag_services+=("$filepath:$service_name - Invalid routing: $routing") + invalid_tag_services+=("$filepath:$service_name|$tag - Invalid routing: $routing") return fi # Validate on-chain if present if [ ! -z "$onchain" ] && [[ ! " ${valid_onchain[@]} " =~ " ${onchain} " ]]; then - invalid_tag_services+=("$filepath:$service_name - Invalid on-chain value: $onchain") + invalid_tag_services+=("$filepath:$service_name|$tag - Invalid on-chain value: $onchain") return fi # If we get here, the tag is valid - valid_tag_services+=("$filepath:$service_name") + valid_tag_services+=("$filepath:$service_name|$tag") } scan_proto_files() { local dir="$1" + echo -e "${BLUE}${MAGNIFIER} Scanning directory: ${CYAN}$dir${NC}" + echo "----------------------------------------" + # Find all .proto files recursively while IFS= read -r -d '' file; do while IFS= read -r line; do @@ -84,14 +98,36 @@ scan_proto_files() { done < <(find "$dir" -type f -name "*.proto" -print0) } +format_service_output() { + local input="$1" + local filepath="${input%%:*}" + local rest="${input#*:}" + local service="${rest%%|*}" + local tag="${rest#*|}" + + if [[ "$tag" == "$service" ]]; then + echo -e " ${CYAN}${filepath}${NC}" + echo -e " └─ ${BOLD}$service${NC}" + else + local error_msg="" + if [[ "$tag" =~ .*-.* ]]; then + error_msg=" - ${tag#* - }" + tag="${tag%% - *}" + fi + echo -e " ${CYAN}${filepath}${NC}" + echo -e " └─ ${BOLD}$service${NC}" + echo -e " ${tag}${RED}${error_msg}${NC}" + fi +} + # Main execution if [ "$#" -ne 1 ]; then - echo "Usage: $0 " + echo -e "${ERROR} Usage: $0 " exit 1 fi if [ ! -d "$1" ]; then - echo "Error: Directory $1 does not exist" + echo -e "${ERROR} Error: Directory $1 does not exist" exit 1 fi @@ -99,17 +135,40 @@ fi scan_proto_files "$1" # Print results -echo -e "\n${RED}Services without @custom:cmp-service tag:${NC}" -printf '%s\n' "${no_tag_services[@]}" | sort +echo -e "\n${RED}${ERROR} Services without @custom:cmp-service tag:${NC}" +echo "==========================================" +if [ ${#no_tag_services[@]} -eq 0 ]; then + echo -e " ${INFO} No services found without tags" +else + for service in "${no_tag_services[@]}"; do + format_service_output "$service" + done +fi -echo -e "\n${YELLOW}Services with invalid @custom:cmp-service tag:${NC}" -printf '%s\n' "${invalid_tag_services[@]}" | sort +echo -e "\n${YELLOW}${WARNING} Services with invalid @custom:cmp-service tag:${NC}" +echo "==========================================" +if [ ${#invalid_tag_services[@]} -eq 0 ]; then + echo -e " ${INFO} No services found with invalid tags" +else + for service in "${invalid_tag_services[@]}"; do + format_service_output "$service" + done +fi -echo -e "\n${GREEN}Services with valid @custom:cmp-service tag:${NC}" -printf '%s\n' "${valid_tag_services[@]}" | sort +echo -e "\n${GREEN}${SUCCESS} Services with valid @custom:cmp-service tag:${NC}" +echo "==========================================" +if [ ${#valid_tag_services[@]} -eq 0 ]; then + echo -e " ${INFO} No services found with valid tags" +else + for service in "${valid_tag_services[@]}"; do + format_service_output "$service" + done +fi # Print summary -echo -e "\nSummary:" -echo "Total services without tag: ${#no_tag_services[@]}" -echo "Total services with invalid tag: ${#invalid_tag_services[@]}" -echo "Total services with valid tag: ${#valid_tag_services[@]}" +echo -e "\n${BLUE}${INFO} Summary:${NC}" +echo "==========================================" +echo -e "${RED}${ERROR} Missing tags: ${#no_tag_services[@]}${NC}" +echo -e "${YELLOW}${WARNING} Invalid tags: ${#invalid_tag_services[@]}${NC}" +echo -e "${GREEN}${SUCCESS} Valid tags: ${#valid_tag_services[@]}${NC}" +echo -e "Total services: $((${#no_tag_services[@]} + ${#invalid_tag_services[@]} + ${#valid_tag_services[@]}))" From 321e87aea9cd235e3a98b7d6301cbcc763976f67 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 08:38:34 +0300 Subject: [PATCH 3/9] wip: update 3 --- proto/cmp/services/accommodation/v1/info.proto | 2 ++ scripts/analyze-proto-tags.sh | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/proto/cmp/services/accommodation/v1/info.proto b/proto/cmp/services/accommodation/v1/info.proto index 964a04c..1bf502c 100644 --- a/proto/cmp/services/accommodation/v1/info.proto +++ b/proto/cmp/services/accommodation/v1/info.proto @@ -39,6 +39,8 @@ message AccommodationProductInfoResponse { // ![Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/info.proto.dot.xs.svg) // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/info.proto.dot.svg) +// +/// @custom:cmp-service type:product routing:p2p on-chain:fals service AccommodationProductInfoService { // Returns product list for accommodation (properties) rpc AccommodationProductInfo(AccommodationProductInfoRequest) returns (AccommodationProductInfoResponse); diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-proto-tags.sh index b56d509..6f9d4da 100644 --- a/scripts/analyze-proto-tags.sh +++ b/scripts/analyze-proto-tags.sh @@ -102,21 +102,26 @@ format_service_output() { local input="$1" local filepath="${input%%:*}" local rest="${input#*:}" - local service="${rest%%|*}" - local tag="${rest#*|}" - if [[ "$tag" == "$service" ]]; then - echo -e " ${CYAN}${filepath}${NC}" - echo -e " └─ ${BOLD}$service${NC}" - else + # Check if the input contains a tag (has a | separator) + if [[ "$rest" == *"|"* ]]; then + local service="${rest%%|*}" + local tag="${rest#*|}" + local error_msg="" if [[ "$tag" =~ .*-.* ]]; then error_msg=" - ${tag#* - }" tag="${tag%% - *}" fi + echo -e " ${CYAN}${filepath}${NC}" echo -e " └─ ${BOLD}$service${NC}" echo -e " ${tag}${RED}${error_msg}${NC}" + else + # No tag case + local service="$rest" + echo -e " ${CYAN}${filepath}${NC}" + echo -e " └─ ${BOLD}$service${NC}" fi } From 22b040be676da48a4dc6baacd666e03bbfad6101 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 08:52:36 +0300 Subject: [PATCH 4/9] wip: update 4 --- .../cmp/services/accommodation/v1/list.proto | 2 +- .../services/accommodation/v1/search.proto | 2 +- scripts/analyze-proto-tags.sh | 31 ++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/proto/cmp/services/accommodation/v1/list.proto b/proto/cmp/services/accommodation/v1/list.proto index 00fc348..2798449 100644 --- a/proto/cmp/services/accommodation/v1/list.proto +++ b/proto/cmp/services/accommodation/v1/list.proto @@ -32,7 +32,7 @@ message AccommodationProductListResponse { // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/list.proto.dot.svg) // -/// @custom:cmp-service type:product roting:p2p on-chain:falsa +/// @custom:cmp-service type:product routing:p2p on-chain:false service AccommodationProductListService { // Returns product list for accommodation (properties) rpc AccommodationProductList(AccommodationProductListRequest) returns (AccommodationProductListResponse); diff --git a/proto/cmp/services/accommodation/v1/search.proto b/proto/cmp/services/accommodation/v1/search.proto index 8227173..641b554 100644 --- a/proto/cmp/services/accommodation/v1/search.proto +++ b/proto/cmp/services/accommodation/v1/search.proto @@ -118,7 +118,7 @@ message AccommodationSearchResponse { // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/search.proto.dot.svg) // -/// @custom:cmp-service type:product routing:p2p on-chain:false +/// @custom:cmp-service typae:product routing:p2p on-chain:false service AccommodationSearchService { // Accommodation Search method rpc AccommodationSearch(AccommodationSearchRequest) returns (AccommodationSearchResponse); diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-proto-tags.sh index 6f9d4da..0969d12 100644 --- a/scripts/analyze-proto-tags.sh +++ b/scripts/analyze-proto-tags.sh @@ -4,13 +4,16 @@ RED='\033[0;31m' YELLOW='\033[1;33m' GREEN='\033[0;32m' +LGREEN='\033[1;32m' BLUE='\033[0;34m' +LBLUE='\033[1;34m' CYAN='\033[0;36m' +PURPLE='\033[0;35m' BOLD='\033[1m' NC='\033[0m' # No Color # Emojis -WARNING="⚠️ " +WARNING="🚫" ERROR="❌" SUCCESS="✅" INFO="ℹ️ " @@ -39,8 +42,8 @@ check_service() { return fi - # Check if the tag matches the expected format - if ! [[ $tag =~ @custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:(true|false))? ]]; then + # Check if the tag matches the expected format (including strict on-chain value check) + if ! [[ $tag =~ ^@custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:(true|false))?$ ]]; then invalid_tag_services+=("$filepath:$service_name|$tag - Malformed tag format") return fi @@ -108,15 +111,19 @@ format_service_output() { local service="${rest%%|*}" local tag="${rest#*|}" - local error_msg="" - if [[ "$tag" =~ .*-.* ]]; then - error_msg=" - ${tag#* - }" - tag="${tag%% - *}" + # For valid services, don't try to extract error message + if [[ "$tag" =~ .*" - ".* ]]; then + local error_msg=" - ${tag#* - }" + local clean_tag="${tag%% - *}" + + echo -e " ${CYAN}${filepath}${NC}" + echo -e " └─ ${BOLD}$service${NC}" + echo -e " ${clean_tag}${RED}${error_msg}${NC}" + else + echo -e " ${CYAN}${filepath}${NC}" + echo -e " └─ ${BOLD}$service${NC}" + echo -e " ${GREEN}${tag}${NC} ${SUCCESS}" fi - - echo -e " ${CYAN}${filepath}${NC}" - echo -e " └─ ${BOLD}$service${NC}" - echo -e " ${tag}${RED}${error_msg}${NC}" else # No tag case local service="$rest" @@ -160,7 +167,7 @@ else done fi -echo -e "\n${GREEN}${SUCCESS} Services with valid @custom:cmp-service tag:${NC}" +echo -e "\n${LGREEN}${SUCCESS} Services with valid @custom:cmp-service tag:${NC}" echo "==========================================" if [ ${#valid_tag_services[@]} -eq 0 ]; then echo -e " ${INFO} No services found with valid tags" From 35f1316b97dca7c9e2b3f429a7ddb906cb6fdb3f Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 09:08:35 +0300 Subject: [PATCH 5/9] wip: update 5 --- scripts/analyze-proto-tags.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-proto-tags.sh index 0969d12..ca5c73b 100644 --- a/scripts/analyze-proto-tags.sh +++ b/scripts/analyze-proto-tags.sh @@ -2,7 +2,8 @@ # Colors for output RED='\033[0;31m' -YELLOW='\033[1;33m' +YELLOW='\033[0;33m' +BYELLOW='\033[1;33m' GREEN='\033[0;32m' LGREEN='\033[1;32m' BLUE='\033[0;34m' @@ -42,9 +43,9 @@ check_service() { return fi - # Check if the tag matches the expected format (including strict on-chain value check) - if ! [[ $tag =~ ^@custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:(true|false))?$ ]]; then - invalid_tag_services+=("$filepath:$service_name|$tag - Malformed tag format") + # First, check basic format (more permissive) + if ! [[ $tag =~ ^@custom:cmp-service[[:space:]]+type:([[:alnum:]]+)[[:space:]]+routing:([[:alnum:]]+)([[:space:]]+on-chain:([[:alnum:]]+))?$ ]]; then + invalid_tag_services+=("$filepath:$service_name|$tag - Malformed tag format: must follow '@custom:cmp-service type: routing: [on-chain:]'") return fi @@ -115,10 +116,9 @@ format_service_output() { if [[ "$tag" =~ .*" - ".* ]]; then local error_msg=" - ${tag#* - }" local clean_tag="${tag%% - *}" - echo -e " ${CYAN}${filepath}${NC}" echo -e " └─ ${BOLD}$service${NC}" - echo -e " ${clean_tag}${RED}${error_msg}${NC}" + echo -e " ${YELLOW}${clean_tag}${NC} ${RED}${error_msg}${NC}" else echo -e " ${CYAN}${filepath}${NC}" echo -e " └─ ${BOLD}$service${NC}" @@ -148,7 +148,7 @@ scan_proto_files "$1" # Print results echo -e "\n${RED}${ERROR} Services without @custom:cmp-service tag:${NC}" -echo "==========================================" +echo "=================================================" if [ ${#no_tag_services[@]} -eq 0 ]; then echo -e " ${INFO} No services found without tags" else @@ -157,18 +157,20 @@ else done fi -echo -e "\n${YELLOW}${WARNING} Services with invalid @custom:cmp-service tag:${NC}" -echo "==========================================" +echo -e "\n${BYELLOW}${WARNING} Services with invalid @custom:cmp-service tag:${NC}" +echo "=================================================" if [ ${#invalid_tag_services[@]} -eq 0 ]; then echo -e " ${INFO} No services found with invalid tags" else for service in "${invalid_tag_services[@]}"; do format_service_output "$service" done + + echo -e "\n ${INFO} Valid values: type=\"${valid_types[@]}\" routing=\"${valid_routing[@]}\" on-chain=\"${valid_onchain[@]}\"" fi echo -e "\n${LGREEN}${SUCCESS} Services with valid @custom:cmp-service tag:${NC}" -echo "==========================================" +echo "=================================================" if [ ${#valid_tag_services[@]} -eq 0 ]; then echo -e " ${INFO} No services found with valid tags" else @@ -179,7 +181,7 @@ fi # Print summary echo -e "\n${BLUE}${INFO} Summary:${NC}" -echo "==========================================" +echo "=================================================" echo -e "${RED}${ERROR} Missing tags: ${#no_tag_services[@]}${NC}" echo -e "${YELLOW}${WARNING} Invalid tags: ${#invalid_tag_services[@]}${NC}" echo -e "${GREEN}${SUCCESS} Valid tags: ${#valid_tag_services[@]}${NC}" From d0a198b1fd2edb3bb8597465e52176b495912865 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 09:09:07 +0300 Subject: [PATCH 6/9] rename --- scripts/{analyze-proto-tags.sh => analyze-service-tags.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{analyze-proto-tags.sh => analyze-service-tags.sh} (100%) diff --git a/scripts/analyze-proto-tags.sh b/scripts/analyze-service-tags.sh similarity index 100% rename from scripts/analyze-proto-tags.sh rename to scripts/analyze-service-tags.sh From 08bf4defcacfd2987e3ba442ae48df77d4edda21 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 09:35:03 +0300 Subject: [PATCH 7/9] add valid tag colorization --- scripts/analyze-service-tags.sh | 72 ++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/scripts/analyze-service-tags.sh b/scripts/analyze-service-tags.sh index ca5c73b..f5e6eef 100644 --- a/scripts/analyze-service-tags.sh +++ b/scripts/analyze-service-tags.sh @@ -2,14 +2,17 @@ # Colors for output RED='\033[0;31m' +LRED='\033[1;31m' YELLOW='\033[0;33m' -BYELLOW='\033[1;33m' +LYELLOW='\033[1;33m' GREEN='\033[0;32m' LGREEN='\033[1;32m' BLUE='\033[0;34m' LBLUE='\033[1;34m' CYAN='\033[0;36m' +LCYAN='\033[1;36m' PURPLE='\033[0;35m' +LPURPLE='\033[1;35m' BOLD='\033[1m' NC='\033[0m' # No Color @@ -102,6 +105,70 @@ scan_proto_files() { done < <(find "$dir" -type f -name "*.proto" -print0) } +colorize_tag() { + local tag="$1" + + # Color mappings for different values + local TYPE_CORE="${LPURPLE}" + local TYPE_PRODUCT="${LBLUE}" + local TYPE_SYSTEM="${LRED}" + + local ROUTING_P2P="${LGREEN}" + local ROUTING_LOCAL="${LYELLOW}" + + local ONCHAIN_TRUE="${LPURPLE}" + local ONCHAIN_FALSE="${LCYAN}" + + # Extract each part using regex + if [[ $tag =~ ^(@custom:cmp-service)[[:space:]]+(type:([[:alnum:]]+))[[:space:]]+(routing:([[:alnum:]]+))([[:space:]]+on-chain:([[:alnum:]]+))?$ ]]; then + local prefix="${BASH_REMATCH[1]}" + local type_full="${BASH_REMATCH[2]}" + local type_value="${BASH_REMATCH[3]}" + local routing_full="${BASH_REMATCH[4]}" + local routing_value="${BASH_REMATCH[5]}" + local onchain_full="${BASH_REMATCH[6]}" + local onchain_value="${BASH_REMATCH[7]}" + + # Select color for type + local type_color + case "$type_value" in + "core") type_color="$TYPE_CORE" ;; + "product") type_color="$TYPE_PRODUCT" ;; + "system") type_color="$TYPE_SYSTEM" ;; + *) type_color="$RED" ;; # Invalid value + esac + + # Select color for routing + local routing_color + case "$routing_value" in + "p2p") routing_color="$ROUTING_P2P" ;; + "local") routing_color="$ROUTING_LOCAL" ;; + *) routing_color="$RED" ;; # Invalid value + esac + + # Select color for on-chain + local onchain_color + case "$onchain_value" in + "true") onchain_color="$ONCHAIN_TRUE" ;; + "false") onchain_color="$ONCHAIN_FALSE" ;; + *) onchain_color="$RED" ;; # Invalid value + esac + + # Build the colored string + local result="${BOLD}$prefix${NC} ${type_color}${type_full}${NC} ${routing_color}${routing_full}${NC}" + #local result="$prefix type:${type_color}${type_value}${NC} routing:${routing_color}${routing_value}${NC}" + if [ ! -z "$onchain_full" ]; then + #result+=" on-chain:${onchain_color}${onchain_value}${NC}" + result+=" ${onchain_color}on-chain:${onchain_value}${NC}" + fi + + echo "$result" + else + # If the tag doesn't match the expected format, return it unchanged + echo "$tag" + fi +} + format_service_output() { local input="$1" local filepath="${input%%:*}" @@ -122,7 +189,8 @@ format_service_output() { else echo -e " ${CYAN}${filepath}${NC}" echo -e " └─ ${BOLD}$service${NC}" - echo -e " ${GREEN}${tag}${NC} ${SUCCESS}" + #echo -e " ${GREEN}${tag}${NC} ${SUCCESS}" + echo -e " $(colorize_tag "$tag")" fi else # No tag case From 27f2e3487bb63ba4133ee2276c8f1de84b631031 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 09:35:15 +0300 Subject: [PATCH 8/9] add some sample tags to services --- proto/cmp/services/accommodation/v1/info.proto | 2 +- proto/cmp/services/accommodation/v1/search.proto | 2 +- proto/cmp/services/notification/v1/notify.proto | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/proto/cmp/services/accommodation/v1/info.proto b/proto/cmp/services/accommodation/v1/info.proto index 1bf502c..a289b9c 100644 --- a/proto/cmp/services/accommodation/v1/info.proto +++ b/proto/cmp/services/accommodation/v1/info.proto @@ -40,7 +40,7 @@ message AccommodationProductInfoResponse { // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/info.proto.dot.svg) // -/// @custom:cmp-service type:product routing:p2p on-chain:fals +/// @custom:cmp-service type:product routing:p2p on-chain:false service AccommodationProductInfoService { // Returns product list for accommodation (properties) rpc AccommodationProductInfo(AccommodationProductInfoRequest) returns (AccommodationProductInfoResponse); diff --git a/proto/cmp/services/accommodation/v1/search.proto b/proto/cmp/services/accommodation/v1/search.proto index 641b554..8227173 100644 --- a/proto/cmp/services/accommodation/v1/search.proto +++ b/proto/cmp/services/accommodation/v1/search.proto @@ -118,7 +118,7 @@ message AccommodationSearchResponse { // // [Open Message Diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/proto/cmp/services/accommodation/v1/search.proto.dot.svg) // -/// @custom:cmp-service typae:product routing:p2p on-chain:false +/// @custom:cmp-service type:product routing:p2p on-chain:false service AccommodationSearchService { // Accommodation Search method rpc AccommodationSearch(AccommodationSearchRequest) returns (AccommodationSearchResponse); diff --git a/proto/cmp/services/notification/v1/notify.proto b/proto/cmp/services/notification/v1/notify.proto index 6b75a7c..5f88b6d 100644 --- a/proto/cmp/services/notification/v1/notify.proto +++ b/proto/cmp/services/notification/v1/notify.proto @@ -16,6 +16,7 @@ message TokenExpired { cmp.types.v1.UUID mint_id = 2; } +/// @custom:cmp-service type:product routing:local on-chain:true service NotificationService { rpc TokenBoughtNotification(TokenBought) returns (google.protobuf.Empty); rpc TokenExpiredNotification(TokenExpired) returns (google.protobuf.Empty); From 4e2d06d929306b59e4215db247d5a4366869dc5b Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Sat, 30 Nov 2024 09:42:00 +0300 Subject: [PATCH 9/9] add exit code to script and add to CI --- .github/workflows/ci.yaml | 9 +++++++++ scripts/analyze-service-tags.sh | 3 +++ 2 files changed, 12 insertions(+) mode change 100644 => 100755 scripts/analyze-service-tags.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 57e9798..447aa1e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -97,6 +97,15 @@ jobs: - name: Run proto dependency check run: scripts/dependency_checker.py --print-graph + # dependency check to catch if proto files were not updated correctly + analyze-service-tags: + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + - name: Run service tag analysis + run: scripts/analyze-service-tags.sh proto + # Check if we use FQPN (fully qualified package names) everywhere fqpn-check: runs-on: ubuntu-latest diff --git a/scripts/analyze-service-tags.sh b/scripts/analyze-service-tags.sh old mode 100644 new mode 100755 index f5e6eef..51ca220 --- a/scripts/analyze-service-tags.sh +++ b/scripts/analyze-service-tags.sh @@ -223,6 +223,7 @@ else for service in "${no_tag_services[@]}"; do format_service_output "$service" done + EXIT_CODE=1 fi echo -e "\n${BYELLOW}${WARNING} Services with invalid @custom:cmp-service tag:${NC}" @@ -235,6 +236,7 @@ else done echo -e "\n ${INFO} Valid values: type=\"${valid_types[@]}\" routing=\"${valid_routing[@]}\" on-chain=\"${valid_onchain[@]}\"" + EXIT_CODE=1 fi echo -e "\n${LGREEN}${SUCCESS} Services with valid @custom:cmp-service tag:${NC}" @@ -254,3 +256,4 @@ echo -e "${RED}${ERROR} Missing tags: ${#no_tag_services[@]}${NC}" echo -e "${YELLOW}${WARNING} Invalid tags: ${#invalid_tag_services[@]}${NC}" echo -e "${GREEN}${SUCCESS} Valid tags: ${#valid_tag_services[@]}${NC}" echo -e "Total services: $((${#no_tag_services[@]} + ${#invalid_tag_services[@]} + ${#valid_tag_services[@]}))" +exit $EXIT_CODE