@@ -16,30 +16,51 @@ runs:
1616 - name : Run version bump script
1717 id : bump_version
1818 shell : bash
19- run : |
20- bump_version() {
21- # Read the VERSION file
22- target_version=$(cat VERSION)
19+ run : |
20+ bump_version() {
21+ # Read the VERSION file
22+ target_version=$(cat VERSION)
2323
24- # Remove 'v' prefix from the latest release tag
25- current_version_clean=${1#v}
24+ # Remove 'v' prefix from the latest release tag
25+ current_version_clean=${1#v}
2626
27- # Split the current and target versions into components
28- IFS='.' read -r current_major current_minor current_patch <<< "$current_version_clean"
29- IFS='.' read -r target_major target_minor <<< "$target_version"
27+ # Split the current and target versions into components
28+ IFS='.' read -r current_major current_minor current_patch <<< "$current_version_clean"
29+ IFS='.' read -r target_major target_minor <<< "$target_version"
30+
31+ # Compare versions and calculate the new version
32+ if [[ "$current_major" -eq "$target_major" && "$current_minor" -eq "$target_minor" ]]; then
33+ new_patch=$((current_patch + 1))
34+ new_version="$current_major.$current_minor.$new_patch"
35+ elif [[ "$current_major" -lt "$target_major" || ("$current_major" -eq "$target_major" && "$current_minor" -lt "$target_minor") ]]; then
36+ new_version="$target_major.$target_minor.0"
37+ else
38+ echo "Error: Current major.minor is greater than the version in the VERSION file." >&2
39+ exit 1
40+ fi
41+
42+ # Check if running on GitHub Actions and required environment variables are set
43+ if [[ -n "$GITHUB_SHA" && -n "$GITHUB_REF" && -n "$GITHUB_RUN_NUMBER" ]]; then
44+ sha="$GITHUB_SHA"
45+ ref="$GITHUB_REF"
46+ build_number="$GITHUB_RUN_NUMBER"
47+
48+ # Convert the short hash to a numeric value
49+ short_hash=$(printf "%08d" $((16#${sha:0:6})))
50+
51+ if [[ "$ref" == *"main"* ]]; then
52+ # Main branch: keep the version as is
53+ echo "$new_version"
54+ else
55+ # Feature branch: append alpha versioning
56+ echo "${new_version}a1${build_number}${short_hash}"
57+ fi
58+ else
59+ echo "Error: Required GitHub Actions environment variables are not set." >&2
60+ exit 1
61+ fi
62+ }
3063
31- # Compare versions and calculate the new version
32- if [[ "$current_major" -eq "$target_major" && "$current_minor" -eq "$target_minor" ]]; then
33- new_patch=$((current_patch + 1))
34- echo "$current_major.$current_minor.$new_patch"
35- elif [[ "$current_major" -lt "$target_major" || ("$current_major" -eq "$target_major" && "$current_minor" -lt "$target_minor") ]]; then
36- echo "$target_major.$target_minor.0"
37- else
38- echo "Error: Current major.minor is greater than the version in the VERSION file." >&2
39- exit 1
40- fi
41- }
42-
4364 # Run the bump_version function with the latest tag
4465 new_version=$(bump_version "${{ steps.fetch_tag.outputs.release }}")
4566 # Save the new version to PYPI_VERSION file
0 commit comments