Skip to content

Updating instrumentation instalambda for new version v1.42.0. Id: 1702353877 #62

Updating instrumentation instalambda for new version v1.42.0. Id: 1702353877

Updating instrumentation instalambda for new version v1.42.0. Id: 1702353877 #62

# This workflow releases all instrumented packages updated to point to the latest core module.
# It should run in the main branch after the PR created by the `Go Tracer Release` workflow is merged to main.
name: Release all updated instrumentations
on:
pull_request:
branches:
- main
types:
- closed
jobs:
release_instrumentations:
name: Release instrumentations
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'update-instrumentations-core')
steps:
- uses: actions/checkout@v3
name: Checkout repo
with:
fetch-depth: 0
ssh-key: ${{secrets.PRIVATE_KEY_GO_TRACER_RELEASE}}
- name: Release all packages
id: release-packages
run: |
CORE_TAG=$(git tag -l "v1.*" | sort -V | tail -n1)
git config user.name "IBM/Instana/Team Go"
git config user.email "github-actions@github.com"
EXCLUDED_DIRS="\/.*\/example"
LIB_LIST=$(find ./instrumentation -name go.mod -exec dirname {} \; | grep -E -v "$EXCLUDED_DIRS")
TAGS=""
for lib in $LIB_LIST
do LIB_PATH="$(echo "$lib" | sed 's/\.\///')"
# Expected to find something like: instrumentation/instaredis/v1.5.0
# This option will be used if the instrumentation has no v2 subfolder
TAG_TO_SEARCH="$LIB_PATH/v[0-1].*"
# Expected to identify packages with subfolders. eg: instrumentation/instaredis/v2
NEW_VERSION_FOLDER=$(echo "$lib" | grep -E "/v[2-9].*")
# If NEW_VERSION_FOLDER has something we update TAG_TO_SEARCH
if [ -n "$NEW_VERSION_FOLDER" ]; then
# Expected to be a version. eg: 1.5.0
NEW_MAJOR_VERSION=$(echo "$NEW_VERSION_FOLDER" | sed "s/.*v//")
# Expected to be tag name with major version higher than 1. eg: instrumentation/instaredis/v2.1.0
PATH_WITHOUT_V=$(echo "$LIB_PATH" | sed "s/\/v[0-9]*//")
TAG_TO_SEARCH="$PATH_WITHOUT_V/v$NEW_MAJOR_VERSION.*"
fi
VERSION=$(git tag -l "$TAG_TO_SEARCH" | sort -V | tail -n1 | sed "s/.*v//")
if [ -z "$VERSION" ]; then
VERSION="0.0.0"
fi
MINOR_VERSION=$(echo "$VERSION" | sed -En 's/[0-9]+\.([0-9]+)\.[0-9]+/\1/p')
MAJOR_VERSION=$(echo "$VERSION" | sed -En 's/([0-9]+)\.[0-9]+\.[0-9]+/\1/p')
MINOR_VERSION=$((MINOR_VERSION+1))
NEW_VERSION="$MAJOR_VERSION.$MINOR_VERSION.0"
# Updates the minor version in version.go
sed -i -E "s/[0-9]+\.[0-9]+\.[0-9]+/${NEW_VERSION}/" "$lib"/version.go | tail -1
# Tags to be created after version.go is merged to the main branch with the new version
PATH_WITHOUT_V=$(echo "$LIB_PATH" | sed "s/\/v[0-9]*//")
TAGS="$TAGS $PATH_WITHOUT_V/v$MAJOR_VERSION.$MINOR_VERSION.0"
done
echo "TAGS=$TAGS" >> "$GITHUB_OUTPUT"
# Commit all version.go files to the main branch
git add ./instrumentation/**/version.go
git add ./instrumentation/**/**/version.go
git commit -m "Updated instrumented packages with core module $CORE_TAG"
git push origin @
echo "Creating tags for each instrumentation"
for t in $TAGS
do git tag "$t" && git push origin "$t"
done
# Release every instrumentation
for t in $TAGS
do gh release create "$t" \
--title "$t" \
--notes "Updated instrumentation with the latest version of go-sensor core module $CORE_TAG.<br/><br/> --auto-generated--"
done
shell: bash {0}
env:
GH_TOKEN: ${{ github.token }}
- name: Update pkg.go.dev
run: |
#!/bin/bash
mkdir dummy && cd dummy
go mod init example.com
echo "get packages..."
for t in ${{ steps.release-packages.outputs.TAGS }}
do go get github.com/instana/go-sensor/$(echo "$t" | sed 's/\/v/@v/') || echo "Error getting package $t, but moving forward..."
done
cd ..
rm -rf dummy