Skip to content

Commit

Permalink
add distribution version max core contrib logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgopack4 committed Dec 13, 2024
1 parent 900b2bf commit a86a585
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
65 changes: 53 additions & 12 deletions .github/workflows/scripts/bump-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ set -e
# current version(s) passed.

# List of files to update
files=(
manifest_files=(
"distributions/otelcol-contrib/manifest.yaml"
"distributions/otelcol/manifest.yaml"
"distributions/otelcol-k8s/manifest.yaml"
"distributions/otelcol-otlp/manifest.yaml"
"Makefile"
)

# Function to display usage
Expand Down Expand Up @@ -83,6 +82,34 @@ if [ -n "$next_stable" ]; then
validate_and_strip_version next_stable
fi

# Function to compare two semantic versions and return the maximum
max_version() {
local version1=$1
local version2=$2

# Strip leading 'v' if present
version1=${version1#v}
version2=${version2#v}

# Split versions into components
IFS='.' read -r -a ver1 <<< "$version1"
IFS='.' read -r -a ver2 <<< "$version2"

# Compare major, minor, and patch versions
for i in {0..2}; do
if [[ ${ver1[i]} -gt ${ver2[i]} ]]; then
echo "$version1"
return
elif [[ ${ver1[i]} -lt ${ver2[i]} ]]; then
echo "$version2"
return
fi
done

# If versions are equal, return either
echo "$version1"
}

# Function to bump the minor version and reset patch version to 0
bump_version() {
local version=$1
Expand All @@ -103,6 +130,10 @@ if [ -n "$current_beta_contrib" ] && [ -z "$next_beta_contrib" ]; then
next_beta_contrib=$(bump_version "$current_beta_contrib")
fi

# Determine the maximum of next_beta_core and next_beta_contrib
next_distribution_version=$(max_version "$next_beta_core" "$next_beta_contrib")
validate_and_strip_version next_distribution_version

# Infer the next stable version if current_stable provided and next version not supplied
if [ -n "$current_stable" ] && [ -z "$next_stable" ]; then
next_stable=$(bump_version "$current_stable")
Expand All @@ -112,19 +143,31 @@ fi
escaped_current_beta_core=${current_beta_core//./\\.}
escaped_current_beta_contrib=${current_beta_contrib//./\\.}
escaped_current_stable=${current_stable//./\\.}
# Update versions in each file
for file in "${files[@]}"; do

# Determine the OS and set the sed command accordingly
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed_command="sed -i ''"
else
# Linux
sed_command="sed -i"
fi

# Update versions in each manifest file
for file in "${manifest_files[@]}"; do
if [ -f "$file" ]; then
sed -i '' "s/\(^.*go\.opentelemetry\.io\/collector\/.*\) v$escaped_current_beta_core/\1 v$next_beta_core/" "$file"
sed -i '' "s/\(^.*github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.*\) v$escaped_current_beta_contrib/\1 v$next_beta_contrib/" "$file"
sed -i '' "s/\(^.*go\.opentelemetry\.io\/collector\/.*\) v$escaped_current_stable/\1 v$next_stable/" "$file"
sed -i '' "s/version: $escaped_current_beta_core/version: $next_beta_core/" "$file"
sed -i '' "s/OTELCOL_BUILDER_VERSION ?= $escaped_current_beta_core/OTELCOL_BUILDER_VERSION ?= $next_beta_core/" Makefile
$sed_command "s/\(^.*go\.opentelemetry\.io\/collector\/.*\) v$escaped_current_beta_core/\1 v$next_beta_core/" "$file"
$sed_command "s/\(^.*github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.*\) v$escaped_current_beta_contrib/\1 v$next_beta_contrib/" "$file"
$sed_command "s/\(^.*go\.opentelemetry\.io\/collector\/.*\) v$escaped_current_stable/\1 v$next_stable/" "$file"
$sed_command "s/version: .*/version: $next_distribution_version/" "$file"
else
echo "File $file does not exist"
fi
done

# Update Makefile OCB version
$sed_command "s/OTELCOL_BUILDER_VERSION ?= $escaped_current_beta_core/OTELCOL_BUILDER_VERSION ?= $next_beta_core/" Makefile

echo "Version update completed."

make chlog-update VERSION="v$next_beta_core"
Expand All @@ -145,9 +188,7 @@ commit_changes() {
local branch_name="update-version-${next_version}"

git checkout -b "$branch_name"
for file in "${files[@]}"; do
git add "$file"
done
git add .
git commit -m "Update version from $current_version to $next_version"
git push -u origin "$branch_name"
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GORELEASER ?= goreleaser

# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(shell git rev-parse --show-toplevel)
OTELCOL_BUILDER_VERSION ?= 0.116.0
OTELCOL_BUILDER_VERSION ?= 0.115.0
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

Expand Down

0 comments on commit a86a585

Please sign in to comment.