Skip to content

Commit 50d4b36

Browse files
authored
[jaeger] Add postUpgradeTasks to auto-bump chart version on dependency updates (#693)
#### What this PR does Automates chart version bumping when Renovatebot updates dependencies. Previously required manual version updates; now patch version increments automatically (4.1.0 → 4.1.1) when dependencies change.
1 parent 0c12483 commit 50d4b36

File tree

5 files changed

+118
-54
lines changed

5 files changed

+118
-54
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# Script to bump the chart version in Chart.yaml
3+
# Used by renovatebot postUpgradeTasks to bump chart version on dependency updates
4+
# Used by update-jaeger-version.sh to bump chart version on app version updates
5+
#
6+
# Usage: ./bump-chart-version.sh [--dry-run] [--bump-minor]
7+
#
8+
# Options:
9+
# --dry-run Skip making changes (just print what would be done)
10+
# --bump-minor Bump minor version instead of patch (e.g., 4.0.0 -> 4.1.0)
11+
#
12+
# Environment variables:
13+
# DRY_RUN - Set to 'true' to skip making changes (same as --dry-run flag)
14+
15+
set -eo pipefail
16+
17+
CHART_PATH="charts/jaeger/Chart.yaml"
18+
BUMP_TYPE="patch"
19+
20+
# Parse command line arguments
21+
for arg in "$@"; do
22+
case $arg in
23+
--dry-run)
24+
DRY_RUN="true"
25+
shift
26+
;;
27+
--bump-minor)
28+
BUMP_TYPE="minor"
29+
shift
30+
;;
31+
esac
32+
done
33+
34+
# Default DRY_RUN to false if not set
35+
DRY_RUN="${DRY_RUN:-false}"
36+
37+
# Get the current version from Chart.yaml
38+
CURRENT_CHART_VERSION=$(grep '^version:' "$CHART_PATH" | sed 's/version: *//' | tr -d '"') || true
39+
40+
if [[ -z "$CURRENT_CHART_VERSION" ]]; then
41+
echo "Error: Could not extract version from '${CHART_PATH}'. Exiting."
42+
exit 1
43+
fi
44+
45+
echo " -> Current chart version in ${CHART_PATH} is: ${CURRENT_CHART_VERSION}"
46+
47+
# Validate current version format (X.Y.Z)
48+
if ! [[ "$CURRENT_CHART_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
49+
echo "Error: Current chart version '${CURRENT_CHART_VERSION}' does not match expected format X.Y.Z. Exiting."
50+
exit 1
51+
fi
52+
53+
# Calculate new chart version (bump patch or minor version)
54+
# Parse the current chart version (e.g., 4.1.0 -> major=4, minor=1, patch=0)
55+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_CHART_VERSION"
56+
57+
if [[ "$BUMP_TYPE" == "minor" ]]; then
58+
# Bump minor version and reset patch to 0 (e.g., 4.0.0 -> 4.1.0)
59+
NEW_MINOR=$((MINOR + 1))
60+
NEW_CHART_VERSION="${MAJOR}.${NEW_MINOR}.0"
61+
else
62+
# Bump patch version (e.g., 4.1.0 -> 4.1.1)
63+
NEW_PATCH=$((PATCH + 1))
64+
NEW_CHART_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
65+
fi
66+
67+
echo " -> New chart version will be: ${NEW_CHART_VERSION}"
68+
69+
# Handle dry run mode
70+
if [[ "$DRY_RUN" == "true" ]]; then
71+
echo "=============================================="
72+
echo "DRY RUN MODE - No changes will be made"
73+
echo "=============================================="
74+
echo "Chart version bump:"
75+
echo " - version: ${CURRENT_CHART_VERSION} -> ${NEW_CHART_VERSION}"
76+
echo "=============================================="
77+
exit 0
78+
fi
79+
80+
# Update Chart.yaml using sed
81+
echo "Updating ${CHART_PATH}..."
82+
83+
# Escape any special characters in versions for sed (though semver should only have digits and dots)
84+
ESCAPED_CURRENT=$(echo "$CURRENT_CHART_VERSION" | sed 's/[.]/\\./g')
85+
86+
# Update version using a safer sed command with mixed quoting
87+
sed -i 's/^version: *'"${ESCAPED_CURRENT}"'$/version: '"${NEW_CHART_VERSION}"'/' "$CHART_PATH"
88+
89+
echo "Successfully updated chart version to ${NEW_CHART_VERSION}"

.github/scripts/update-jaeger-version.sh

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -84,62 +84,29 @@ echo " -> Current chart version in ${CHART_PATH} is: ${CURRENT_CHART_VERSION}"
8484
# --- 3. Compare and determine if update is needed ---
8585
if [[ "$LATEST_TAG" == "$CURRENT_APP_VERSION" ]]; then
8686
echo "Versions match. No update needed."
87-
if [[ -n "$GITHUB_OUTPUT" ]]; then
88-
echo "update_needed=false" >> "$GITHUB_OUTPUT"
89-
fi
90-
if [[ "$DRY_RUN" == "true" ]]; then
91-
echo "=============================================="
92-
echo "DRY RUN MODE - No changes needed"
93-
echo "=============================================="
94-
fi
9587
exit 0
9688
fi
9789

90+
# --- 4. Print summary about appVersion update ---
9891
echo "Update needed: appVersion change from ${CURRENT_APP_VERSION} to ${LATEST_TAG}."
9992

100-
# --- 4. Calculate new chart version (bump minor version) ---
101-
# Validate that the current chart version follows semantic versioning (X.Y.Z)
102-
if ! [[ "$CURRENT_CHART_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
103-
echo "Error: Current chart version '${CURRENT_CHART_VERSION}' does not match expected format X.Y.Z. Exiting."
104-
exit 1
105-
fi
106-
107-
# Parse the current chart version (e.g., 4.0.0 -> major=4, minor=0, patch=0)
108-
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_CHART_VERSION"
109-
NEW_MINOR=$((MINOR + 1))
110-
NEW_CHART_VERSION="${MAJOR}.${NEW_MINOR}.0"
111-
112-
echo " -> New chart version will be: ${NEW_CHART_VERSION}"
113-
114-
# Set outputs for GitHub Actions
115-
if [[ -n "$GITHUB_OUTPUT" ]]; then
116-
echo "update_needed=true" >> "$GITHUB_OUTPUT"
117-
echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT"
118-
echo "current_app_version=${CURRENT_APP_VERSION}" >> "$GITHUB_OUTPUT"
119-
echo "current_chart_version=${CURRENT_CHART_VERSION}" >> "$GITHUB_OUTPUT"
120-
echo "new_chart_version=${NEW_CHART_VERSION}" >> "$GITHUB_OUTPUT"
121-
fi
122-
123-
# --- 5. Handle dry run mode ---
12493
if [[ "$DRY_RUN" == "true" ]]; then
12594
echo "=============================================="
12695
echo "DRY RUN MODE - No changes will be made"
12796
echo "=============================================="
128-
echo "Update IS needed:"
129-
echo " - appVersion: ${CURRENT_APP_VERSION} -> ${LATEST_TAG}"
130-
echo " - version: ${CURRENT_CHART_VERSION} -> ${NEW_CHART_VERSION}"
131-
echo "=============================================="
13297
exit 0
13398
fi
13499

135-
# --- 6. Update Chart.yaml using sed ---
100+
# --- 5. Execute the update ---
136101
echo "Updating ${CHART_PATH}..."
137102

138103
# Update appVersion
139104
sed -i "s/^appVersion:.*/appVersion: ${LATEST_TAG}/" "$CHART_PATH"
140105

141-
# Update version
142-
sed -i "s/^version:.*/version: ${NEW_CHART_VERSION}/" "$CHART_PATH"
106+
# Get the script directory (where this script is located)
107+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
108+
109+
# Call bump-chart-version.sh to update chart version
110+
"${SCRIPT_DIR}/bump-chart-version.sh" --bump-minor
143111

144-
echo "Updated ${CHART_PATH}:"
145-
cat "$CHART_PATH"
112+
echo "Update complete."

.github/workflows/update-jaeger-version.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ jobs:
3030
ref: main
3131

3232
- name: 🔍 Check for new Jaeger version
33-
id: check_version
3433
run: bash ./.github/scripts/update-jaeger-version.sh
3534

3635
- name: ⚙️ Configure Git
37-
if: ${{ steps.check_version.outputs.update_needed == 'true' && env.DRY_RUN != 'true' }}
36+
if: ${{ env.DRY_RUN != 'true' }}
3837
run: |
3938
git config user.name "jaegertracingbot"
4039
git config user.email "[email protected]"
4140
4241
- name: 📝 Commit changes
43-
if: ${{ steps.check_version.outputs.update_needed == 'true' && env.DRY_RUN != 'true' }}
42+
if: ${{ env.DRY_RUN != 'true' }}
4443
id: commit
4544
run: |
4645
CHART_PATH="charts/jaeger/Chart.yaml"
@@ -50,15 +49,19 @@ jobs:
5049
echo "No changes to commit. Exiting."
5150
echo "pr_needed=false" >> $GITHUB_OUTPUT
5251
else
52+
# Extract versions from Chart.yaml for commit message and PR
53+
NEW_APP_VERSION=$(grep '^appVersion:' "$CHART_PATH" | sed 's/appVersion: *//' | tr -d '"')
54+
5355
git add "$CHART_PATH"
54-
git commit -sm "chore(deps): Bump Jaeger to ${{ steps.check_version.outputs.latest_tag }}"
56+
git commit -sm "chore(deps): Bump Jaeger to ${NEW_APP_VERSION}"
5557
5658
# Create and switch to a new topic branch for the PR
57-
NEW_BRANCH="bot/update-jaeger-${{ steps.check_version.outputs.latest_tag }}"
59+
NEW_BRANCH="bot/update-jaeger-${NEW_APP_VERSION}"
5860
git checkout -b "$NEW_BRANCH"
5961
6062
echo "pr_needed=true" >> $GITHUB_OUTPUT
6163
echo "branch_name=${NEW_BRANCH}" >> $GITHUB_OUTPUT
64+
echo "new_app_version=${NEW_APP_VERSION}" >> $GITHUB_OUTPUT
6265
fi
6366
6467
- name: 🚀 Push new branch
@@ -72,12 +75,8 @@ jobs:
7275
GH_TOKEN: ${{ secrets.JAEGERTRACINGBOT_PAT }}
7376
run: |
7477
gh pr create \
75-
--title "chore(deps): Bump Jaeger to ${{ steps.check_version.outputs.latest_tag }}" \
76-
--body "This PR was automatically generated to update the Jaeger Helm chart.
77-
78-
## Changes
79-
- **appVersion**: \`${{ steps.check_version.outputs.current_app_version }}\` → \`${{ steps.check_version.outputs.latest_tag }}\`
80-
- **version**: \`${{ steps.check_version.outputs.current_chart_version }}\` → \`${{ steps.check_version.outputs.new_chart_version }}\`
78+
--title "chore(deps): Bump Jaeger to ${{ steps.commit.outputs.new_app_version }}" \
79+
--body "This PR was automatically generated to update the Jaeger Helm chart to version \`${{ steps.commit.outputs.new_app_version }}\`.
8180
8281
## Source
8382
Docker Hub image: [jaegertracing/jaeger](https://hub.docker.com/r/jaegertracing/jaeger)" \

charts/jaeger/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ appVersion: 2.13.0
33
description: A Jaeger Helm chart for Kubernetes
44
name: jaeger
55
type: application
6-
version: 4.1.0
6+
version: 4.1.1
77
# CronJobs require v1.21
88
kubeVersion: ">= 1.21-0"
99
keywords:

renovate.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33
"extends": [
44
"config:recommended",
55
":gitSignOff"
6-
]
6+
],
7+
"postUpgradeTasks": {
8+
"commands": [
9+
".github/scripts/bump-chart-version.sh"
10+
],
11+
"fileFilters": [
12+
"charts/**/Chart.yaml"
13+
],
14+
"executionMode": "update"
15+
}
716
}

0 commit comments

Comments
 (0)