Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump the version using the #flags from the PR description #85

Merged
merged 8 commits into from
Nov 21, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,13 @@ 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

run: |
# Run the compute_version script and pass the PR description as an argument
cd .github/workflows
new_tag=$(./compute_version.sh "${{ github.event.pull_request.body }}")
ll-nick marked this conversation as resolved.
Show resolved Hide resolved
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT

update-version-file:
needs: compute-version
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/compute_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_FILE="$SCRIPT_DIR/../../version"
ll-nick marked this conversation as resolved.
Show resolved Hide resolved

# Read the current version from the version file or default to v0.0.0
if [[ -f "$VERSION_FILE" ]]; then
source "$VERSION_FILE"
else
VERSION="v0.0.0"
fi

# Extract the current version components
major=$(echo $VERSION | cut -d'.' -f1 | cut -d'v' -f2)
minor=$(echo $VERSION | cut -d'.' -f2)
patch=$(echo $VERSION | cut -d'.' -f3)

# Read the PR description passed as an argument
input_string="$1"

# Determine the bump type based on PR description
ll-nick marked this conversation as resolved.
Show resolved Hide resolved
if [[ "$input_string" == *"#major"* ]]; then
new_major=$((major + 1))
new_minor=0
new_patch=0
elif [[ "$input_string" == *"#minor"* ]]; then
new_major=$major
new_minor=$((minor + 1))
new_patch=0
elif [[ "$input_string" == *"#patch"* ]]; then
new_major=$major
new_minor=$minor
new_patch=$((patch + 1))
else
# Default to minor bump
new_major=$major
new_minor=$((minor + 1))
new_patch=0
fi

# Construct the new version
new_version="v${new_major}.${new_minor}.${new_patch}"

# Output the new version
echo "${new_version}"