github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/currency_report.sh (about) 1 #!/bin/bash 2 3 # (c) Copyright IBM Corp. 2024 4 5 # Function to extract the package url and other data from the markdown line 6 extract_info_from_markdown_line() { 7 local markdown_line=$1 8 # Extract target-package-url and local path from the markdown line using awk 9 TARGET_PKG_URL=$(echo "$markdown_line" | awk -F '[(|)]' '{print $10}' | awk -F'https://pkg.go.dev/' '{print $2}') 10 INSTANA_PKG_URL=$(echo "$markdown_line" | awk -F '[(|)]' '{print $13}') 11 TARGET_PACKAGE_NAME=$(echo "$markdown_line" | awk -F '|' '{print $2}') 12 LOCAL_PATH=$(echo "$INSTANA_PKG_URL" | awk -F 'github.com/instana/go-sensor/' '{print $2}') 13 14 IS_STANDARD_LIBRARY="false" 15 IS_DEPRECATED="false" 16 17 if [[ $(echo "$markdown_line" | awk -F '|' '{print $11}') == " Standard library " ]]; then 18 echo "Standard library" 19 IS_STANDARD_LIBRARY="true" 20 fi 21 22 if [[ $(echo "$markdown_line" | awk -F '|' '{print $3}') == " Deprecated " ]]; then 23 echo "Deprecated" 24 IS_DEPRECATED="true" 25 fi 26 27 28 } 29 30 # Function to query the latest released version of the package 31 find_latest_version() { 32 local pkg=$1 33 if [ -n "$pkg" ]; then 34 # Query the latest version for the package 35 local url="https://proxy.golang.org/${pkg}/@latest" 36 local url1=$(echo "$url" | awk '{ print tolower($0) }') 37 echo $url1 38 LATEST_VERSION=$(curl -s "$url1" | awk -F '[:,]' '/Version/{print $2}' | tr -d '"' | tr -d 'v') 39 else 40 LATEST_VERSION="" 41 echo "Invalid package location: $pkg" 42 echo "Invalid package location: $pkg" >> $OUTPUT_TO_SLACK 43 fi 44 45 } 46 47 # Function to find the current version of the package using go command. 48 find_current_version(){ 49 local pkg=$1 50 CURRENT_VERSION=$(go list -m $pkg | awk '{print $NF}') 51 if ! [[ "$CURRENT_VERSION" =~ ^"v" ]]; then 52 echo "Invalid current version" 53 CURRENT_VERSION="" 54 else 55 CURRENT_VERSION=$(echo "$CURRENT_VERSION" | tr -d 'v') 56 fi 57 } 58 59 # This script needs to be called from the go-sensor folder. 60 GO_TRACER_REPO_PATH=$(pwd) 61 TRACER_REPORTS_REPO_PATH=$(pwd)/../tracer-reports 62 GO_REPORTS_MD_PATH=$TRACER_REPORTS_REPO_PATH/automated/currency/go/report.md 63 GO_REPORTS_MD_PATH_COPY=$TRACER_REPORTS_REPO_PATH/automated/currency/go/report_copy.md 64 GO_REPORTS_MD_PATH_TMP=$TRACER_REPORTS_REPO_PATH/automated/currency/go/report_temp.md 65 OUTPUT_TO_SLACK=$GO_TRACER_REPO_PATH/output.txt 66 67 # Copy the original file 68 cp $GO_REPORTS_MD_PATH $GO_REPORTS_MD_PATH_COPY 69 rm $OUTPUT_TO_SLACK 70 71 skip_execution=true 72 first_line=true 73 while IFS= read -r line; do 74 75 if [ "$first_line" = true ]; then 76 first_line=false 77 changed_line="#### Note: This page is auto-generated. Any change will be overwritten after the next sync. For more details on Go Tracer SDK, please visit our [Github](https://github.com/instana/go-sensor) page. Last updated on $(date +'%d.%m.%Y')." 78 # Update the markdown report file 79 awk -v new_line="$changed_line" '{ if ($0 == old_line) print new_line; else print }' old_line="$line" $GO_REPORTS_MD_PATH > $GO_REPORTS_MD_PATH_TMP && mv $GO_REPORTS_MD_PATH_TMP $GO_REPORTS_MD_PATH 80 continue 81 fi 82 83 # For skipping first few lines from the md file. 84 if [ "$skip_execution" = true ]; then 85 if [ "$line" = "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |" ]; then 86 skip_execution=false 87 fi 88 continue 89 fi 90 91 extract_info_from_markdown_line "$line" 92 93 94 if [ "$IS_STANDARD_LIBRARY" = "true" ] || [ "$IS_DEPRECATED" = "true" ]; then 95 # skip execution 96 continue 97 fi 98 99 folder=$GO_TRACER_REPO_PATH/$LOCAL_PATH 100 101 cd $folder 102 # Find the latest version of the instrumented package 103 find_latest_version "$TARGET_PKG_URL" 104 find_current_version "$TARGET_PKG_URL" 105 106 # Replace supported and latest version in the markdown line 107 changed_line=$(echo "$line" | awk -v new_val="$(printf ' %s ' "$CURRENT_VERSION")" 'BEGIN{OFS=FS="|"} {$5=new_val} 1') 108 changed_line=$(echo "$changed_line" | awk -v new_val="$(printf ' %s ' "$LATEST_VERSION")" 'BEGIN{OFS=FS="|"} {$6=new_val} 1') 109 110 if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then 111 echo "Latest version:" "$LATEST_VERSION" 112 echo "Current version:" "$CURRENT_VERSION" 113 114 echo "$TARGET_PACKAGE_NAME - $CURRENT_VERSION - $LATEST_VERSION" >> $OUTPUT_TO_SLACK 115 116 changed_line=$(echo "$changed_line" | awk -v new_val=" No " 'BEGIN{OFS=FS="|"} {$7=new_val} 1') 117 else 118 changed_line=$(echo "$changed_line" | awk -v new_val=" Yes " 'BEGIN{OFS=FS="|"} {$7=new_val} 1') 119 fi 120 121 # Update the markdown report file 122 awk -v new_line="$changed_line" '{ if ($0 == old_line) print new_line; else print }' old_line="$line" $GO_REPORTS_MD_PATH > $GO_REPORTS_MD_PATH_TMP && mv $GO_REPORTS_MD_PATH_TMP $GO_REPORTS_MD_PATH 123 124 cd $GO_TRACER_REPO_PATH 125 done < "$GO_REPORTS_MD_PATH_COPY" 126 127 rm $GO_REPORTS_MD_PATH_COPY