Skip to content

Commit be74168

Browse files
suyadav1Copilot
andauthored
Add automated telegraf-agent upgrade workflow (#1652)
* Add automated telegraf-agent upgrade workflow Adds a scheduled GitHub Actions workflow that checks PMC daily for new telegraf-agent packages and creates PRs to update kubernetes/linux/setup.sh. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add upstream release notes to auto-generated telegraf upgrade PRs - Add 'Fetch upstream release notes' step that fetches from influxdata/telegraf GitHub releases using gh api (authenticated, best-effort with fallback) - Enhanced PR body with collapsible release notes, full release link, and compare link between versions - Use --body-file and env vars to safely handle multiline release notes containing special characters - Use unique delimiter for GITHUB_OUTPUT multiline values to prevent collision Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: Rename check-telegraf-upgrade.yml to telegraf-upgrade.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: Rename workflow and fix PR body formatting - Rename workflow to 'Telegraf Package Upgrade' - Add co-authored-by trailer to commit message - Fix heredoc indentation for clean PR body rendering Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b96f8c0 commit be74168

1 file changed

Lines changed: 164 additions & 0 deletions

File tree

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Telegraf Package Upgrade
2+
3+
on:
4+
schedule:
5+
# Run daily at 10 AM UTC
6+
- cron: '0 10 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
check-telegraf:
15+
name: Check for new telegraf-agent on PMC
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ci_prod
22+
23+
- name: Check for new telegraf version
24+
id: check
25+
run: |
26+
set -euo pipefail
27+
28+
PMC_URL="https://packages.microsoft.com/azurelinux/3.0/prod/cloud-native/x86_64/Packages/t/"
29+
30+
# Get latest telegraf-agent version from PMC (format: telegraf-agent-1.38.2-1)
31+
LATEST_PKG=$(curl -sf "$PMC_URL" \
32+
| grep -oP 'telegraf-agent-\K[0-9]+\.[0-9]+\.[0-9]+-[0-9]+(?=\.azl3)' \
33+
| sort -V | tail -1)
34+
35+
if [ -z "$LATEST_PKG" ]; then
36+
echo "ERROR: Could not determine latest telegraf version from PMC"
37+
exit 1
38+
fi
39+
40+
# Extract version (e.g., 1.38.2) and full package ref (e.g., 1.38.2-1)
41+
LATEST_VERSION=$(echo "$LATEST_PKG" | grep -oP '^[0-9]+\.[0-9]+\.[0-9]+')
42+
echo "latest_version=$LATEST_VERSION" >> "$GITHUB_OUTPUT"
43+
echo "latest_pkg=$LATEST_PKG" >> "$GITHUB_OUTPUT"
44+
45+
# Get current version from setup.sh
46+
CURRENT_VERSION=$(grep -oP 'telegraf-agent-\K[0-9]+\.[0-9]+\.[0-9]+' kubernetes/linux/setup.sh)
47+
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
48+
49+
echo "PMC latest: telegraf-agent-$LATEST_PKG"
50+
echo "setup.sh: telegraf-agent-$CURRENT_VERSION"
51+
52+
if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then
53+
echo "Telegraf is already up to date ($CURRENT_VERSION)"
54+
echo "needs_update=false" >> "$GITHUB_OUTPUT"
55+
else
56+
echo "New version available: $LATEST_VERSION (current: $CURRENT_VERSION)"
57+
echo "needs_update=true" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
- name: Check for existing PR
61+
if: steps.check.outputs.needs_update == 'true'
62+
id: existing_pr
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
EXISTING=$(gh pr list \
67+
--search "Upgrade telegraf-agent to ${{ steps.check.outputs.latest_version }} in:title" \
68+
--state open \
69+
--json number \
70+
--jq 'length')
71+
if [ "$EXISTING" -gt 0 ]; then
72+
echo "PR already exists for version ${{ steps.check.outputs.latest_version }}"
73+
echo "exists=true" >> "$GITHUB_OUTPUT"
74+
else
75+
echo "exists=false" >> "$GITHUB_OUTPUT"
76+
fi
77+
78+
- name: Fetch upstream release notes
79+
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.exists == 'false'
80+
id: release_notes
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
set -euo pipefail
85+
86+
LATEST="${{ steps.check.outputs.latest_version }}"
87+
88+
# Fetch release notes from influxdata/telegraf (best-effort)
89+
NOTES=""
90+
if NOTES=$(gh api "repos/influxdata/telegraf/releases/tag/v${LATEST}" --jq '.body' 2>/dev/null); then
91+
# Truncate if too long (keep under 30k chars to stay within GitHub PR body limits)
92+
if [ "${#NOTES}" -gt 30000 ]; then
93+
NOTES="${NOTES:0:30000}
94+
95+
... _(truncated — see full release notes link above)_"
96+
fi
97+
else
98+
NOTES="_Could not fetch release notes. See the links above for full details._"
99+
fi
100+
101+
# Output multiline release notes using unique EOF delimiter
102+
DELIM="RELEASE_NOTES_$(head -c 16 /dev/urandom | base64 | tr -dc 'A-Za-z0-9')"
103+
echo "notes<<${DELIM}" >> "$GITHUB_OUTPUT"
104+
printf '%s\n' "$NOTES" >> "$GITHUB_OUTPUT"
105+
echo "${DELIM}" >> "$GITHUB_OUTPUT"
106+
107+
- name: Update setup.sh and create PR
108+
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.exists == 'false'
109+
env:
110+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
RELEASE_NOTES: ${{ steps.release_notes.outputs.notes }}
112+
run: |
113+
set -euo pipefail
114+
115+
CURRENT="${{ steps.check.outputs.current_version }}"
116+
LATEST="${{ steps.check.outputs.latest_version }}"
117+
BRANCH="auto/upgrade-telegraf-${LATEST}"
118+
119+
# Update version in setup.sh
120+
sed -i "s/telegraf-agent-${CURRENT}/telegraf-agent-${LATEST}/g" kubernetes/linux/setup.sh
121+
122+
# Verify the change was made
123+
grep "telegraf-agent-${LATEST}" kubernetes/linux/setup.sh
124+
125+
# Configure git
126+
git config user.name "github-actions[bot]"
127+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
128+
129+
# Create branch, commit, push
130+
git checkout -b "$BRANCH"
131+
git add kubernetes/linux/setup.sh
132+
git commit -m "Upgrade telegraf-agent to ${LATEST}
133+
134+
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>"
135+
git push origin "$BRANCH"
136+
137+
# Write PR body to a file (avoids shell quoting issues with release notes)
138+
cat > /tmp/pr-body.md <<PRBODY_EOF
139+
## Summary
140+
Automated upgrade of \`telegraf-agent\` package from \`${CURRENT}\` to \`${LATEST}\`.
141+
142+
New package detected on [PMC](https://packages.microsoft.com/azurelinux/3.0/prod/cloud-native/x86_64/Packages/t/).
143+
144+
### Changes
145+
- Updated \`kubernetes/linux/setup.sh\`: \`telegraf-agent-${CURRENT}\` → \`telegraf-agent-${LATEST}\`
146+
147+
### Upstream Release Notes
148+
[Full release notes](https://github.com/influxdata/telegraf/releases/tag/v${LATEST}) | [Compare changes](https://github.com/influxdata/telegraf/compare/v${CURRENT}...v${LATEST})
149+
150+
<details><summary>Release notes for v${LATEST}</summary>
151+
152+
${RELEASE_NOTES}
153+
154+
</details>
155+
156+
_This PR was created automatically by the telegraf upgrade workflow._
157+
PRBODY_EOF
158+
159+
# Create PR
160+
gh pr create \
161+
--title "Upgrade telegraf-agent to ${LATEST}" \
162+
--body-file /tmp/pr-body.md \
163+
--base ci_prod \
164+
--head "$BRANCH"

0 commit comments

Comments
 (0)