github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/instrumentations.sh (about) 1 #!/bin/sh 2 3 # This script provides utilities to update all instrumentations to refer to the latest core module. 4 # 5 # Usage 6 # 7 # Update instrumentation phase 8 # 9 # 1. Run `./instrumentations.sh update`. This will update all instrumentations to reference the latest core module. 10 # 2. Run `make test` to ensure that all instrumentations work with the latest core. 11 # 3. If any errors are detected in some instrumentation, fix them. 12 # 4. If everything is fine, commit your changes, open a PR and get it merged into the main branch. 13 # 14 # Release phase 15 # 1. Run `./instrumentations.sh release` to create tags for each instrumentation with a new minor version, and update all version.go files. 16 17 # Checks if gh is installed, otherwise stop the script 18 if ! [ -x "$(command -v gh)" ]; then 19 echo "Error: gh is not installed." >&2 20 exit 1 21 fi 22 23 # Checks if the user is logged into Github, otherwise stop the script 24 if gh auth status 2>&1 | grep -i "You are not logged"; then 25 echo "Error: You must log into Github." >&2 26 exit 1 27 fi 28 29 CORE_VERSION=latest 30 31 # List of folders to be excluded from the instrumentation list 32 # If new matches must be added, use regular expressions. eg: 33 # EXCLUDED_DIRS="\/.*\/example|\/new_match" 34 EXCLUDED_DIRS="\/.*\/example" 35 36 # List of instrumentation folders 37 LIB_LIST=$(find ./instrumentation -name go.mod -exec dirname {} \; | grep -E -v "$EXCLUDED_DIRS") 38 39 # Updates all instrumentations to use the @latest version of the core module 40 run_update() { 41 for lib in $LIB_LIST 42 do cd "$lib" && go get github.com/instana/go-sensor@$CORE_VERSION && go mod tidy && cd -; 43 done 44 } 45 46 # Updates version.go and creates a new tag for every instrumentation, incrementing the minor version 47 run_release() { 48 TAGS="" 49 for lib in $LIB_LIST 50 do LIB_PATH="$(echo "$lib" | sed 's/\.\///')" 51 52 # Expected to find something like: instrumentation/instaredis/v1.5.0 53 # This option will be used if the instrumentation has no v2 subfolder 54 TAG_TO_SEARCH="$LIB_PATH/v[0-1].*" 55 56 # Expected to identify packages with subfolders. eg: instrumentation/instaredis/v2 57 NEW_VERSION_FOLDER=$(echo "$lib" | grep -E "v[2-9].*") 58 59 # If NEW_VERSION_FOLDER has something we update TAG_TO_SEARCH 60 if [ -n "$NEW_VERSION_FOLDER" ]; then 61 # Expected to be a version. eg: 1.5.0 62 NEW_MAJOR_VERSION=$(echo "$NEW_VERSION_FOLDER" | sed "s/.*v//") 63 64 # Expected to be tag name with major version higher than 1. eg: instrumentation/instaredis/v2.1.0 65 TAG_TO_SEARCH="$LIB_PATH/v$NEW_MAJOR_VERSION.*" 66 fi 67 68 VERSION=$(git tag -l "$TAG_TO_SEARCH" | sort -V | tail -n1 | sed "s/.*v//") 69 70 if [ -z "$VERSION" ]; then 71 VERSION="0.0.0" 72 fi 73 74 MINOR_VERSION=$(echo "$VERSION" | sed -En 's/[0-9]+\.([0-9]+)\.[0-9]+/\1/p') 75 MAJOR_VERSION=$(echo "$VERSION" | sed -En 's/([0-9]+)\.[0-9]+\.[0-9]+/\1/p') 76 MINOR_VERSION=$((MINOR_VERSION+1)) 77 NEW_VERSION="$MAJOR_VERSION.$MINOR_VERSION.0" 78 79 # Updates the minor version in version.go 80 sed -i '' -E "s/[0-9]+\.[0-9]+\.[0-9]+/${NEW_VERSION}/" "$lib"/version.go | tail -1 81 82 # Tags to be created after version.go is merged to the main branch with the new version 83 PATH_WITHOUT_V=$(echo "$LIB_PATH" | sed "s/\/v[0-9]*//") 84 TAGS="$TAGS $PATH_WITHOUT_V/v$MAJOR_VERSION.$MINOR_VERSION.0" 85 done 86 87 # Commit all version.go files to the main branch 88 git add ./instrumentation/**/version.go 89 git add ./instrumentation/**/**/version.go 90 git commit -m "Bumping new version of the instrumentation" 91 git push origin main 92 93 echo "Creating tags for each instrumentation" 94 95 for t in $TAGS 96 do git tag "$t" && git push origin "$t" 97 done 98 99 # Release every instrumentation 100 for t in $TAGS 101 do gh release create "$t" \ 102 --title "$t" \ 103 --notes "Updated instrumentation with the latest version of go-sensor core module.<br/><br/> --auto-generated--" 104 done 105 } 106 107 run_replace() { 108 ROOT_DIR="$PWD" 109 110 for lib in $LIB_LIST 111 do cd "$lib" && go mod edit -replace=github.com/instana/go-sensor="$ROOT_DIR" && cd -; 112 done 113 } 114 115 run_dropreplace() { 116 ROOT_DIR="$PWD" 117 118 for lib in $LIB_LIST 119 do cd "$lib" && go mod edit -dropreplace=github.com/instana/go-sensor && cd -; 120 done 121 } 122 123 if [ "$1" = "update" ]; then 124 run_update 125 exit 0 126 fi 127 128 if [ "$1" = "release" ]; then 129 run_release 130 exit 0 131 fi 132 133 if [ "$1" = "replace" ]; then 134 run_replace 135 exit 0 136 fi 137 138 if [ "$1" = "dropreplace" ]; then 139 run_dropreplace 140 exit 0 141 fi 142 143 echo "---------------------------------------------------------" 144 echo "Usage: $0 COMMAND" 145 echo "" 146 echo "Where COMMAND can be:" 147 echo "- update: Updates every instrumentation to reference the latest version of the core" 148 echo "- release: Releases all instrumentations by increasing a minor version" 149 echo "- replace: Adds the 'replace' directive into the go.mod file of each instrumentation changing github.com/instana/go-sensor to the local path" 150 echo "- dropreplace: Removes existing 'replace' directives that changes github.com/instana/go-sensor to a different path" 151 echo "" 152 echo "Example: $0 update" 153 echo "---------------------------------------------------------"