Skip to content

Commit b4ecb99

Browse files
authored
Improved automated chart versioning (#609)
<MAJOR>.<MINOR>.<NEXT_PATCH>-<TIMESTAMP>-<SHORT_SHA>
1 parent c3e363f commit b4ecb99

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.github/workflows/publish-chart.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
steps:
3636
- name: Checkout code
3737
uses: actions/checkout@v6
38+
with:
39+
fetch-depth: 0
3840

3941
- name: Set up Helm
4042
uses: azure/setup-helm@v4
@@ -44,15 +46,28 @@ jobs:
4446
- name: Determine chart version
4547
id: chart_version
4648
run: |
47-
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
48-
# Use SHA for main branch
49-
CHART_VERSION="0.0.0-$(echo ${{ github.sha }} | cut -c1-7)"
50-
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
49+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
5150
# Use tag version (strip 'v' prefix)
5251
CHART_VERSION="${GITHUB_REF#refs/tags/v}"
5352
else
54-
# Use PR SHA for dry run
55-
CHART_VERSION="0.0.0-$(echo ${{ github.sha }} | cut -c1-7)"
53+
# Get the latest tag
54+
LATEST_TAG=$(git describe --tags --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null || echo "v0.0.0")
55+
# Strip 'v' prefix
56+
VERSION="${LATEST_TAG#v}"
57+
# Remove prerelease/build metadata (everything after '-' or '+')
58+
BASE_VERSION="${VERSION%%-*}"
59+
BASE_VERSION="${BASE_VERSION%%+*}"
60+
# Parse base version
61+
MAJOR=$(echo $BASE_VERSION | cut -d. -f1)
62+
MINOR=$(echo $BASE_VERSION | cut -d. -f2)
63+
PATCH=$(echo $BASE_VERSION | cut -d. -f3)
64+
# Increment patch version
65+
NEXT_PATCH=$((PATCH + 1))
66+
# Get timestamp and short SHA
67+
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
68+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
69+
# Format: major.minor.patch+1-timestamp-sha
70+
CHART_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-${TIMESTAMP}-${SHORT_SHA}"
5671
fi
5772
echo "version=$CHART_VERSION" >> $GITHUB_OUTPUT
5873

0 commit comments

Comments
 (0)