Skip to content

Commit 1fff5b1

Browse files
committed
fix version to conform to V.V.V.V (#253)
1 parent 2bb88dc commit 1fff5b1

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

.github/workflows/build-test-installer-release.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,28 @@ jobs:
3131
with:
3232
fetch-depth: 0
3333

34-
- name: Compute version
34+
- name: Compute Version
3535
id: compute_version
36-
shell: pwsh
37-
env:
38-
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/v') }}
39-
REF_NAME: ${{ github.ref_name }}
40-
HEAD_COMMIT_TIMESTAMP: ${{ github.event.head_commit && github.event.head_commit.timestamp || '' }}
41-
GITHUB_SHA: ${{ github.sha }}
36+
shell: bash
4237
run: |
43-
if ($env:IS_TAG -eq 'true') {
44-
$version = $env:REF_NAME
45-
} elseif (-not [string]::IsNullOrEmpty($env:HEAD_COMMIT_TIMESTAMP)) {
46-
$timestamp = [DateTime]::Parse($env:HEAD_COMMIT_TIMESTAMP).ToUniversalTime().ToString("yyyyMMddHHmm")
47-
$version = "$timestamp-$($env:GITHUB_SHA)"
48-
} else {
49-
$timestamp = [DateTime]::UtcNow.ToString("yyyyMMddHHmm")
50-
$version = "$timestamp-$($env:GITHUB_SHA)"
51-
}
52-
53-
"Version=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
54-
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
38+
# If this is a tag push and it starts with v, just use it
39+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
40+
Version="${GITHUB_REF#refs/tags/}"
41+
echo "version=$Version" >> $GITHUB_OUTPUT
42+
echo "detected tag push: $Version"
43+
exit 0
44+
fi
45+
46+
# Otherwise find the latest tag that starts with v
47+
LAST_TAG=$(git describe --tags --match "v*" --abbrev=0 2>/dev/null || echo "v0.0.0")
48+
49+
# Compute a build number based on number of commits since that tag
50+
COMMITS_SINCE_TAG=$(git rev-list ${LAST_TAG}..HEAD --count)
51+
52+
# Final version: vX.Y.Z+<build>
53+
Version="${LAST_TAG}.${COMMITS_SINCE_TAG}"
54+
echo "version=$Version" >> $GITHUB_OUTPUT
55+
echo "no tag push; using $Version"
5556
5657
- name: Setup NuGet
5758
uses: NuGet/setup-nuget@v2
@@ -68,7 +69,7 @@ jobs:
6869
run: msbuild build\SayMore.proj /t:Build /p:Configuration=$env:Configuration /p:Version=$env:Version /m
6970

7071
- name: Run tests
71-
run: msbuild build\SayMore.proj /t:Test /p:Configuration=$env:Configuration /p:excludedCategories=SkipOnTeamCity /m
72+
run: msbuild build\SayMore.proj /t:Test /p:Configuration=$env:Configuration /p:useNUnit-x86=true /p:excludedCategories=SkipOnTeamCity /m
7273

7374
- name: Upload test results
7475
if: always()

build/SayMore.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
<Target Name="VersionNumbers">
3434
<PropertyGroup>
35-
<!-- The Version should be set from the outside, if not, set a default value -->
36-
<Version Condition="'$(Version)' == ''">$([System.DateTime]::Now.ToString("yyyyMMddHHmmss"))</Version>
35+
<!-- The Version should be set from the outside, if not, set a meaningless default value -->
36+
<Version Condition="'$(Version)' == ''">1.0.0.0</Version>
3737
</PropertyGroup>
3838

3939
<Message Text="Version: $(Version)" Importance="high"/>

0 commit comments

Comments
 (0)