|
5 | 5 | name: Bump Version |
6 | 6 | description: Retrieve the latest release tag, run the Bash script to bump version, and save the new version to PYPI_VERSION. |
7 | 7 | runs: |
8 | | - using: "composite" |
9 | | - steps: |
10 | | - - name: Get Latest Release Tag |
11 | | - id: fetch_tag |
12 | | - uses: pozetroninc/github-action-get-latest-release@master |
13 | | - with: |
14 | | - repository: ${{ github.repository }} |
| 8 | + using: "composite" |
| 9 | + steps: |
| 10 | + - name: Get Latest Release Tag |
| 11 | + id: fetch_tag |
| 12 | + uses: pozetroninc/github-action-get-latest-release@master |
| 13 | + with: |
| 14 | + repository: ${{ github.repository }} |
15 | 15 |
|
16 | | - - name: Run version bump script |
17 | | - id: bump_version |
18 | | - shell: bash |
19 | | - run: | |
20 | | - bump_version() { |
21 | | - # Read the VERSION file |
22 | | - target_version=$(cat VERSION) |
23 | | -
|
24 | | - # Remove 'v' prefix from the latest release tag |
25 | | - current_version_clean=${1#v} |
26 | | -
|
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 | | - # handle GitHub Actions context |
43 | | - sha="$GITHUB_SHA" |
44 | | - ref="$GITHUB_REF" |
45 | | - build_number="$GITHUB_RUN_NUMBER" |
46 | | -
|
47 | | - # Convert the short hash to a numeric value |
48 | | - short_hash=$(printf "%08d" $((16#${sha:0:6}))) |
49 | | -
|
50 | | - if [[ "$ref" == *"main"* ]]; then |
51 | | - # Main branch: keep the version as is |
52 | | - echo "$new_version" |
53 | | - else |
54 | | - # Feature branch: append alpha versioning |
55 | | - echo "${new_version}a1${build_number}${short_hash}" |
56 | | - fi |
57 | | - } |
58 | | -
|
59 | | - # Run the bump_version function with the latest tag |
60 | | - new_version=$(bump_version "${{ steps.fetch_tag.outputs.release }}") |
61 | | - # Save the new version to PYPI_VERSION file |
62 | | - echo "$new_version" > PYPI_VERSION |
| 16 | + - name: Run version bump script |
| 17 | + id: bump_version |
| 18 | + shell: bash |
| 19 | + run: | |
| 20 | + bump_version() { |
| 21 | + # Read the VERSION file |
| 22 | + target_version=$(cat VERSION) |
| 23 | +
|
| 24 | + # Remove 'v' prefix from the latest release tag |
| 25 | + current_version_clean=${1#v} |
| 26 | +
|
| 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 | + # handle GitHub Actions context |
| 43 | + sha="$GITHUB_SHA" |
| 44 | + ref="$GITHUB_REF" |
| 45 | + build_number="$GITHUB_RUN_NUMBER" |
| 46 | +
|
| 47 | + # Convert the short hash to a numeric value |
| 48 | + short_hash=$(printf "%08d" $((16#${sha:0:6}))) |
| 49 | +
|
| 50 | + if [[ "$ref" == *"main"* ]]; then |
| 51 | + # Main branch: keep the version as is |
| 52 | + echo "$new_version" |
| 53 | + else |
| 54 | + # Feature branch: append alpha versioning |
| 55 | + echo "${new_version}a1${build_number}${short_hash}" |
| 56 | + fi |
| 57 | + } |
| 58 | +
|
| 59 | + # Run the bump_version function with the latest tag |
| 60 | + new_version=$(bump_version "${{ steps.fetch_tag.outputs.release }}") |
| 61 | + # Save the new version to PYPI_VERSION file |
| 62 | + echo "$new_version" > PYPI_VERSION |
0 commit comments