-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
104 lines (91 loc) · 3.46 KB
/
action.yml
File metadata and controls
104 lines (91 loc) · 3.46 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: 'Get Next Version'
description: 'Calculates the next semantic version from GitHub releases'
author: 'Eric Veenendaal'
inputs:
version-prefix:
description: 'Prefix for version tags (e.g., v). Leave empty for no prefix.'
required: false
default: ''
bump-type:
description: 'Which part to bump: major, minor, or patch'
required: false
default: 'patch'
outputs:
next-version:
description: 'The calculated next version number'
value: ${{ steps.calculate_version.outputs.next_version }}
current-version:
description: 'The current/latest version found (empty if no releases)'
value: ${{ steps.calculate_version.outputs.current_version }}
runs:
using: 'composite'
steps:
- name: Ensure access to releases
shell: bash
run: |
set -e
echo "Testing access to GitHub releases..."
if ! gh release list --limit 1 > /dev/null 2>&1; then
echo "Error: Unable to access GitHub releases. Ensure the GITHUB_TOKEN has appropriate permissions and the repository has releases enabled." >&2
exit 1
fi
echo "GitHub releases are accessible."
- id: calculate_version
shell: bash
run: |
set -e
prefix="${{ inputs.version-prefix }}"
bump_type="${{ inputs.bump-type }}"
echo "Fetching latest release version..."
# Get the latest release tag, handle case when no releases exist
latest_tag=$(gh release list --limit 1 --json tagName \
-q '.[0].tagName' 2>/dev/null || echo "")
if [[ -z "$latest_tag" ]]; then
echo "Error: No tags found. At least one release tag is required to proceed.\nMake sure you set 'fetch-depth: 0' on the actions/checkout step so all tags are available." >&2
exit 1
elif [[ $latest_tag =~ ^${prefix}([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
# Parse semantic version (with or without prefix)
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
# Remove prefix from current version for output
current_version="${latest_tag#$prefix}"
# Calculate next version based on bump type
case "$bump_type" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
*)
patch=$((patch + 1))
;;
esac
next_version="$major.$minor.$patch"
echo "Found latest release: $latest_tag, next version: $next_version"
else
# Invalid version format, start over with appropriate version
case "$bump_type" in
major)
next_version="1.0.0" ;;
minor)
next_version="0.1.0" ;;
*)
next_version="0.0.1" ;;
esac
echo "Invalid version format in latest release: $latest_tag, resetting to $next_version"
current_version="$latest_tag"
fi
# Output results
echo "next_version=$next_version" >> "$GITHUB_OUTPUT"
echo "current_version=$current_version" >> "$GITHUB_OUTPUT"
echo "✅ Version calculation complete:"
echo " Current version: ${current_version:-'(none)'}"
echo " Next version: $next_version"
branding:
icon: 'tag'
color: 'green'