Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions .github/scripts/update-jaeger-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash
# Script to check for new Jaeger Docker Hub releases and update Chart.yaml
# Can be run standalone for testing or via the GitHub Actions workflow
#
# Usage: ./update-jaeger-version.sh [--dry-run]
#
# Environment variables:
# DRY_RUN - Set to 'true' to skip making changes (same as --dry-run flag)
# GITHUB_OUTPUT - If set, outputs will be written for GitHub Actions

set -eo pipefail

DOCKER_IMAGE="jaegertracing/jaeger"
CHART_PATH="charts/jaeger/Chart.yaml"

# Parse command line arguments
for arg in "$@"; do
case $arg in
--dry-run)
DRY_RUN="true"
shift
;;
esac
done

# Default DRY_RUN to false if not set
DRY_RUN="${DRY_RUN:-false}"

echo "1. Checking latest Docker tag for ${DOCKER_IMAGE}..."

# --- 1. Get the latest semantic version tag by checking the digest of the 'latest' tag ---
echo " -> Fetching image digest for 'latest' tag..."
# Get all digests from the 'latest' tag (multi-platform images have multiple digests)
LATEST_RESPONSE=$(curl -sf "https://registry.hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/latest")
if [[ $? -ne 0 || -z "$LATEST_RESPONSE" ]]; then
echo "Error: Failed to fetch 'latest' tag from Docker Hub. Exiting."
exit 1
fi

LATEST_DIGESTS=$(echo "$LATEST_RESPONSE" | jq -r '.images[].digest | select(. != null)')

if [[ -z "$LATEST_DIGESTS" ]]; then
echo "Error: Could not retrieve valid digests for the 'latest' tag. Exiting."
exit 1
fi
echo " -> Latest digests found:"
echo "$LATEST_DIGESTS" | head -3

# Fetch a list of tags and filter to find the one that:
# 1. Has any digest matching the 'latest' tag digests.
# 2. Matches the semantic version pattern (e.g., 2.39.0).
echo " -> Searching through tags for a semantic version matching these digests..."
TAGS_JSON=$(curl -sf "https://registry.hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags?page_size=100")
if [[ $? -ne 0 || -z "$TAGS_JSON" ]]; then
echo "Error: Failed to fetch tags from Docker Hub. Exiting."
exit 1
fi

# Convert digests to a JSON array for jq comparison
DIGESTS_ARRAY=$(echo "$LATEST_DIGESTS" | jq -R -s 'split("\n") | map(select(length > 0))')

LATEST_TAG=$(echo "$TAGS_JSON" | \
jq -r --argjson digests "$DIGESTS_ARRAY" '
.results[] |
select(.images | map(.digest) | any(. as $d | $digests | index($d))) |
.name' | \
grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \
head -n 1)

if [[ -z "$LATEST_TAG" ]]; then
echo "Error: Could not find a matching semantic version tag in the first 100 results. Exiting."
exit 1
fi

echo " -> Latest available version is: ${LATEST_TAG}"

# --- 2. Get the current appVersion and version from Chart.yaml using grep/sed ---
CURRENT_APP_VERSION=$(grep '^appVersion:' "$CHART_PATH" | sed 's/appVersion: *//' | tr -d '"')
CURRENT_CHART_VERSION=$(grep '^version:' "$CHART_PATH" | sed 's/version: *//' | tr -d '"')

echo " -> Current appVersion in ${CHART_PATH} is: ${CURRENT_APP_VERSION}"
echo " -> Current chart version in ${CHART_PATH} is: ${CURRENT_CHART_VERSION}"

# --- 3. Compare and determine if update is needed ---
if [[ "$LATEST_TAG" == "$CURRENT_APP_VERSION" ]]; then
echo "Versions match. No update needed."
if [[ -n "$GITHUB_OUTPUT" ]]; then
echo "update_needed=false" >> "$GITHUB_OUTPUT"
fi
if [[ "$DRY_RUN" == "true" ]]; then
echo "=============================================="
echo "DRY RUN MODE - No changes needed"
echo "=============================================="
fi
exit 0
fi

echo "Update needed: appVersion change from ${CURRENT_APP_VERSION} to ${LATEST_TAG}."

# --- 4. Calculate new chart version (bump minor version) ---
# Validate that the current chart version follows semantic versioning (X.Y.Z)
if ! [[ "$CURRENT_CHART_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Current chart version '${CURRENT_CHART_VERSION}' does not match expected format X.Y.Z. Exiting."
exit 1
fi

# Parse the current chart version (e.g., 4.0.0 -> major=4, minor=0, patch=0)
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_CHART_VERSION"
NEW_MINOR=$((MINOR + 1))
NEW_CHART_VERSION="${MAJOR}.${NEW_MINOR}.0"

echo " -> New chart version will be: ${NEW_CHART_VERSION}"

# Set outputs for GitHub Actions
if [[ -n "$GITHUB_OUTPUT" ]]; then
echo "update_needed=true" >> "$GITHUB_OUTPUT"
echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT"
echo "current_app_version=${CURRENT_APP_VERSION}" >> "$GITHUB_OUTPUT"
echo "current_chart_version=${CURRENT_CHART_VERSION}" >> "$GITHUB_OUTPUT"
echo "new_chart_version=${NEW_CHART_VERSION}" >> "$GITHUB_OUTPUT"
fi

# --- 5. Handle dry run mode ---
if [[ "$DRY_RUN" == "true" ]]; then
echo "=============================================="
echo "DRY RUN MODE - No changes will be made"
echo "=============================================="
echo "Update IS needed:"
echo " - appVersion: ${CURRENT_APP_VERSION} -> ${LATEST_TAG}"
echo " - version: ${CURRENT_CHART_VERSION} -> ${NEW_CHART_VERSION}"
echo "=============================================="
exit 0
fi

# --- 6. Update Chart.yaml using sed ---
echo "Updating ${CHART_PATH}..."

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

# Update version
sed -i "s/^version:.*/version: ${NEW_CHART_VERSION}/" "$CHART_PATH"

echo "Updated ${CHART_PATH}:"
cat "$CHART_PATH"
81 changes: 81 additions & 0 deletions .github/workflows/update-jaeger-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Update Jaeger Version

on:
schedule:
# Runs once a week on Monday at 00:00 UTC
- cron: '0 0 * * 1'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run mode - skip PR creation and only print status'
required: false
default: 'false'
type: boolean

jobs:
update-jaeger-version:
runs-on: ubuntu-latest
permissions:
contents: read
env:
# Use the dry_run input if it exists (workflow_dispatch).
# Otherwise, if the event is 'schedule' (or anything else), default to 'false'.
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run || 'false' }}
steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@v4

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

- name: ⚙️ Configure Git
if: ${{ steps.check_version.outputs.update_needed == 'true' && env.DRY_RUN != 'true' }}
run: |
git config user.name "jaegertracingbot"
git config user.email "[email protected]"

- name: 📝 Commit changes
if: ${{ steps.check_version.outputs.update_needed == 'true' && env.DRY_RUN != 'true' }}
id: commit
run: |
CHART_PATH="charts/jaeger/Chart.yaml"

# Check if any changes exist before committing
if git diff --exit-code "$CHART_PATH"; then
echo "No changes to commit. Exiting."
echo "pr_needed=false" >> $GITHUB_OUTPUT
else
git add "$CHART_PATH"
git commit -m "chore(deps): Bump Jaeger to ${{ steps.check_version.outputs.latest_tag }}"

# Create and switch to a new topic branch for the PR
NEW_BRANCH="bot/update-jaeger-${{ steps.check_version.outputs.latest_tag }}"
git checkout -b "$NEW_BRANCH"

echo "pr_needed=true" >> $GITHUB_OUTPUT
echo "branch_name=${NEW_BRANCH}" >> $GITHUB_OUTPUT
fi

- name: 🚀 Push new branch
if: ${{ steps.commit.outputs.pr_needed == 'true' && env.DRY_RUN != 'true' }}
run: |
git push https://${{ secrets.JAEGERTRACINGBOT_PAT }}@github.com/${{ github.repository }} HEAD:${{ steps.commit.outputs.branch_name }}

- name: ✨ Create Pull Request
if: ${{ steps.commit.outputs.pr_needed == 'true' && env.DRY_RUN != 'true' }}
env:
GH_TOKEN: ${{ secrets.JAEGERTRACINGBOT_PAT }}
run: |
gh pr create \
--title "chore(deps): Bump Jaeger to ${{ steps.check_version.outputs.latest_tag }}" \
--body "This PR was automatically generated to update the Jaeger Helm chart.

## Changes
- **appVersion**: \`${{ steps.check_version.outputs.current_app_version }}\` → \`${{ steps.check_version.outputs.latest_tag }}\`
- **version**: \`${{ steps.check_version.outputs.current_chart_version }}\` → \`${{ steps.check_version.outputs.new_chart_version }}\`

## Source
Docker Hub image: [jaegertracing/jaeger](https://hub.docker.com/r/jaegertracing/jaeger)" \
--base main \
--head ${{ steps.commit.outputs.branch_name }}