| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # This script finds which Grafana releases include a specific commit. | 
					
						
							|  |  |  | # It checks both release branches and tags to determine: | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  | # 1. Which previous releases include the commit | 
					
						
							|  |  |  | # 2. Which upcoming releases will include the commit | 
					
						
							|  |  |  | # 3. The first release that included the commit | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | # | 
					
						
							|  |  |  | # Usage: ./scripts/releasefinder.sh <commit-hash> | 
					
						
							|  |  |  | # The commit hash can be either: | 
					
						
							|  |  |  | # - Full hash (e.g., 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t) | 
					
						
							|  |  |  | # - Short hash (e.g., 1a2b3c4d) | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Example: ./scripts/releasefinder.sh a1b2c3d4e5f6 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2025-07-12 05:10:20 +08:00
										 |  |  | # Note: This script requires a full repository clone with all branches and tags. | 
					
						
							|  |  |  | # It will not work correctly with shallow clones (--depth) or single-branch clones. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | # If you get a "Permission denied" error, make the script executable with: | 
					
						
							|  |  |  | #   chmod +x scripts/releasefinder.sh | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Check if script is executable | 
					
						
							|  |  |  | if [ ! -x "$0" ]; then | 
					
						
							|  |  |  |     echo "Error: This script is not executable." | 
					
						
							|  |  |  |     echo "To fix this, run: chmod +x $0" | 
					
						
							|  |  |  |     echo "Then try running the script again." | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Check if a commit hash was provided | 
					
						
							|  |  |  | if [ $# -ne 1 ]; then | 
					
						
							|  |  |  |     echo "Usage: $0 <commit-hash>" | 
					
						
							|  |  |  |     echo "The commit hash can be either:" | 
					
						
							|  |  |  |     echo "  - Full hash (e.g., 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t)" | 
					
						
							|  |  |  |     echo "  - Short hash (e.g., 1a2b3c4d)" | 
					
						
							|  |  |  |     echo "Example: $0 a1b2c3d4e5f6" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | COMMIT_HASH=$1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Validate that the commit exists | 
					
						
							|  |  |  | if ! git cat-file -t "$COMMIT_HASH" >/dev/null 2>&1; then | 
					
						
							|  |  |  |     echo "Error: Commit $COMMIT_HASH not found in repository" | 
					
						
							|  |  |  |     echo "Make sure you've provided a valid commit hash (full or short)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "Fetching latest remote information..." | 
					
						
							|  |  |  | git fetch --all --tags --prune 2>/dev/null | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | echo "Finding releases containing commit: $COMMIT_HASH" | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | echo "=============================================" | 
					
						
							|  |  |  | echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Get all commit details in one call for better performance | 
					
						
							|  |  |  | commit_info=$(git log -1 --format="%an <%ae>%n%ad%n%B" --date=iso "$COMMIT_HASH") | 
					
						
							|  |  |  | author=$(echo "$commit_info" | sed -n '1p') | 
					
						
							|  |  |  | date=$(echo "$commit_info" | sed -n '2p') | 
					
						
							|  |  |  | commit_message=$(echo "$commit_info" | sed -n '3,$p') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | echo "Commit details:" | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | echo "  Author: $author" | 
					
						
							|  |  |  | echo "  Date: $date" | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Extract PR number and title | 
					
						
							|  |  |  | PR_NUMBER=$(echo "$commit_message" | grep -o '#[0-9]\+' | head -n1 | tr -d '#') | 
					
						
							| 
									
										
										
										
											2025-06-18 03:15:03 +08:00
										 |  |  | if [ -n "$PR_NUMBER" ]; then | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |     PR_TITLE=$(echo "$commit_message" | head -n1) | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |     echo "  PR: #$PR_NUMBER - $PR_TITLE" | 
					
						
							|  |  |  |     echo "  Link: https://github.com/grafana/grafana/pull/$PR_NUMBER" | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | fi | 
					
						
							|  |  |  | echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Find release branches and tags containing the commit | 
					
						
							|  |  |  | release_branches=$(git branch -r --contains "$COMMIT_HASH" 2>/dev/null | grep -E 'origin/release-[0-9]+\.[0-9]+\.[0-9]+(\+security-[0-9]{2})?$' | sed 's/.*origin\///') | 
					
						
							|  |  |  | release_tags=$(git tag --contains "$COMMIT_HASH" 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(\+security-[0-9]{2})?$' | sort -V) | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Get all existing tags for upcoming release filtering | 
					
						
							|  |  |  | all_tags=$(git tag 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(\+security-[0-9]{2})?$') | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Display previous releases | 
					
						
							|  |  |  | if [ -n "$release_tags" ]; then | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |     echo "This commit has been included in these PREVIOUS on-prem releases:" | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |     first_release=$(echo "$release_tags" | head -1) | 
					
						
							|  |  |  |     while read -r tag; do | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |         if [ "$tag" = "$first_release" ]; then | 
					
						
							|  |  |  |             echo "  - $tag (first release)" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             echo "  - $tag" | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |     done <<< "$release_tags" | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |     echo | 
					
						
							|  |  |  |     echo "Note: This code may have been backported to previous release branches. Please check the original PR for backport information." | 
					
						
							|  |  |  |     echo | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  | # Display upcoming releases | 
					
						
							|  |  |  | if [ -n "$release_branches" ]; then | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |     echo "This commit will be included in these UPCOMING on-prem releases:" | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |     while read -r branch; do | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  |         tag_version="v${branch#release-}" | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |         # Only show branches that don't have a corresponding tag yet | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |         if ! echo "$all_tags" | grep -q "^$tag_version$"; then | 
					
						
							| 
									
										
										
										
											2025-03-22 06:01:10 +08:00
										 |  |  |             echo "  - $tag_version" | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  |         fi | 
					
						
							| 
									
										
										
										
											2025-07-12 01:43:03 +08:00
										 |  |  |     done <<< "$release_branches" | sort -V | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     echo "This commit is not yet included in any release branches." | 
					
						
							|  |  |  |     echo "The corresponding release branch has likely not been created yet." | 
					
						
							| 
									
										
										
										
											2025-03-20 04:45:23 +08:00
										 |  |  | fi | 
					
						
							|  |  |  | echo |