Skip to content

Commit ebc9999

Browse files
committed
Switch to gitversion
1 parent 7be883d commit ebc9999

9 files changed

Lines changed: 533 additions & 49 deletions

File tree

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"gitversion.tool": {
6+
"version": "6.4.0",
7+
"commands": [
8+
"dotnet-gitversion"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/publish-prerelease.yml

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,35 @@ jobs:
2222
with:
2323
dotnet-version: 8.0.x
2424

25-
- name: Set version with padded build number
26-
id: version
25+
- name: Restore .NET tools
26+
run: dotnet tool restore
27+
28+
- name: Compute semantic version
29+
id: gitversion
30+
shell: bash
2731
run: |
28-
# Pad the run number with leading zeros (4 digits)
29-
PADDED_BUILD_NUMBER=$(printf "%04d" ${{ github.run_number }})
30-
PACKAGE_VERSION="6.0.0-prerelease.${PADDED_BUILD_NUMBER}"
31-
echo "package_version=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
32-
echo "Version set to $PACKAGE_VERSION"
32+
set -euo pipefail
33+
JSON=$(dotnet tool run dotnet-gitversion /output json)
34+
echo "$JSON"
35+
36+
NUGET_VERSION=$(echo "$JSON" | jq -r '.NuGetVersion')
37+
FULL_SEMVER=$(echo "$JSON" | jq -r '.FullSemVer')
38+
SHORT_SHA=$(echo "$JSON" | jq -r '.ShortSha')
39+
MAJOR_MINOR_PATCH=$(echo "$JSON" | jq -r '.MajorMinorPatch')
40+
PR_LABEL=$(echo "$JSON" | jq -r '.PreReleaseLabel')
41+
PR_NUMBER=$(echo "$JSON" | jq -r '.PreReleaseNumber')
42+
43+
if [[ "$PR_LABEL" != "" && "$PR_LABEL" != "null" ]]; then
44+
printf -v PR_PADDED '%04d' "$PR_NUMBER"
45+
RELEASE_VERSION_PADDED="${MAJOR_MINOR_PATCH}-${PR_LABEL}.${PR_PADDED}"
46+
else
47+
RELEASE_VERSION_PADDED="$MAJOR_MINOR_PATCH"
48+
fi
49+
50+
echo "nugetVersion=$NUGET_VERSION" >> "$GITHUB_OUTPUT"
51+
echo "fullSemVer=$FULL_SEMVER" >> "$GITHUB_OUTPUT"
52+
echo "releaseVersionPadded=$RELEASE_VERSION_PADDED" >> "$GITHUB_OUTPUT"
53+
echo "informational=${NUGET_VERSION}+${SHORT_SHA}" >> "$GITHUB_OUTPUT"
3354
3455
- name: Restore
3556
run: dotnet restore LiteDB.sln
@@ -38,23 +59,30 @@ jobs:
3859
timeout-minutes: 5
3960
run: dotnet test LiteDB.sln --configuration Release --verbosity normal --settings tests.runsettings --logger "trx;LogFileName=TestResults.trx" --logger "console;verbosity=detailed" /p:DefineConstants=TESTING
4061

62+
- name: Upload test results
63+
uses: actions/upload-artifact@v4
64+
if: always()
65+
with:
66+
name: test-results
67+
path: "**/*TestResults*.trx"
68+
69+
- name: Upload hang dumps (if any)
70+
uses: actions/upload-artifact@v4
71+
if: always()
72+
with:
73+
name: hangdumps
74+
path: |
75+
hangdumps
76+
**/TestResults/**/*.dmp
77+
if-no-files-found: ignore
78+
4179
- name: Build
42-
run: dotnet build LiteDB.sln --configuration Release --no-restore
80+
if: success()
81+
run: dotnet build LiteDB/LiteDB.csproj --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
4382

4483
- name: Pack
45-
run: |
46-
dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts -p:PackageVersion=${{ steps.version.outputs.package_version }} -p:Version=${{ steps.version.outputs.package_version }}
47-
48-
- name: Publish GitHub prerelease
49-
uses: softprops/action-gh-release@v2
50-
with:
51-
tag_name: v${{ steps.version.outputs.package_version }}
52-
name: LiteDB ${{ steps.version.outputs.package_version }}
53-
generate_release_notes: true
54-
prerelease: true
55-
files: artifacts/*.nupkg
56-
env:
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
if: success()
85+
run: dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts /p:ContinuousIntegrationBuild=true
5886

5987
- name: Retrieve secrets from Bitwarden
6088
uses: bitwarden/sm-action@v2
@@ -65,7 +93,9 @@ jobs:
6593
265b2fb6-2cf0-4859-9bc8-b24c00ab4378 > NUGET_API_KEY
6694
6795
- name: Push package to NuGet
96+
if: success()
97+
env:
98+
PACKAGE_VERSION: ${{ steps.gitversion.outputs.nugetVersion }}
6899
run: |
100+
echo "Pushing LiteDB version $PACKAGE_VERSION"
69101
dotnet nuget push "artifacts/*.nupkg" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
70-
71-
Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
name: Publish release
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
tags:
8-
- v*
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: Branch, tag, or SHA to release from
8+
default: master
9+
required: true
10+
publish_nuget:
11+
description: Push packages to NuGet
12+
type: boolean
13+
default: false
14+
publish_github:
15+
description: Create or update GitHub release
16+
type: boolean
17+
default: false
918

1019
jobs:
1120
publish:
12-
if: startsWith(github.ref, 'refs/tags/v')
1321
runs-on: ubuntu-latest
1422
permissions:
1523
contents: write
@@ -19,36 +27,58 @@ jobs:
1927
uses: actions/checkout@v4
2028
with:
2129
fetch-depth: 0
30+
ref: ${{ inputs.ref }}
2231

2332
- name: Set up .NET SDK
2433
uses: actions/setup-dotnet@v4
2534
with:
2635
dotnet-version: 8.0.x
2736

37+
- name: Restore .NET tools
38+
run: dotnet tool restore
39+
40+
- name: Compute semantic version
41+
id: gitversion
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
JSON=$(dotnet tool run dotnet-gitversion /output json)
46+
echo "$JSON"
47+
48+
NUGET_VERSION=$(echo "$JSON" | jq -r '.NuGetVersion')
49+
FULL_SEMVER=$(echo "$JSON" | jq -r '.FullSemVer')
50+
SHORT_SHA=$(echo "$JSON" | jq -r '.ShortSha')
51+
MAJOR_MINOR_PATCH=$(echo "$JSON" | jq -r '.MajorMinorPatch')
52+
PR_LABEL=$(echo "$JSON" | jq -r '.PreReleaseLabel')
53+
PR_NUMBER=$(echo "$JSON" | jq -r '.PreReleaseNumber')
54+
55+
if [[ "$PR_LABEL" != "" && "$PR_LABEL" != "null" ]]; then
56+
printf -v PR_PADDED '%04d' "$PR_NUMBER"
57+
RELEASE_VERSION_PADDED="${MAJOR_MINOR_PATCH}-${PR_LABEL}.${PR_PADDED}"
58+
else
59+
RELEASE_VERSION_PADDED="$MAJOR_MINOR_PATCH"
60+
fi
61+
62+
echo "nugetVersion=$NUGET_VERSION" >> "$GITHUB_OUTPUT"
63+
echo "fullSemVer=$FULL_SEMVER" >> "$GITHUB_OUTPUT"
64+
echo "releaseVersionPadded=$RELEASE_VERSION_PADDED" >> "$GITHUB_OUTPUT"
65+
echo "informational=${NUGET_VERSION}+${SHORT_SHA}" >> "$GITHUB_OUTPUT"
66+
2867
- name: Restore
2968
run: dotnet restore LiteDB.sln
3069

3170
- name: Build
32-
run: dotnet build LiteDB.sln --configuration Release --no-restore
71+
run: dotnet build LiteDB.sln --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
3372

3473
- name: Test
35-
timeout-minutes: 5
74+
timeout-minutes: 8
3675
run: dotnet test LiteDB.sln --configuration Release --no-build --verbosity normal --settings tests.runsettings --logger "trx;LogFileName=TestResults.trx" --logger "console;verbosity=detailed"
3776

3877
- name: Pack
39-
run: |
40-
dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts
41-
42-
- name: Capture package version
43-
id: version
44-
run: |
45-
PACKAGE_PATH=$(ls artifacts/LiteDB.*.nupkg | head -n 1)
46-
PACKAGE_FILENAME=$(basename "$PACKAGE_PATH")
47-
PACKAGE_VERSION=${PACKAGE_FILENAME#LiteDB.}
48-
PACKAGE_VERSION=${PACKAGE_VERSION%.nupkg}
49-
echo "package_version=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
78+
run: dotnet pack LiteDB/LiteDB.csproj --configuration Release --no-build -o artifacts /p:ContinuousIntegrationBuild=true
5079

5180
- name: Retrieve secrets from Bitwarden
81+
if: ${{ inputs.publish_nuget }}
5282
uses: bitwarden/sm-action@v2
5383
with:
5484
access_token: ${{ secrets.BW_ACCESS_TOKEN }}
@@ -57,15 +87,21 @@ jobs:
5787
265b2fb6-2cf0-4859-9bc8-b24c00ab4378 > NUGET_API_KEY
5888
5989
- name: Push package to NuGet
90+
if: ${{ inputs.publish_nuget }}
91+
env:
92+
PACKAGE_VERSION: ${{ steps.gitversion.outputs.nugetVersion }}
6093
run: |
94+
echo "Pushing LiteDB version $PACKAGE_VERSION"
6195
dotnet nuget push "artifacts/*.nupkg" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
6296
6397
- name: Publish GitHub release
98+
if: ${{ inputs.publish_github }}
6499
uses: softprops/action-gh-release@v2
65100
with:
66-
tag_name: v${{ steps.version.outputs.package_version }}
67-
name: LiteDB ${{ steps.version.outputs.package_version }}
101+
tag_name: v${{ steps.gitversion.outputs.releaseVersionPadded }}
102+
name: LiteDB ${{ steps.gitversion.outputs.releaseVersionPadded }}
68103
generate_release_notes: true
69104
files: artifacts/*.nupkg
105+
target_commitish: ${{ github.sha }}
70106
env:
71107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tag-version.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Tag version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: Branch or SHA to tag
8+
default: master
9+
required: true
10+
bump:
11+
description: Version component to increment
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
default: patch
18+
19+
jobs:
20+
create-tag:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
25+
steps:
26+
- name: Check out repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
ref: ${{ inputs.ref }}
31+
32+
- name: Set up .NET SDK
33+
uses: actions/setup-dotnet@v4
34+
with:
35+
dotnet-version: 8.0.x
36+
37+
- name: Restore .NET tools
38+
run: dotnet tool restore
39+
40+
- name: Determine current version
41+
id: gitversion
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
JSON=$(dotnet tool run dotnet-gitversion /output json)
46+
echo "$JSON"
47+
48+
MAJOR_MINOR_PATCH=$(echo "$JSON" | jq -r '.MajorMinorPatch')
49+
PR_LABEL=$(echo "$JSON" | jq -r '.PreReleaseLabel')
50+
PR_NUMBER=$(echo "$JSON" | jq -r '.PreReleaseNumber')
51+
52+
if [[ "$PR_LABEL" != "" && "$PR_LABEL" != "null" ]]; then
53+
printf -v PR_PADDED '%04d' "$PR_NUMBER"
54+
SEMVER="${MAJOR_MINOR_PATCH}-${PR_LABEL}.${PR_PADDED}"
55+
else
56+
SEMVER="$MAJOR_MINOR_PATCH"
57+
fi
58+
59+
echo "fullSemVer=$SEMVER" >> "$GITHUB_OUTPUT"
60+
echo "major=$(echo "$JSON" | jq -r '.Major')" >> "$GITHUB_OUTPUT"
61+
echo "minor=$(echo "$JSON" | jq -r '.Minor')" >> "$GITHUB_OUTPUT"
62+
echo "patch=$(echo "$JSON" | jq -r '.Patch')" >> "$GITHUB_OUTPUT"
63+
64+
- name: Calculate next version
65+
id: next
66+
shell: bash
67+
env:
68+
BUMP: ${{ inputs.bump }}
69+
MAJOR: ${{ steps.gitversion.outputs.major }}
70+
MINOR: ${{ steps.gitversion.outputs.minor }}
71+
PATCH: ${{ steps.gitversion.outputs.patch }}
72+
run: |
73+
set -euo pipefail
74+
major=$MAJOR
75+
minor=$MINOR
76+
patch=$PATCH
77+
78+
case "$BUMP" in
79+
major)
80+
major=$((major + 1))
81+
minor=0
82+
patch=0
83+
;;
84+
minor)
85+
minor=$((minor + 1))
86+
patch=0
87+
;;
88+
patch)
89+
patch=$((patch + 1))
90+
;;
91+
esac
92+
93+
target="${major}.${minor}.${patch}"
94+
echo "target=$target" >> "$GITHUB_OUTPUT"
95+
96+
- name: Configure git
97+
run: |
98+
git config user.name "github-actions[bot]"
99+
git config user.email "github-actions[bot]@users.noreply.github.com"
100+
101+
- name: Create annotated tag
102+
env:
103+
TARGET: ${{ steps.next.outputs.target }}
104+
run: |
105+
set -euo pipefail
106+
if git rev-parse -q --verify "refs/tags/v${TARGET}" >/dev/null; then
107+
echo "Tag v${TARGET} already exists" >&2
108+
exit 1
109+
fi
110+
111+
git tag -a "v${TARGET}" -m "Release tag v${TARGET}"
112+
113+
- name: Push tag
114+
env:
115+
TARGET: ${{ steps.next.outputs.target }}
116+
run: |
117+
set -euo pipefail
118+
git push origin "v${TARGET}"
119+
120+
- name: Summary
121+
if: always()
122+
env:
123+
TARGET: ${{ steps.next.outputs.target }}
124+
FULL: ${{ steps.gitversion.outputs.fullSemVer }}
125+
run: echo "Created tag v${TARGET} (previous build was ${FULL})"

Directory.Build.props

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<Project>
22
<PropertyGroup>
3-
<MinVerTagPrefix Condition="'$(MinVerTagPrefix)' == ''">v</MinVerTagPrefix>
4-
<!-- Use single prerelease identifier so resulting versions are like 6.0.0-prerelease.3 instead of 6.0.0-prerelease.0.3 when using MinVerMinimumMajorMinor baseline -->
5-
<MinVerDefaultPreReleaseIdentifiers Condition="'$(MinVerDefaultPreReleaseIdentifiers)' == ''">prerelease</MinVerDefaultPreReleaseIdentifiers>
6-
<MinVerMinimumMajorMinor Condition="'$(MinVerMinimumMajorMinor)' == ''">6.0</MinVerMinimumMajorMinor>
3+
<GitVersion_NoFetch Condition="'$(GitVersion_NoFetch)' == ''">true</GitVersion_NoFetch>
4+
<GitVersion_UpdateAssemblyInfo>false</GitVersion_UpdateAssemblyInfo>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<_GitVersionPreReleaseNumberPadded Condition="'$(GitVersion_PreReleaseNumber)' != ''">$([System.String]::Format("{0:0000}", $(GitVersion_PreReleaseNumber)))</_GitVersionPreReleaseNumberPadded>
9+
<_GitVersionCalculatedSemVer Condition="'$(GitVersion_PreReleaseLabel)' != ''">$(GitVersion_MajorMinorPatch)-$(GitVersion_PreReleaseLabel).$(_GitVersionPreReleaseNumberPadded)</_GitVersionCalculatedSemVer>
10+
<_GitVersionCalculatedSemVer Condition="'$(GitVersion_PreReleaseLabel)' == ''">$(GitVersion_MajorMinorPatch)</_GitVersionCalculatedSemVer>
11+
<Version Condition="'$(GitVersion_Major)' != ''">$(_GitVersionCalculatedSemVer)</Version>
12+
<PackageVersion Condition="'$(GitVersion_Major)' != ''">$(_GitVersionCalculatedSemVer)</PackageVersion>
13+
<AssemblyVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_AssemblySemVer)</AssemblyVersion>
14+
<FileVersion Condition="'$(GitVersion_AssemblySemFileVer)' != ''">$(GitVersion_AssemblySemFileVer)</FileVersion>
15+
<InformationalVersion Condition="'$(GitVersion_Major)' != ''">$(_GitVersionCalculatedSemVer)+$(GitVersion_ShortSha)</InformationalVersion>
716
</PropertyGroup>
817

918
<ItemGroup>
10-
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
19+
<PackageReference Include="GitVersion.MsBuild" Version="6.4.0" PrivateAssets="all" />
1120
</ItemGroup>
1221
</Project>

0 commit comments

Comments
 (0)