Skip to content

Commit

Permalink
✨ feat(build-and-release.yml): Implement dynamic version increment ba…
Browse files Browse the repository at this point in the history
…sed on branch name
  • Loading branch information
pdodds committed Nov 8, 2024
1 parent 4424293 commit 169a87e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,29 @@ jobs:
- name: Increment version
id: version
run: |
# Your existing version increment logic here
# ...
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///')
VERSION=$(poetry version --short)
MINOR_PATCH_PART=$(echo $VERSION | awk -F '.' '{print $1"."$2}')
PATCH_PART=$(echo $VERSION | awk -F '.' '{print substr($NF,1,1)}')
if [[ $BRANCH_NAME == "fix"* || $BRANCH_NAME == "bugs"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))b${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "feature"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))a${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "test"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))rc${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "main"* ]]; then
poetry version patch
VERSION=$(poetry version --short)
MINOR_PATCH_PART=${VERSION#*.}
LAST_VERSION_PART_PREFIX=${MINOR_PATCH_PART%??}
PATCH_PART=${LAST_VERSION_PART_PREFIX%.*}
NEW_LATEST_PATCH_PART=${PATCH_PART}${GITHUB_RUN_ID}
else
echo "Invalid branch name"
exit 1
fi
NEW_VERSION=${VERSION%.*}.${NEW_LATEST_PATCH_PART}
echo $NEW_VERSION
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "versionType=Release" >> $GITHUB_OUTPUT
poetry version $NEW_VERSION --no-ansi
Expand Down

0 comments on commit 169a87e

Please sign in to comment.