Skip to content

Commit e787779

Browse files
authored
Refactor version generation logic in workflow
1 parent 35b384f commit e787779

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

.github/workflows/push-on-main.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,31 @@ jobs:
2525
- name: Generate Hybrid Version
2626
id: semver
2727
run: |
28-
# PowerShell equivalent of the git logic
29-
$LATEST_TAG = git describe --tags --abbrev=0 2>$null
30-
if ($LASTEXITCODE -ne 0) { $LATEST_TAG = "v0.0" }
28+
# This pattern matches v, digits, a literal dot, and digits.
29+
# It effectively blocks v1.0.1 because the * after the second number
30+
# would usually allow another dot, but we want to anchor strictly.
31+
$BASE_TAG = git describe --tags --abbrev=0 --match "v[0-9]*.[0-9]*" --exclude "v*.*.*" 2>$null
32+
33+
if ($LASTEXITCODE -ne 0) {
34+
Write-Host "No base tag found, defaulting to v0.0"
35+
$BASE_TAG = "v0.0"
36+
}
3137
32-
if ($LATEST_TAG -eq "v0.0") {
38+
# 2. Count commits since that base tag.
39+
# If the current commit is the tag itself, COUNT will be 0.
40+
if ($BASE_TAG -eq "v0.0") {
3341
$COUNT = git rev-list --count HEAD
3442
} else {
35-
$COUNT = git rev-list --count "$LATEST_TAG..HEAD"
43+
$COUNT = git rev-list --count "$($BASE_TAG)..HEAD"
3644
}
3745
38-
$VERSION = "$LATEST_TAG.$COUNT"
46+
# 3. Construct the hybrid VERSION (vX.Y.Z)
47+
$VERSION = "$BASE_TAG.$COUNT"
48+
49+
Write-Host "Base Tag: $BASE_TAG"
50+
Write-Host "Commits since base: $COUNT"
51+
Write-Host "Final Release Version: $VERSION"
52+
3953
echo "VERSION=$VERSION" >> $env:GITHUB_OUTPUT
4054
4155
- name: Create Github Release

0 commit comments

Comments
 (0)