|
| 1 | +name: Check Telegraf Package Upgrade |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run weekdays at 10 AM UTC (after dalec-build-defs publishes at ~9 AM) |
| 6 | + - cron: '0 10 * * 1-5' |
| 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: Update setup.sh and create PR |
| 79 | + if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.exists == 'false' |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | +
|
| 85 | + CURRENT="${{ steps.check.outputs.current_version }}" |
| 86 | + LATEST="${{ steps.check.outputs.latest_version }}" |
| 87 | + BRANCH="auto/upgrade-telegraf-${LATEST}" |
| 88 | +
|
| 89 | + # Update version in setup.sh |
| 90 | + sed -i "s/telegraf-agent-${CURRENT}/telegraf-agent-${LATEST}/g" kubernetes/linux/setup.sh |
| 91 | +
|
| 92 | + # Verify the change was made |
| 93 | + grep "telegraf-agent-${LATEST}" kubernetes/linux/setup.sh |
| 94 | +
|
| 95 | + # Configure git |
| 96 | + git config user.name "github-actions[bot]" |
| 97 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 98 | +
|
| 99 | + # Create branch, commit, push |
| 100 | + git checkout -b "$BRANCH" |
| 101 | + git add kubernetes/linux/setup.sh |
| 102 | + git commit -m "Upgrade telegraf-agent to ${LATEST}" |
| 103 | + git push origin "$BRANCH" |
| 104 | +
|
| 105 | + # Create PR |
| 106 | + gh pr create \ |
| 107 | + --title "Upgrade telegraf-agent to ${LATEST}" \ |
| 108 | + --body "## Summary |
| 109 | + Automated upgrade of \`telegraf-agent\` package from \`${CURRENT}\` to \`${LATEST}\`. |
| 110 | +
|
| 111 | + New package detected on [PMC](https://packages.microsoft.com/azurelinux/3.0/prod/cloud-native/x86_64/Packages/t/). |
| 112 | +
|
| 113 | + ### Changes |
| 114 | + - Updated \`kubernetes/linux/setup.sh\`: \`telegraf-agent-${CURRENT}\` → \`telegraf-agent-${LATEST}\` |
| 115 | +
|
| 116 | + _This PR was created automatically by the telegraf upgrade workflow._" \ |
| 117 | + --base ci_prod \ |
| 118 | + --head "$BRANCH" |
0 commit comments