Skip to content

Commit

Permalink
Compute version from PR description instead of using commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ll-nick committed Nov 29, 2024
1 parent 7ed6dc8 commit 3de7483
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/bump-version-and-create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@ jobs:
- name: Check out the repository
uses: actions/checkout@v4

- name: Read version from file
run: |
# Read the version from the version file, only store the number (without the 'v')
INITIAL_VERSION=$(source version && echo ${VERSION#v})
echo "Current version: $INITIAL_VERSION"
echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV
- name: Bump version
- name: Compute new version
id: bump_version
uses: anothrNick/github-tag-action@v1
env:
DEFAULT_BUMP: minor
DRY_RUN: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INITIAL_VERSION: ${{ env.INITIAL_VERSION }}
WITH_V: true

PR_BODY: ${{ github.event.pull_request.body }}
run: |
source version
new_version=$(.github/workflows/compute_version.sh "$VERSION" "${PR_BODY//[^a-zA-Z0-9# $'\n']/}")
echo "new_version=$new_version" >> $GITHUB_OUTPUT
update-version-file:
needs: compute-version
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/compute_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <version> <input_string>"
exit 1
fi

initial_version=${1//[^0-9.]/}
input_string=${2//[^a-zA-Z0-9# $'\n']/}

initial_major=$(echo "$initial_version" | cut -d'.' -f1)
initial_minor=$(echo "$initial_version" | cut -d'.' -f2)
initial_patch=$(echo "$initial_version" | cut -d'.' -f3)

# Determine the bump type based on input string
if [[ "$input_string" == *"#major"* ]]; then
new_major=$((initial_major + 1))
new_minor=0
new_patch=0
elif [[ "$input_string" == *"#minor"* ]]; then
new_major=$initial_major
new_minor=$((initial_minor + 1))
new_patch=0
elif [[ "$input_string" == *"#patch"* ]]; then
new_major=$initial_major
new_minor=$initial_minor
new_patch=$((initial_patch + 1))
else
# Default to minor bump
new_major=$initial_major
new_minor=$((initial_minor + 1))
new_patch=0
fi

new_version="v${new_major}.${new_minor}.${new_patch}"
echo "${new_version}"

0 comments on commit 3de7483

Please sign in to comment.