-
Notifications
You must be signed in to change notification settings - Fork 4
269 lines (223 loc) · 11.5 KB
/
update_native_agent.yml
File metadata and controls
269 lines (223 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: Update Native Agent Versions
on:
workflow_dispatch:
inputs:
android_version:
description: 'Android agent version (leave empty to fetch latest)'
required: false
type: string
ios_version:
description: 'iOS agent version (leave empty to fetch latest)'
required: false
type: string
create_pr:
description: 'Create PR with new branch (always true for this workflow)'
required: false
type: boolean
default: true
push:
branches:
- '**'
paths:
- '.github/workflows/update_native_agent.yml'
schedule:
# Run weekly on Monday at 9:00 AM UTC to check for updates
- cron: '0 9 * * 1'
jobs:
update-versions:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq xmlstarlet
- name: Fetch latest Android agent version
id: android_version
run: |
if [ -n "${{ inputs.android_version }}" ]; then
VERSION="${{ inputs.android_version }}"
echo "Using provided Android version: $VERSION"
else
# Fetch latest version from Maven Central metadata
VERSION=$(curl -s 'https://repo1.maven.org/maven2/com/newrelic/agent/android/android-agent/maven-metadata.xml' | \
grep '<latest>' | \
sed 's/.*<latest>\(.*\)<\/latest>.*/\1/')
echo "Fetched latest Android version: $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Fetch latest iOS agent version
id: ios_version
run: |
if [ -n "${{ inputs.ios_version }}" ]; then
VERSION="${{ inputs.ios_version }}"
echo "Using provided iOS version: $VERSION"
else
# Fetch latest version from CocoaPods using jq to properly parse JSON
VERSION=$(curl -s 'https://trunk.cocoapods.org/api/v1/pods/NewRelicAgent' | \
jq -r '.versions[-1].name')
echo "Fetched latest iOS version: $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Get current versions
id: current_versions
run: |
# Extract current versions from package.json
CURRENT_PLUGIN=$(jq -r '.version' package.json)
# Extract Android version from TestUnityDependencies.xml
CURRENT_ANDROID=$(xmlstarlet sel -t -v "//androidPackage[contains(@spec, 'android-agent')]/@spec" com.newrelic.agent/Editor/TestUnityDependencies.xml | sed 's/.*:\([0-9.]*\).*/\1/')
# Extract iOS version from TestUnityDependencies.xml
CURRENT_IOS=$(xmlstarlet sel -t -v "//iosPod[@name='NewRelicAgent']/@version" com.newrelic.agent/Editor/TestUnityDependencies.xml | sed 's/~> //')
echo "current_android=$CURRENT_ANDROID" >> $GITHUB_OUTPUT
echo "current_ios=$CURRENT_IOS" >> $GITHUB_OUTPUT
echo "current_plugin=$CURRENT_PLUGIN" >> $GITHUB_OUTPUT
echo "Current Android version: $CURRENT_ANDROID"
echo "Current iOS version: $CURRENT_IOS"
echo "Current Plugin version: $CURRENT_PLUGIN"
- name: Check if updates are needed
id: check_updates
run: |
NEEDS_UPDATE=false
ANDROID_UPDATED=false
IOS_UPDATED=false
if [ "${{ steps.current_versions.outputs.current_android }}" != "${{ steps.android_version.outputs.version }}" ]; then
echo "Android version needs update"
NEEDS_UPDATE=true
ANDROID_UPDATED=true
fi
if [ "${{ steps.current_versions.outputs.current_ios }}" != "${{ steps.ios_version.outputs.version }}" ]; then
echo "iOS version needs update"
NEEDS_UPDATE=true
IOS_UPDATED=true
fi
echo "needs_update=$NEEDS_UPDATE" >> $GITHUB_OUTPUT
echo "android_updated=$ANDROID_UPDATED" >> $GITHUB_OUTPUT
echo "ios_updated=$IOS_UPDATED" >> $GITHUB_OUTPUT
- name: Calculate new plugin version (patch bump)
id: new_plugin_version
if: steps.check_updates.outputs.needs_update == 'true'
run: |
CURRENT_VERSION="${{ steps.current_versions.outputs.current_plugin }}"
echo "Current version: $CURRENT_VERSION"
# Increment patch version (e.g., 1.4.10 -> 1.4.11)
major=$(echo "$CURRENT_VERSION" | cut -d. -f1)
minor=$(echo "$CURRENT_VERSION" | cut -d. -f2)
patch=$(echo "$CURRENT_VERSION" | cut -d. -f3)
echo "Parsed - Major: $major, Minor: $minor, Patch: $patch"
NEW_PATCH=$((patch + 1))
NEW_VERSION="$major.$minor.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New plugin version will be: $NEW_VERSION"
- name: Update package.json
if: steps.check_updates.outputs.needs_update == 'true'
run: |
NEW_VERSION="${{ steps.new_plugin_version.outputs.new_version }}"
# Update package.json version using jq
jq --arg version "$NEW_VERSION" \
'.version = $version' \
package.json > package-tmp.json && mv package-tmp.json package.json
echo "Updated package.json to version $NEW_VERSION"
- name: Update TestUnityDependencies.xml
if: steps.check_updates.outputs.needs_update == 'true'
run: |
ANDROID_VERSION="${{ steps.android_version.outputs.version }}"
IOS_VERSION="${{ steps.ios_version.outputs.version }}"
# Update Android agent version
xmlstarlet ed -L \
-u "//androidPackage[contains(@spec, 'android-agent')]/@spec" \
-v "com.newrelic.agent.android:android-agent:$ANDROID_VERSION" \
com.newrelic.agent/Editor/TestUnityDependencies.xml
# Update iOS agent version
xmlstarlet ed -L \
-u "//iosPod[@name='NewRelicAgent']/@version" \
-v "~> $IOS_VERSION" \
com.newrelic.agent/Editor/TestUnityDependencies.xml
echo "Updated TestUnityDependencies.xml"
echo "Android agent: $ANDROID_VERSION"
echo "iOS agent: $IOS_VERSION"
- name: Update NewRelicAndroid.cs Plugin Version
if: steps.check_updates.outputs.needs_update == 'true'
run: |
NEW_VERSION="${{ steps.new_plugin_version.outputs.new_version }}"
# Update version in NewRelicAndroid.cs withApplicationFramework call
sed -i "s/agentInstance\.Call<AndroidJavaObject>(\"withApplicationFramework\", platform, \"[0-9.]\+\")/agentInstance.Call<AndroidJavaObject>(\"withApplicationFramework\", platform, \"$NEW_VERSION\")/" com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs
echo "Updated NewRelicAndroid.cs to version $NEW_VERSION"
- name: Update README.md
if: steps.check_updates.outputs.needs_update == 'true'
run: |
ANDROID_VERSION="${{ steps.android_version.outputs.version }}"
# Update Android agent version references in README.md
# Update agent-gradle-plugin reference
sed -i "s/com.newrelic.agent.android:agent-gradle-plugin:[0-9.]\+/com.newrelic.agent.android:agent-gradle-plugin:$ANDROID_VERSION/" README.md
# Update android-agent references in dependency examples
sed -i "s/com.newrelic.agent.android:android-agent:[0-9.]\+/com.newrelic.agent.android:android-agent:$ANDROID_VERSION/" README.md
echo "Updated README.md with Android agent version $ANDROID_VERSION"
- name: Update CHANGELOG.md
if: steps.check_updates.outputs.needs_update == 'true'
run: |
ANDROID_VERSION="${{ steps.android_version.outputs.version }}"
IOS_VERSION="${{ steps.ios_version.outputs.version }}"
NEW_VERSION="${{ steps.new_plugin_version.outputs.new_version }}"
ANDROID_UPDATED="${{ steps.check_updates.outputs.android_updated }}"
IOS_UPDATED="${{ steps.check_updates.outputs.ios_updated }}"
# Create changelog entry
CHANGELOG_ENTRY="## $NEW_VERSION\n\n## Improvements\n"
if [ "$ANDROID_UPDATED" = "true" ]; then
CHANGELOG_ENTRY="${CHANGELOG_ENTRY}- Native Android agent updated to version ${ANDROID_VERSION}\n"
fi
if [ "$IOS_UPDATED" = "true" ]; then
CHANGELOG_ENTRY="${CHANGELOG_ENTRY}- Native iOS agent updated to version ${IOS_VERSION}\n"
fi
CHANGELOG_ENTRY="${CHANGELOG_ENTRY}\n"
# Create temporary file with new entry prepended
echo -e "$CHANGELOG_ENTRY" | cat - CHANGELOG.md > CHANGELOG.tmp
mv CHANGELOG.tmp CHANGELOG.md
echo "Updated CHANGELOG.md"
- name: Create Pull Request
if: steps.check_updates.outputs.needs_update == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update native agents to v${{ steps.new_plugin_version.outputs.new_version }}"
branch: "update-native-agents-${{ steps.new_plugin_version.outputs.new_version }}"
delete-branch: true
title: "chore: update native agents to v${{ steps.new_plugin_version.outputs.new_version }}"
body: |
## Updates
- **Android Agent**: ${{ steps.current_versions.outputs.current_android }} → ${{ steps.android_version.outputs.version }}
- **iOS Agent**: ${{ steps.current_versions.outputs.current_ios }} → ${{ steps.ios_version.outputs.version }}
- **Plugin Version**: ${{ steps.current_versions.outputs.current_plugin }} → ${{ steps.new_plugin_version.outputs.new_version }}
## Testing
- [ ] Android app builds successfully
- [ ] iOS app builds successfully
- [ ] Manual testing completed
- [ ] Unity package imports correctly
---
🤖 *Automated PR created by Update Native Agent Versions workflow.*
- name: Summary
if: steps.check_updates.outputs.needs_update == 'true'
run: |
echo "## Version Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Component | Old Version | New Version |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|-------------|-------------|" >> $GITHUB_STEP_SUMMARY
echo "| Android Agent | ${{ steps.current_versions.outputs.current_android }} | ${{ steps.android_version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| iOS Agent | ${{ steps.current_versions.outputs.current_ios }} | ${{ steps.ios_version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| Plugin Version | ${{ steps.current_versions.outputs.current_plugin }} | ${{ steps.new_plugin_version.outputs.new_version }} |" >> $GITHUB_STEP_SUMMARY
- name: No updates needed
if: steps.check_updates.outputs.needs_update == 'false'
run: |
echo "## No Updates Needed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All native agents are already up to date!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Android Agent: ${{ steps.android_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- iOS Agent: ${{ steps.ios_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY