From e184518608c0aed7f2813ddc2c85b2b762312555 Mon Sep 17 00:00:00 2001
From: Frederik91 <11948105+Frederik91@users.noreply.github.com>
Date: Tue, 10 Jun 2025 10:39:04 +0200
Subject: [PATCH] Integrate GitVersion for deterministic versioning
---
.github/workflows/dotnet.yml | 38 +++++++++++--------
.gitversion.yml | 6 +++
.../MakeInterface.Generator.csproj | 5 ++-
readme.md | 14 +++----
4 files changed, 39 insertions(+), 24 deletions(-)
create mode 100644 .gitversion.yml
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 708ea87..c8e2c66 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -3,7 +3,7 @@ name: .NET
on:
push:
branches: [ "master" ]
- tags: [ "v*" ]
+ tags: [ "*" ]
pull_request:
branches: [ "master" ]
@@ -12,38 +12,46 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
+ - uses: gittools/actions/gitversion/setup@v3
+ - id: gitversion
+ uses: gittools/actions/gitversion/execute@v3
+
- name: Restore dependencies
run: dotnet restore
- - name: Determine package version
- id: version
- shell: bash
- run: |
- if [ "$GITHUB_REF_TYPE" = "tag" ]; then
- echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- else
- echo "version=0.1.0-ci.${GITHUB_RUN_NUMBER}" >> "$GITHUB_OUTPUT"
- fi
-
- name: Build
- run: dotnet build --no-restore --configuration Release /p:Version=${{ steps.version.outputs.version }}
+ run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --verbosity normal --configuration Release
- name: Pack
- run: dotnet pack MakeInterface.Generator/MakeInterface.Generator.csproj --no-build --configuration Release /p:PackageVersion=${{ steps.version.outputs.version }} -o ./artifacts
+ run: >
+ dotnet pack MakeInterface.Generator/MakeInterface.Generator.csproj
+ --no-build -c Release
+ /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}
+ -o ./artifacts
- name: Publish prerelease to GitHub Packages
if: github.event_name == 'push' && github.ref_type == 'branch'
- run: dotnet nuget push ./artifacts/MakeInterface.Generator.${{ steps.version.outputs.version }}.nupkg --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
+ run: >
+ dotnet nuget push
+ ./artifacts/MakeInterface.Generator.${{ steps.gitversion.outputs.nuGetVersionV2 }}.nupkg
+ --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
+ --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
- name: Publish release to NuGet.org
if: github.ref_type == 'tag'
- run: dotnet nuget push ./artifacts/MakeInterface.Generator.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
+ run: >
+ dotnet nuget push
+ ./artifacts/MakeInterface.Generator.${{ steps.gitversion.outputs.nuGetVersionV2 }}.nupkg
+ --source https://api.nuget.org/v3/index.json
+ --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
diff --git a/.gitversion.yml b/.gitversion.yml
new file mode 100644
index 0000000..9929659
--- /dev/null
+++ b/.gitversion.yml
@@ -0,0 +1,6 @@
+mode: ContinuousDeployment
+branches:
+ master:
+ regex: ^master$
+ label: ''
+commit-message-incrementing: Enabled
diff --git a/MakeInterface.Generator/MakeInterface.Generator.csproj b/MakeInterface.Generator/MakeInterface.Generator.csproj
index 0da2d71..023be31 100644
--- a/MakeInterface.Generator/MakeInterface.Generator.csproj
+++ b/MakeInterface.Generator/MakeInterface.Generator.csproj
@@ -11,7 +11,6 @@
library
netstandard2.0
MakeInterface.Generator
- 1.0.0
Frederik Tegnander
COWI
Interfaces;SourceGenerator;MakeInterface
@@ -44,6 +43,10 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
all
diff --git a/readme.md b/readme.md
index 54757ed..bb1c11e 100644
--- a/readme.md
+++ b/readme.md
@@ -97,17 +97,15 @@ dotnet add package MakeInterface.Generator
```
The `GenerateInterface` attribute is included in the package and will be available after the build without adding any extra references.
-Install the NuGet package [MakeInterface](https://www.nuget.org/packages/MakeInterface.Generator/):
-
-```bash
-dotnet add package MakeInterface.Generator
-```
-The `GenerateInterface` attribute is included in the package and will be available after the build without adding any extra references.
+## Versioning
+This repository uses [GitVersion](https://gitversion.net/) in **Continuous Deployment** mode.
+Every build calculates a deterministic SemVer 2.0 version from the Git history.
+Local builds and CI therefore produce identical package and assembly versions.
## License
MIT
## Release process
-- Pushes to the `master` branch publish prerelease packages to GitHub Packages using versions like `0.1.0-ci.`.
-- Tagging the repository with `v` automatically publishes that version to NuGet.org if `NUGET_API_KEY` is configured.
+- Pushes to `master` publish prerelease packages to GitHub Packages using the version calculated by GitVersion.
+- Tagging the repository publishes the tagged version to NuGet.org when `NUGET_API_KEY` is configured.