Skip to content

Commit 87942f9

Browse files
authored
chore: fix bump-versions (open-telemetry#1195)
* try to fix bump-versions * add newline
1 parent 34b3c2f commit 87942f9

File tree

2 files changed

+25
-83
lines changed

2 files changed

+25
-83
lines changed

.github/workflows/scripts/bump-versions.sh

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/bin/bash
22
set -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
98
manifest_files=(
@@ -16,10 +15,7 @@ manifest_files=(
1615

1716
# Function to display usage
1817
usage() {
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() {
4137
commit_changes=false
4238
create_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+
4744
while [[ "$#" -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
6357
fi
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
7560
if [ -n "$next_beta_core" ]; then
7661
validate_and_strip_version next_beta_core
7762
fi
@@ -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
13499
next_distribution_version=$(max_version "$next_beta_core" "$next_beta_contrib")
135100
validate_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
143103
echo "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"
147107
echo " - distribution version to $next_distribution_version"
148108
for file in "${manifest_files[@]}"; do
149109
if [ -f "$file" ]; then
@@ -166,50 +126,48 @@ if [ "$commit_changes" = false ]; then
166126
fi
167127

168128
commit_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

180139
create_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
207165
else
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
214172
fi
215173

.github/workflows/update-version.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
name: Update Version in Distributions and Prepare PR
22
on:
33
workflow_dispatch:
4-
inputs:
5-
next_beta_core:
6-
description: 'Collector core beta module set version to update to. Leave empty to bump to next minor version (e.g. 0.120.1 -> 0.121.0)'
7-
required: false
8-
default: ''
9-
next_beta_contrib:
10-
description: 'Collector contrib beta module set version to update to. Leave empty to bump to next minor version (e.g. 0.120.1 -> 0.121.0)'
11-
required: false
12-
default: ''
13-
next_stable_core:
14-
description: 'Collector core stable module set version to update to. Leave empty to bump to next minor version (e.g. 1.26.0 -> 1.27.0)'
15-
required: false
16-
default: ''
174

185
permissions:
196
contents: read
@@ -49,6 +36,3 @@ jobs:
4936
.github/workflows/scripts/bump-versions.sh --commit --pull-request
5037
env:
5138
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
52-
next_beta_core: ${{ github.event.inputs.next_beta_core }}
53-
next_beta_contrib: ${{ github.event.inputs.next_beta_contrib }}
54-
next_stable_core: ${{ github.event.inputs.next_stable_core }}

0 commit comments

Comments
 (0)