Skip to content

Commit 95e257f

Browse files
ci: automate pre- and post-release version bump to include -DEV in main
1 parent 6aece9b commit 95e257f

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Post-Release Version Bump
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
bump-version:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout main branch
13+
uses: actions/checkout@v4
14+
with:
15+
ref: main
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
18+
- name: Extract release version and decide bump type
19+
run: |
20+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
21+
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
22+
23+
MAJOR=$(echo "$TAG_VERSION" | cut -d. -f1)
24+
MINOR=$(echo "$TAG_VERSION" | cut -d. -f2)
25+
PATCH=$(echo "$TAG_VERSION" | cut -d. -f3)
26+
27+
if [ "$PATCH" -gt 0 ]; then
28+
# Patch release → bump patch
29+
NEW_MAJOR=$MAJOR
30+
NEW_MINOR=$MINOR
31+
NEW_PATCH=$((PATCH + 1))
32+
else
33+
# Minor release → bump minor, reset patch
34+
NEW_MAJOR=$MAJOR
35+
NEW_MINOR=$((MINOR + 1))
36+
NEW_PATCH=0
37+
fi
38+
39+
echo "NEW_MAJOR=$NEW_MAJOR" >> $GITHUB_ENV
40+
echo "NEW_MINOR=$NEW_MINOR" >> $GITHUB_ENV
41+
echo "NEW_PATCH=$NEW_PATCH" >> $GITHUB_ENV
42+
43+
- name: Update version.h to DEV version
44+
run: |
45+
FILE_PATH="include/opentelemetry/version.h"
46+
sed -i "s|#define OPENTELEMETRY_VERSION \".*\"|#define OPENTELEMETRY_VERSION \"${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}-DEV\"|" "$FILE_PATH"
47+
sed -i "s|#define OPENTELEMETRY_VERSION_MAJOR .*|#define OPENTELEMETRY_VERSION_MAJOR ${NEW_MAJOR}|" "$FILE_PATH"
48+
sed -i "s|#define OPENTELEMETRY_VERSION_MINOR .*|#define OPENTELEMETRY_VERSION_MINOR ${NEW_MINOR}|" "$FILE_PATH"
49+
sed -i "s|#define OPENTELEMETRY_VERSION_PATCH .*|#define OPENTELEMETRY_VERSION_PATCH ${NEW_PATCH}|" "$FILE_PATH"
50+
51+
- name: Commit and push changes
52+
run: |
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
git add include/opentelemetry/version.h
56+
git commit -m "Bump version to ${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}-DEV after release" || echo "No changes to commit"
57+
git push origin main
58+

.github/workflows/pre-release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Pre-Release Preparation
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release version (e.g. 1.23.0)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
prepare-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout main branch
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Validate current version contains -DEV
22+
run: |
23+
FILE_PATH="include/opentelemetry/version.h"
24+
if ! grep -q -- "-DEV" "$FILE_PATH"; then
25+
echo "Error: version.h does not contain -DEV. Aborting to prevent overwriting a release."
26+
exit 1
27+
fi
28+
29+
- name: Remove -DEV from version.h
30+
run: |
31+
FILE_PATH="include/opentelemetry/version.h"
32+
VERSION="${{ github.event.inputs.version }}"
33+
34+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
35+
MINOR=$(echo "$VERSION" | cut -d. -f2)
36+
PATCH=$(echo "$VERSION" | cut -d. -f3)
37+
38+
sed -i "s|#define OPENTELEMETRY_VERSION \".*\"|#define OPENTELEMETRY_VERSION \"${VERSION}\"|" "$FILE_PATH"
39+
sed -i "s|#define OPENTELEMETRY_VERSION_MAJOR .*|#define OPENTELEMETRY_VERSION_MAJOR ${MAJOR}|" "$FILE_PATH"
40+
sed -i "s|#define OPENTELEMETRY_VERSION_MINOR .*|#define OPENTELEMETRY_VERSION_MINOR ${MINOR}|" "$FILE_PATH"
41+
sed -i "s|#define OPENTELEMETRY_VERSION_PATCH .*|#define OPENTELEMETRY_VERSION_PATCH ${PATCH}|" "$FILE_PATH"
42+
43+
- name: Commit clean release version
44+
run: |
45+
git config user.name "github-actions[bot]"
46+
git config user.email "github-actions[bot]@users.noreply.github.com"
47+
git add include/opentelemetry/version.h
48+
git commit -m "Prepare release ${{ github.event.inputs.version }}" || echo "No changes to commit"
49+
git push origin main
50+
51+
- name: Create and push tag
52+
run: |
53+
git tag -a "v${{ github.event.inputs.version }}" -m "Release v${{ github.event.inputs.version }}"
54+
git push origin "v${{ github.event.inputs.version }}"

api/include/opentelemetry/version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
# define OPENTELEMETRY_ABI_VERSION_NO 1
1111
#endif
1212

13-
#define OPENTELEMETRY_VERSION "1.22.0"
13+
// Development version after 1.22.0 release
14+
#define OPENTELEMETRY_VERSION "1.23.0-DEV"
1415
#define OPENTELEMETRY_VERSION_MAJOR 1
15-
#define OPENTELEMETRY_VERSION_MINOR 22
16+
#define OPENTELEMETRY_VERSION_MINOR 23
1617
#define OPENTELEMETRY_VERSION_PATCH 0
1718

1819
#define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO)
@@ -25,5 +26,4 @@
2526
}}
2627

2728
#define OPENTELEMETRY_NAMESPACE opentelemetry :: OPENTELEMETRY_CONCAT(v, OPENTELEMETRY_ABI_VERSION_NO)
28-
2929
// clang-format on

0 commit comments

Comments
 (0)