-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
69 lines (58 loc) · 2.69 KB
/
action.yml
File metadata and controls
69 lines (58 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
#
# SPDX-License-Identifier: MPL-2.0
name: Bump Version
description: Retrieve the latest release tag, run the Bash script to bump version, and save the new version to PYPI_VERSION.
inputs: # actions don't have secrets, so we use inputs instead
token:
description: "A Github PAT, e.g. secrets.GITHUB_TOKEN. When not provided, the action will use the default token (may hit rate limits)."
runs:
using: "composite"
steps:
- name: Get Latest Release Tag
id: fetch_tag
uses: pozetroninc/github-action-get-latest-release@2a61c339ea7ef0a336d1daa35ef0cb1418e7676c # v0.8.0
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
token: ${{ inputs.token }}
- name: Run version bump script
id: bump_version
shell: bash
run: |
bump_version() {
# Read the VERSION file
target_version=$(cat VERSION)
# Remove 'v' prefix from the latest release tag
current_version_clean=${1#v}
# Split the current and target versions into components
IFS='.' read -r current_major current_minor current_patch <<< "$current_version_clean"
IFS='.' read -r target_major target_minor <<< "$target_version"
# Compare versions and calculate the new version
if [[ "$current_major" -eq "$target_major" && "$current_minor" -eq "$target_minor" ]]; then
new_patch=$((current_patch + 1))
new_version="$current_major.$current_minor.$new_patch"
elif [[ "$current_major" -lt "$target_major" || ("$current_major" -eq "$target_major" && "$current_minor" -lt "$target_minor") ]]; then
new_version="$target_major.$target_minor.0"
else
echo "Error: Current major.minor is greater than the version in the VERSION file." >&2
exit 1
fi
# handle GitHub Actions context
sha="$GITHUB_SHA"
ref="$GITHUB_REF"
build_number="$GITHUB_RUN_NUMBER"
# Convert the short hash to a numeric value
short_hash=$(printf "%08d" $((16#${sha:0:6})))
if [[ "$ref" == "refs/heads/main" ]]; then
# Main branch: keep the version as is
echo "$new_version"
else
# Feature branch: append alpha versioning
echo "${new_version}a1${build_number}${short_hash}"
fi
}
# Run the bump_version function with the latest tag
new_version=$(bump_version "${{ steps.fetch_tag.outputs.release }}")
# Save the new version to PYPI_VERSION file
echo "$new_version" > PYPI_VERSION