11#! /bin/bash
22set -e
3- # This script reads current versions and takes optional next versions, and updates the
4- # version in the specified files. If next version is not provided, it will infer the
5- # next semantic version (e.g. v0.110.0 -> v0.111.0 or v1.16.0 -> v1.17.0) based on the
6- # current version(s) read in.
3+ # This script reads next versions, and updates the version in the specified files.
4+ # It will infer the next semantic version (e.g. v0.110.0 -> v0.111.0 or v1.16.0 -> v1.17.0)
5+ # based on the version(s) read in.
76
87# List of files to update
98manifest_files=(
@@ -16,10 +15,7 @@ manifest_files=(
1615
1716# Function to display usage
1817usage () {
19- echo " Usage: $0 [--commit] [--pull-request] [--next-beta-core <next-beta-core>] [--next-beta-contrib <next-beta-contrib>] [--next-stable-core <next-stable-core>]"
20- echo " --next-beta-core: Next beta version of the core component (e.g., v0.111.0)"
21- echo " --next-beta-contrib: Next beta version of the contrib component (e.g., v0.111.0)"
22- echo " --next-stable-core: Next stable version of the core component (e.g., v1.17.0)"
18+ echo " Usage: $0 [--commit] [--pull-request]"
2319 echo
2420 echo " --commit: Commit the changes to a new branch"
2521 echo " --pull-request: Push the changes to the repo and create a draft PR (requires --commit)"
@@ -41,14 +37,12 @@ validate_and_strip_version() {
4137commit_changes=false
4238create_pr=false
4339# Parse named arguments
44- current_beta_core=$( awk ' /^.*go\.opentelemetry\.io\/collector\/.* v0/ {print $4; exit}' distributions/otelcol/manifest.yaml)
45- current_beta_contrib=$( awk ' /^.*github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.* v0/ {print $4; exit}' distributions/otelcol-contrib/manifest.yaml)
46- current_stable=$( awk ' /^.*go\.opentelemetry\.io\/collector\/.* v1/ {print $4; exit}' distributions/otelcol/manifest.yaml)
40+ next_beta_core=$( awk ' /^.*go\.opentelemetry\.io\/collector\/.* v0/ {print $4; exit}' distributions/otelcol/manifest.yaml)
41+ next_beta_contrib=$( awk ' /^.*github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.* v0/ {print $4; exit}' distributions/otelcol-contrib/manifest.yaml)
42+ next_stable_core=$( awk ' /^.*go\.opentelemetry\.io\/collector\/.* v1/ {print $4; exit}' distributions/otelcol/manifest.yaml)
43+
4744while [[ " $# " -gt 0 ]]; do
4845 case $1 in
49- --next-beta-core) next_beta_core=" $2 " ; shift ;;
50- --next-beta-contrib) next_beta_contrib=" $2 " ; shift ;;
51- --next-stable-core) next_stable_core=" $2 " ; shift ;;
5246 --commit) commit_changes=true ;;
5347 --pull-request) create_pr=true ;;
5448 * ) echo " Unknown parameter passed: $1 " ; usage ;;
@@ -63,15 +57,6 @@ if [ "$create_pr" = true ] && [ "$commit_changes" = false ]; then
6357fi
6458
6559# Validate and strip versions
66- if [ -n " $current_beta_core " ]; then
67- validate_and_strip_version current_beta_core
68- fi
69- if [ -n " $current_beta_contrib " ]; then
70- validate_and_strip_version current_beta_contrib
71- fi
72- if [ -n " $current_stable " ]; then
73- validate_and_strip_version current_stable
74- fi
7560if [ -n " $next_beta_core " ]; then
7661 validate_and_strip_version next_beta_core
7762fi
@@ -110,40 +95,15 @@ max_version() {
11095 echo " $version1 "
11196}
11297
113- # Function to bump the minor version and reset patch version to 0
114- bump_version () {
115- local version=$1
116- local major
117- major=$( echo " $version " | cut -d. -f1)
118- local minor
119- minor=$( echo " $version " | cut -d. -f2)
120- local new_minor
121- new_minor=$(( minor + 1 ))
122- echo " $major .$new_minor .0"
123- }
124-
125- # Infer the next beta version if not supplied
126- if [ -n " $current_beta_core " ] && [ -z " $next_beta_core " ]; then
127- next_beta_core=$( bump_version " $current_beta_core " )
128- fi
129- if [ -n " $current_beta_contrib " ] && [ -z " $next_beta_contrib " ]; then
130- next_beta_contrib=$( bump_version " $current_beta_contrib " )
131- fi
132-
13398# Determine the maximum of next_beta_core and next_beta_contrib
13499next_distribution_version=$( max_version " $next_beta_core " " $next_beta_contrib " )
135100validate_and_strip_version next_distribution_version
136101
137- # Infer the next stable version if current_stable provided and next version not supplied
138- if [ -n " $current_stable " ] && [ -z " $next_stable_core " ]; then
139- next_stable_core=$( bump_version " $current_stable " )
140- fi
141-
142102# Update versions in each manifest file
143103echo " Making the following updates:"
144- echo " - core beta module set from $current_beta_core to $next_beta_core "
145- echo " - core stable module set from $current_stable to $next_stable_core "
146- echo " - contrib beta module set from $current_beta_contrib to $next_beta_contrib "
104+ echo " - core beta module set to $next_beta_core "
105+ echo " - core stable module set to $next_stable_core "
106+ echo " - contrib beta module set to $next_beta_contrib "
147107echo " - distribution version to $next_distribution_version "
148108for file in " ${manifest_files[@]} " ; do
149109 if [ -f " $file " ]; then
@@ -166,50 +126,48 @@ if [ "$commit_changes" = false ]; then
166126fi
167127
168128commit_changes () {
169- local current_version=$1
170- local next_version=$2
171- shift 2
129+ local next_version=$1
130+ shift 1
172131 local branch_name=" update-version-${next_version} "
173132
174133 git checkout -b " $branch_name "
175134 git add .
176- git commit -m " Update version from $current_version to $next_version "
135+ git commit -m " Update version to $next_version "
177136 git push -u origin " $branch_name "
178137}
179138
180139create_pr () {
181- local current_version=$1
182- local next_version=$2
183- shift 2
140+ local next_version=$1
141+ shift 1
184142 local branch_name=" update-version-${next_version} "
185143
186144 gh pr create --title " [chore] Prepare release $next_version " \
187- --body " This PR updates the version from $current_version to $next_version " \
145+ --body " This PR updates the version to $next_version " \
188146 --base main --head " $branch_name "
189147}
190148
191149# TODO: Once Collector 1.0 is released, we can consider removing the
192150# beta version check for commit and PR creation
193- if [ -n " $current_beta_core " ]; then
151+ if [ -n " $next_beta_core " ]; then
194152 if [ " $commit_changes " = true ]; then
195- commit_changes " $current_beta_core " " $ next_beta_core"
153+ commit_changes " $next_beta_core "
196154 fi
197155 if [ " $create_pr " = true ]; then
198- create_pr " $current_beta_core " " $ next_beta_core"
156+ create_pr " $next_beta_core "
199157 fi
200- elif [ -n " $current_beta_contrib " ]; then
158+ elif [ -n " $next_beta_contrib " ]; then
201159 if [ " $commit_changes " = true ]; then
202- commit_changes " $current_beta_contrib " " $ next_beta_contrib"
160+ commit_changes " $next_beta_contrib "
203161 fi
204162 if [ " $create_pr " = true ]; then
205- create_pr " $current_beta_contrib " " $ next_beta_contrib"
163+ create_pr " $next_beta_contrib "
206164 fi
207165else
208166 if [ " $commit_changes " = true ]; then
209- commit_changes " $current_stable " " $ next_stable_core"
167+ commit_changes " $next_stable_core "
210168 fi
211169 if [ " $create_pr " = true ]; then
212- create_pr " $current_stable " " $ next_stable_core"
170+ create_pr " $next_stable_core "
213171 fi
214172fi
215173
0 commit comments