Skip to content

Commit

Permalink
Update action.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardteach42 authored Apr 10, 2024
1 parent d3995cb commit 0e4e345
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,48 @@ runs:
$content = Get-Content $iniPath -Raw
# Updated to match both 0.0.0 and 0.0.0.0 formats
$semVerPattern = 'ProjectVersion=([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)'
if ($content -match $semVerPattern) {
$versionFromIni = $matches[1]
echo "VERSION=$versionFromIni" >> $env:GITHUB_ENV
# Updated to match both version formats in tags
$semVerTagPattern = '^(v)?[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?'
$latestTag = $null
foreach ($tag in $tags) {
if ($tag -match $semVerTagPattern) {
$latestTag = $matches[0]
break
}
}
if ($null -eq $latestTag) {
$latestTag = "0.0.0"
if ($isReleaseBuild -and $releaseTag) {
# Use release tag for version and build ID, supporting both version formats
$buildId = $releaseTag
$newVersion = $buildId -replace '^v', ''
$newVersion = $newVersion -replace '-.*$', '' # Strip any prefix or suffix
} else {
$latestTag = $latestTag -replace '^v', ''
}
$commitCount = & git rev-list --count "${latestTag}..HEAD"
$newVersion = $versionFromIni
if ($latestTag -ne "0.0.0") {
# Convert to System.Version for comparison
$latestVersion = New-Object System.Version($latestTag)
$iniVersion = New-Object System.Version($versionFromIni)
# Updated to match both version formats in tags
$semVerTagPattern = '^(v)?[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$'
$latestTag = $null
foreach ($tag in $tags) {
if ($tag -match $semVerTagPattern) {
$latestTag = $matches[0]
break
}
}
if ($null -eq $latestTag) {
$latestTag = "0.0.0"
} else {
$latestTag = $latestTag -replace '^v', ''
}
$commitCount = & git rev-list --count "${latestTag}..HEAD"
if ($latestVersion -gt $iniVersion) {
$newVersion = $latestTag
} elseif ($latestVersion -eq $iniVersion) {
# Auto-increment the patch or build number if versions match and commit count is more than 0
if ($commitCount -gt 0) {
$versionParts = $newVersion -split '\.'
if ($versionParts.Length -eq 4) { # For 0.0.0.0 format, increment the last part
$versionParts[3] = [int]$versionParts[3] + 1
} else { # For 0.0.0 format, increment the patch number
$versionParts[2] = [int]$versionParts[2] + 1
$newVersion = $versionFromIni
if ($latestTag -ne "0.0.0") {
if ([Version]$latestTag -gt [Version]$versionFromIni) {
$newVersion = $latestTag
} elseif ([Version]$latestTag -eq [Version]$versionFromIni) {
# Auto-increment the appropriate version number based on format
if ($commitCount -gt 0) {
$versionParts = $newVersion -split '\.'
if ($versionParts.Length -eq 4) { # For 0.0.0.0 format, increment the last part
$versionParts[3] = [int]$versionParts[3] + 1
} else { # For 0.0.0 format, increment the patch number
$versionParts[2] = [int]$versionParts[2] + 1
}
$newVersion = $versionParts -join '.'
}
$newVersion = $versionParts -join '.'
}
}
$buildId = "$newVersion-${{ inputs.BUILD_PREFIX }}$commitCount"
Expand Down

0 comments on commit 0e4e345

Please sign in to comment.