Skip to content

Commit

Permalink
Merge pull request #509 from instana/sh-release-pipeline-improvements
Browse files Browse the repository at this point in the history
Automation pipeline improvements
  • Loading branch information
nithinputhenveettil authored Jan 3, 2024
2 parents 89c008e + 4f56149 commit 58a2963
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 87 deletions.
27 changes: 27 additions & 0 deletions supported_versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
| Serial Number | Technology | Target Package | Instana Package | Supported Lowest Version - Target Package | Supported Highest Version - Target Package |
| ------------- | ---------- | --------------- | --------------- | ----------------------------------------- | ----------------------------------------- |
| 1 | HTTP | net/http | | | |
| 2 | HTTP | [echo](https://pkg.go.dev/github.com/labstack/echo/v4) | [instaecho](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaecho) | v4.6.0 | v4.9.0 |
| 3 | HTTP | [gin](https://pkg.go.dev/github.com/gin-gonic/gin) | [instagin](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagin) | v1.7.2 | v1.9.1 |
| 4 | HTTP | [mux](https://pkg.go.dev/github.com/gorilla/mux) | [instamux](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamux) | v1.8.0 | v1.8.0 |
| 5 | HTTP | [httprouter](http://pkg.go.dev/github.com/julienschmidt/httprouter) | [instahttprouter](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instahttprouter) | v1.3.0 | v1.3.0 |
| 6 | HTTP | [fiber](https://pkg.go.dev/github.com/gofiber/fiber/v2) | [instafiber](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instafiber) | v2.48.0 | v2.51.0 |
| 7 | RPC | [grpc](https://pkg.go.dev/google.golang.org/grpc) | [instagrpc](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagrpc) | v1.15.0 | v1.59.0 |
| 8 | Databases | database/sql | | | |
| 9 | Databases | [mongo-driver](https://pkg.go.dev/go.mongodb.org/mongo-driver) | [instamongo](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instamongo) | v1.7.2 | v1.13.0 |
| 10 | Databases | [pgx](https://pkg.go.dev/github.com/jackc/pgx/v4) | [instapgx](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instapgx) | v4.14.1 | v4.18.1 |
| 11 | Databases | [go-redis](https://pkg.go.dev/github.com/go-redis/redis/v8) | [instaredis](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis) | v8.11.4 | v8.11.4 |
| 12 | Databases | [redigo](https://pkg.go.dev/github.com/gomodule/redigo) | [instaredigo](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredigo) | v1.8.8 | v1.8.8 |
| 13 | Databases | [gorm](https://pkg.go.dev/gorm.io/gorm) | [instagorm](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagorm) | v1.25.0 | v1.25.0 |
| 14 | Messaging | [pubsub](https://pkg.go.dev/cloud.google.com/go/pubsub) | [instapubsub](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/cloud.google.com/go/pubsub) | v1.3.1 | v1.33.0 |
| 15 | Messaging | [sarama](https://pkg.go.dev/github.com/IBM/sarama) | [instasarama](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instasarama) | v1.19.0 | v1.41.3 |
| 16 | Messaging | [amqp](https://pkg.go.dev/github.com/streadway/amqp) | [instaamqp](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp) | v1.0.0 | v1.1.0 |
| 17 | Messaging | [amqp091-go](https://pkg.go.dev/github.com/rabbitmq/amqp091-go) | [instaamqp091](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaamqp091) | v1.5.0 | v1.9.0 |
| 18 | GraphQL | [graphql](https://pkg.go.dev/github.com/graphql-go/graphql) | [instagraphql](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instagraphql) | v0.8.0 | v0.8.1 |
| 19 | Other | [storage](https://pkg.go.dev/cloud.google.com/go/storage) | [storage](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/cloud.google.com/go/storage) | v1.7.0 | v1.33.0 |
| 20 | Other | [aws-sdk-go](https://pkg.go.dev/github.com/aws/aws-sdk-go) | [instaawssdk](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawssdk) | v1.8.0 | v1.48.3 |
| 21 | Other | [aws-lambda-go](https://pkg.go.dev/github.com/aws/aws-lambda-go) | [instalambda](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalambda) | v1.20.0 | v1.41.0 |
| 22 | Other | [logrus](https://pkg.go.dev/github.com/sirupsen/logrus) | [instalogrus](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instalogrus) | v1.5.0 | v1.9.3 |
| 23 | Databases | [go-redis v2](https://pkg.go.dev/github.com/redis/go-redis/v9) | [instaredis](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaredis/v2) | v8.11.4 | v9.0.2 |
| 24 | HTTP | [beego](https://pkg.go.dev/github.com/beego/beego/v2) | [instabeego](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instabeego) | v2.1.3 | v2.1.3 |
| 25 | Other | [aws-sdk-go](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2) | [instaawsv2](https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/instaawsv2) | v1.21.0 | v1.21.0 |
208 changes: 121 additions & 87 deletions version_updater.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
# Script to monitor the packages and update the instrumentation packages #
# ---------------------------------------------------------------------- #

# Function to extract the package url and current version from the metadata
extract_info_from_markdown() {
if [ -e "$1" ]; then
local markdown_text=$(<"$1")
# Extract target-package-url and current-version using awk
TARGET_PKG_URL=$(echo "$markdown_text" | awk -F: '/target-pkg-url:/ {print $2}' | tr -d '[:space:]')
CURRENT_VERSION=$(echo "$markdown_text" | awk -F: '/current-version:/ {print $2}' | tr -d '[:space:]')
else
echo "Error: File not found - $1"
TARGET_PKG_URL=""
CURRENT_VERSION=""
fi

# Function to extract the package url, current version and local path from the markdown line
extract_info_from_markdown_line() {
# if [ -e "$1" ]; then
local markdown_line=$1
# Extract target-package-url, current version and local path from the markdown line usin awk
TARGET_PKG_URL=$(echo "$markdown_line" | awk -F '[(|)]' '{print $5}' | awk -F'https://pkg.go.dev/' '{print $2}')
INSTANA_PKG_URL=$(echo "$markdown_line" | awk -F '[(|)]' '{print $8}')
TARGET_PACKAGE_NAME=$(echo "$markdown_line" | awk -F '[][]' '{print $2}' | tr -d '[:space:]' | tr -d '()')
INSTANA_PACKAGE_NAME=$(echo "$markdown_line" | awk -F '[][]' '{print $4}' | tr -d '[:space:]' | tr -d '()')
LOCAL_PATH=$(echo "$INSTANA_PKG_URL" | awk -F 'github.com/instana/go-sensor/' '{print $2}')
CURRENT_VERSION=$(echo "$markdown_line" | awk -F '|' '{print $7}' | tr -d '[:space:]')

}

# Function to query the latest released version of the package
Expand All @@ -26,6 +27,8 @@ find_latest_version() {
if [ -n "$pkg" ]; then
# Query the latest version for the package
local url="https://proxy.golang.org/${pkg}/@latest"
echo $url
curl -s "$url"
LATEST_VERSION=$(curl -s "$url" | jq .Version | tr -d '"')
else
LATEST_VERSION=""
Expand All @@ -39,106 +42,137 @@ version_compare() {
local version1=$1
local version2=$2

local major_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
local minor_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')
local major_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\1/')
local minor_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\..*/\2/')
local major_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/')
local minor_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/')
local patch_version1=$(echo "$version1" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/')
local major_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/')
local minor_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/')
local patch_version2=$(echo "$version2" | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/')

echo $major_version1, $minor_version1, $patch_version1

UPDATE_NEEDED="false"

# We are checking the changes in minor versions for automation purpose
if [ "$major_version1" = "$major_version2" ] && [ "$minor_version1" -gt "$minor_version2" ]; then
echo "true"
else
echo "false"
if [ "$major_version1" = "$major_version2" ]; then
if [ "$minor_version1" -gt "$minor_version2" ]; then
UPDATE_NEEDED="true"
elif [ "$minor_version1" = "$minor_version2" ]; then
if [ "$patch_version1" -gt "$patch_version2" ]; then
UPDATE_NEEDED="true"
fi
fi
elif [ "$major_version1" -gt "$major_version2" ]; then
echo "Major version update needed"
fi

}

# Function to update the metadata with the latest version information
replace_version_in_file() {
local version=$1
local file_path=$2

# Read the content of the file
local file_content=$(<"$file_path")
TRACER_PATH=$(pwd)
LIBRARY_INFO_MD_PATH=$(pwd)/supported_versions.md
LIBRARY_INFO_MD_TMP=$(pwd)/supported_versions_temp.md
LIBRARY_INFO_MD_PATH_COPY=$(pwd)/supported_versions_copy.md

# Replace current-version with the new version
# shellcheck disable=SC2001
local updated_content=$(echo "$file_content" | sed "s/current-version: [^ ]*/current-version: $version/")
# Check if the file exists
if [ ! -f "$LIBRARY_INFO_MD_PATH" ]; then
echo "Error: File '$LIBRARY_INFO_MD_PATH' not found."
exit 1
fi

# Write the updated content back to the file
echo "$updated_content" > "$file_path"
echo "Version in file $file_path updated to $version"
}
# Copy the original file
cp $LIBRARY_INFO_MD_PATH $LIBRARY_INFO_MD_PATH_COPY

# Open the file and read it line by line
first_line=true
while IFS= read -r line; do
# Skip the first line
# As it only contains the markdown headers
if [ "$first_line" = true ]; then
first_line=false
continue
fi

echo "Processing line: $line"
extract_info_from_markdown_line "$line"

DIRECTORY_PATH=$(pwd)/instrumentation
echo "$DIRECTORY_PATH"
# Create a branch and commit the changes
git config user.name "IBM/Instana/Team Go"
git config user.email "github-actions@github.com"

if [ -d "$DIRECTORY_PATH" ]; then
for folder in "$DIRECTORY_PATH"/*/; do
# Create a branch and commit the changes
git config user.name "IBM/Instana/Team Go"
git config user.email "github-actions@github.com"
git checkout main

git checkout main
folder=$TRACER_PATH/$LOCAL_PATH

INSTRUMENTATION=$(basename "$folder")
# Identify the path to the README file
README_PATH="${folder}README.md"
INSTRUMENTATION=$INSTANA_PACKAGE_NAME

echo "--------------$INSTRUMENTATION-----------------"
if [ ! -e "$README_PATH" ]; then
continue
fi
echo "--------------$INSTRUMENTATION-----------------"

# Extract the metadata from the README file
extract_info_from_markdown "$README_PATH"
# Print the extracted values
echo "Target Package URL: $TARGET_PKG_URL"
echo "Instana Package URL: $INSTANA_PKG_URL"
echo "Target Package Text: $TARGET_PACKAGE_NAME"
echo "Instana Package Text: $INSTANA_PACKAGE_NAME"
echo "Local Path: $LOCAL_PATH"
echo "Current version: $CURRENT_VERSION"

if [ -z "$TARGET_PKG_URL" ]; then
continue
fi
if [ -z "$TARGET_PKG_URL" ]; then
continue
fi

# Print the extracted values
#echo "Target Package URL: $TARGET_PKG_URL"
echo "Current Version: $CURRENT_VERSION"
# Find the latest version of the instrumented package
find_latest_version "$TARGET_PKG_URL"
echo "Latest version:" "$LATEST_VERSION"

# Find the latest version of the instrumented package
find_latest_version "$TARGET_PKG_URL"
echo "Latest version:" "$LATEST_VERSION"
version_compare "$LATEST_VERSION" "$CURRENT_VERSION"

version_compare "$LATEST_VERSION" "$CURRENT_VERSION"
update_needed=$( version_compare "$LATEST_VERSION" "$CURRENT_VERSION" )
if [ "$UPDATE_NEEDED" != true ]; then
continue
fi

if [ "$update_needed" != true ]; then
continue
fi
if gh pr list | grep -q "instrumentation $INSTRUMENTATION for new version $LATEST_VERSION"; then
echo "PR for $INSTRUMENTATION newer version:$LATEST_VERSION already exists. Skipping to next iteration"
continue
fi

if gh pr list | grep -q "instrumentation $INSTRUMENTATION for new version $LATEST_VERSION"; then
echo "PR for $INSTRUMENTATION newer version:$LATEST_VERSION already exists. Skipping to next iteration"
continue
fi
echo "Update needed for this package. Update process starting..."

# For some packages, eg : https://pkg.go.dev/github.com/instana/go-sensor/instrumentation/cloud.google.com/go/storage
# The go.mod file will be in the previous directory
# Need this check here to proceed to the correct directry containing go.mod
LOCAL_PATH_2=$(go list -m | awk -F 'github.com/instana/go-sensor/' '{print $2}')

echo "Update needed for this package. Update process starting..."
if [ "$LOCAL_PATH" = "$LOCAL_PATH_2" ]; then
cd "$folder" || continue
go get "$TARGET_PKG_URL"
go mod tidy
go test ./... || echo "Continuing the operation even if the test fails. This needs manual intervention"
else
# change working folder to the correct path
folder=$TRACER_PATH/$LOCAL_PATH_2
cd "$folder" || continue
fi

go get "$TARGET_PKG_URL"
go mod tidy
go test ./... || echo "Continuing the operation even if the test fails. This needs manual intervention"

# Need to update the current version in the README file
replace_version_in_file "$LATEST_VERSION" "$README_PATH"
# Need to update the current version in the supported_versions.md file
new_line=$(echo "$line" | awk -v old_value="$CURRENT_VERSION" -v new_value="$LATEST_VERSION" '{ gsub(old_value, new_value, $0); print }')
awk -v new_line="$new_line" '{ if ($0 == old_line) print new_line; else print }' old_line="$line" $LIBRARY_INFO_MD_PATH > $LIBRARY_INFO_MD_TMP && mv $LIBRARY_INFO_MD_TMP $LIBRARY_INFO_MD_PATH

CURRENT_TIME_UNIX=$(date '+%s')
git checkout -b "update-instrumentations-$INSTRUMENTATION-id-$CURRENT_TIME_UNIX"

git add go.mod go.sum README.md
git commit -m "Updated go.mod, go.sum files, README.md for $INSTRUMENTATION"
git push origin @
CURRENT_TIME_UNIX=$(date '+%s')
git checkout -b "update-instrumentations-$INSTRUMENTATION-id-$CURRENT_TIME_UNIX"

# Create a PR request for the changes
# shellcheck disable=SC2046
gh pr create --title "Updating instrumentation $INSTRUMENTATION for new version $LATEST_VERSION. Id: $CURRENT_TIME_UNIX" \
--body "This PR adds changes for the newer version $LATEST_VERSION for the instrumented package" --head $(git branch --show-current)
git add go.mod go.sum $LIBRARY_INFO_MD_PATH
git commit -m "Updated go.mod, go.sum files, README.md for $INSTRUMENTATION"
git push fork @

# Create a PR request for the changes
# shellcheck disable=SC2046
gh pr create --title "Updating instrumentation $INSTRUMENTATION for new version $LATEST_VERSION. Id: $CURRENT_TIME_UNIX" \
--body "This PR adds changes for the newer version $LATEST_VERSION for the instrumented package" --head $(git branch --show-current)

# Back to working directry
cd $TRACER_PATH

done < "$LIBRARY_INFO_MD_PATH_COPY"

done
else
echo "Error: The specified path is not a directory."
fi

0 comments on commit 58a2963

Please sign in to comment.