1+ name : Auto-update agents
2+
3+ on :
4+ schedule :
5+ # Daily at 01:30 (UTC)
6+ - cron : ' 30 1 * * *'
7+ workflow_dispatch :
8+ pull_request :
9+
10+ jobs :
11+ update-agent :
12+ runs-on : ubuntu-latest
13+ strategy :
14+ matrix :
15+ agent : [java, dotnet, nodejs, python]
16+ steps :
17+ - uses : actions/checkout@v4
18+
19+ - id : check-versions
20+ name : Check versions
21+ env :
22+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ run : |
24+ case ${{ matrix.agent }} in
25+ java)
26+ current_version=$(grep -Po "[0-9]+.[0-9]+.[0-9]+" autoinstrumentation/java/version.txt)
27+ latest_version=$(gh release view \
28+ --repo open-telemetry/opentelemetry-java-instrumentation \
29+ --json tagName \
30+ --jq .tagName \
31+ | sed 's/^v//')
32+ ;;
33+ dotnet)
34+ current_version=$(grep -Po "[0-9]+.[0-9]+.[0-9]+" autoinstrumentation/dotnet/version.txt)
35+ latest_version=$(gh release view \
36+ --repo open-telemetry/opentelemetry-dotnet-instrumentation \
37+ --json tagName \
38+ --jq .tagName \
39+ | sed 's/^v//')
40+ ;;
41+ nodejs)
42+ current_version=$(grep -Po '"@opentelemetry/auto-instrumentations-node": "\K[0-9]+\.[0-9]+\.[0-9]+"' autoinstrumentation/nodejs/package.json | tr -d '"')
43+ latest_version=$(gh release list \
44+ --repo open-telemetry/opentelemetry-js-contrib \
45+ --json tagName \
46+ --jq '.[] | select(.tagName | startswith("auto-instrumentations-node-v")) | .tagName' \
47+ | head -1 \
48+ | sed 's/auto-instrumentations-node-v//')
49+ ;;
50+ python)
51+ current_version=$(grep -Po "^opentelemetry-distro==\K[0-9]+\.[0-9]+(b[0-9]+)?" autoinstrumentation/python/requirements.txt)
52+ # Python releases are not tagged with the same version published on PyPI. Instead, we extract the PyPI version from the release name.
53+ latest_version=$(gh release view \
54+ --repo open-telemetry/opentelemetry-python \
55+ --json name \
56+ --jq .name \
57+ | sed -E 's/.*\/([0-9]+\.[0-9]+(b[0-9]+)?).*/\1/')
58+ ;;
59+ esac
60+
61+ matches=$(gh pr list \
62+ --author opentelemetrybot \
63+ --state open \
64+ --search "in:title \"Update the OpenTelemetry ${{ matrix.agent }} agent version to $latest_version\"")
65+ if [ ! -z "$matches" ]
66+ then
67+ already_opened=true
68+ fi
69+
70+ # Ensure proper format and remove any unintended characters
71+ echo "current-version=${current_version}" >> $GITHUB_OUTPUT
72+ echo "latest-version=${latest_version}" >> $GITHUB_OUTPUT
73+ echo "already-opened=${already_opened}" >> $GITHUB_OUTPUT
74+
75+ # Debug information
76+ echo "Debug information for ${{ matrix.agent }} agent:"
77+ echo "Current version detected: ${current_version}"
78+ echo "Latest version detected: ${latest_version}"
79+ echo "PR already opened for this version: ${already_opened:-false}"
80+ echo "Version comparison: Current ${current_version} vs Latest ${latest_version}"
81+
82+ # Additional validation
83+ if [[ -z "$current_version" ]]; then
84+ echo "WARNING: Failed to detect current version"
85+ fi
86+
87+ if [[ -z "$latest_version" ]]; then
88+ echo "WARNING: Failed to detect latest version"
89+ fi
90+
91+ # Print PR search query details
92+ echo "PR search query: \"Update the OpenTelemetry ${{ matrix.agent }} agent version to $latest_version\""
93+ echo "PR search results: ${matches:-none}"
94+
95+ - name : Update version
96+ if : |
97+ steps.check-versions.outputs.current-version != steps.check-versions.outputs.latest-version &&
98+ steps.check-versions.outputs.already-opened != 'true'
99+ env :
100+ VERSION : ${{ steps.check-versions.outputs.latest-version }}
101+ run : |
102+ case ${{ matrix.agent }} in
103+ java)
104+ echo $VERSION > autoinstrumentation/java/version.txt
105+ ;;
106+ dotnet)
107+ echo $VERSION > autoinstrumentation/dotnet/version.txt
108+ ;;
109+ nodejs)
110+ sed -i "s/\"@opentelemetry\/auto-instrumentations-node\": \".*\"/\"@opentelemetry\/auto-instrumentations-node\": \"$VERSION\"/" autoinstrumentation/nodejs/package.json
111+ ;;
112+ python)
113+ sed -i "s/^opentelemetry-distro==.*/opentelemetry-distro==$VERSION/" autoinstrumentation/python/requirements.txt
114+ ;;
115+ esac
116+
117+ - name : Use CLA approved github bot
118+ run : |
119+ git config user.name opentelemetrybot
120+ git config user.email 107717825+opentelemetrybot@users.noreply.github.com
121+
122+ - name : Create pull request against main
123+ if : |
124+ steps.check-versions.outputs.current-version != steps.check-versions.outputs.latest-version &&
125+ steps.check-versions.outputs.already-opened != 'true'
126+ env :
127+ VERSION : ${{ steps.check-versions.outputs.latest-version }}
128+ # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
129+ GH_TOKEN : ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
130+ run : |
131+ message="Update the OpenTelemetry ${{ matrix.agent }} agent version to $VERSION"
132+ body="Update the OpenTelemetry ${{ matrix.agent }} agent version to \`$VERSION\`."
133+ branch="opentelemetrybot/update-opentelemetry-${{ matrix.agent }}-agent-to-${VERSION}"
134+
135+ git checkout -b $branch
136+ git commit -a -m "$message"
137+ # Only push and create PR when not triggered by a pull_request event
138+ if [[ "${{ github.event_name }}" != "pull_request" ]]; then
139+ git push --set-upstream origin $branch
140+ gh pr create --title "$message" \
141+ --body "$body" \
142+ --base main
143+ else
144+ git show HEAD
145+ fi
0 commit comments