Skip to content

Commit 251db47

Browse files
authored
Merge pull request #40 from KIT-MRT/compute_version_from_pr_description
Compute version from PR description
2 parents e512a18 + 3de7483 commit 251db47

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

.github/workflows/bump-version-and-create-release.yaml

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,19 @@ jobs:
1313
permissions:
1414
contents: write
1515
outputs:
16-
new_tag: ${{ steps.bump_version.outputs.new_tag }}
16+
new_version: ${{ steps.bump_version.outputs.new_version }}
1717
steps:
1818
- name: Check out the repository
1919
uses: actions/checkout@v4
2020

21-
- name: Read version from file
22-
run: |
23-
# Read the version from the version file, only store the number (without the 'v')
24-
INITIAL_VERSION=$(source version && echo ${VERSION#v})
25-
echo "Current version: $INITIAL_VERSION"
26-
echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV
27-
28-
- name: Bump version
21+
- name: Compute new version
2922
id: bump_version
30-
uses: anothrNick/github-tag-action@v1
3123
env:
32-
DEFAULT_BUMP: minor
33-
DRY_RUN: true
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
INITIAL_VERSION: ${{ env.INITIAL_VERSION }}
36-
WITH_V: true
37-
24+
PR_BODY: ${{ github.event.pull_request.body }}
25+
run: |
26+
source version
27+
new_version=$(.github/workflows/compute_version.sh "$VERSION" "${PR_BODY//[^a-zA-Z0-9# $'\n']/}")
28+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
3829
3930
update-version-file:
4031
needs: compute-version
@@ -49,18 +40,18 @@ jobs:
4940

5041
- name: Update version file with new version
5142
run: |
52-
echo "New version: ${{ needs.compute-version.outputs.new_tag }}"
53-
echo "VERSION=${{ needs.compute-version.outputs.new_tag }}" > version
43+
echo "New version: ${{ needs.compute-version.outputs.new_version }}"
44+
echo "VERSION=${{ needs.compute-version.outputs.new_version }}" > version
5445
git config --local user.name "github-actions[bot]"
5546
git config --local user.email "github-actions[bot]@users.noreply.github.com"
5647
git add version
57-
git commit -m "chore: update version file to ${{ needs.compute-version.outputs.new_tag }}"
48+
git commit -m "chore: update version file to ${{ needs.compute-version.outputs.new_version }}"
5849
git push
5950
6051
- name: Push new tag
6152
run: |
62-
git tag ${{ needs.compute-version.outputs.new_tag }}
63-
git push origin ${{ needs.compute-version.outputs.new_tag }}
53+
git tag ${{ needs.compute-version.outputs.new_version }}
54+
git push origin ${{ needs.compute-version.outputs.new_version }}
6455
6556
6657
create-release:
@@ -73,7 +64,7 @@ jobs:
7364
uses: actions/checkout@v4
7465
with:
7566
fetch-depth: 0
76-
ref: ${{ needs.compute-version.outputs.new_tag }}
67+
ref: ${{ needs.compute-version.outputs.new_version }}
7768

7869
- name: Build release packages
7970
uses: docker/build-push-action@v6
@@ -93,7 +84,7 @@ jobs:
9384
uses: ncipollo/release-action@v1
9485
with:
9586
artifacts: "/tmp/artifacts/release/*"
96-
tag: ${{ needs.compute-version.outputs.new_tag }}
87+
tag: ${{ needs.compute-version.outputs.new_version }}
9788
body: ${{ github.event.pull_request.body }}
9889

9990

@@ -105,11 +96,11 @@ jobs:
10596
uses: docker/build-push-action@v6
10697
with:
10798
build-args: |
108-
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/util_caching/releases/download/${{ needs.compute-version.outputs.new_tag }}
99+
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/util_caching/releases/download/${{ needs.compute-version.outputs.new_version }}
109100
push: false
110101
tags: release_tester
111102
target: release_test
112103

113104
- name: Run unit tests with/against released version
114105
run: |
115-
docker run --rm release_tester
106+
docker run --rm release_tester
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ $# -ne 2 ]]; then
6+
echo "Usage: $0 <version> <input_string>"
7+
exit 1
8+
fi
9+
10+
initial_version=${1//[^0-9.]/}
11+
input_string=${2//[^a-zA-Z0-9# $'\n']/}
12+
13+
initial_major=$(echo "$initial_version" | cut -d'.' -f1)
14+
initial_minor=$(echo "$initial_version" | cut -d'.' -f2)
15+
initial_patch=$(echo "$initial_version" | cut -d'.' -f3)
16+
17+
# Determine the bump type based on input string
18+
if [[ "$input_string" == *"#major"* ]]; then
19+
new_major=$((initial_major + 1))
20+
new_minor=0
21+
new_patch=0
22+
elif [[ "$input_string" == *"#minor"* ]]; then
23+
new_major=$initial_major
24+
new_minor=$((initial_minor + 1))
25+
new_patch=0
26+
elif [[ "$input_string" == *"#patch"* ]]; then
27+
new_major=$initial_major
28+
new_minor=$initial_minor
29+
new_patch=$((initial_patch + 1))
30+
else
31+
# Default to minor bump
32+
new_major=$initial_major
33+
new_minor=$((initial_minor + 1))
34+
new_patch=0
35+
fi
36+
37+
new_version="v${new_major}.${new_minor}.${new_patch}"
38+
echo "${new_version}"
39+

0 commit comments

Comments
 (0)