Skip to content

Commit

Permalink
Update Versioning (#3)
Browse files Browse the repository at this point in the history
* revert to manual versioning

* Calculate version on CI

* add manual trigger option

* fix config

* fix code

* Add further CI params

* fix restore params

* append build id to version suffix
  • Loading branch information
gasparnagy authored Jan 19, 2024
1 parent fb1a1d0 commit 2c9fc7b
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 43 deletions.
79 changes: 71 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,40 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
configuration:
description: 'Build Configuration'
required: true
default: 'Debug'
type: choice
options:
- Debug
- Release
version_suffix:
description: 'Suffix for the NuGet packages (without leading -). Build ID will be appended.'
required: false
specs_filter:
description: 'Filter for Specs execution (e.g. Category=basicExecution)'
required: false


permissions:
checks: write

env:
SPECS_FILTER: "" # use for testing CI: "&Category=quarantaine"
SPECS_FILTER: "" # use for testing CI: "&Category=basicExecution"

jobs:
build:

runs-on: ubuntu-latest

outputs:
product_version_suffix: ${{ steps.versions.outputs.product_version_suffix }}
product_configuration: ${{ steps.versions.outputs.product_configuration }}
build_params: ${{ steps.versions.outputs.build_params }}

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -25,10 +47,46 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- id: versions
name: Calculate versions
shell: pwsh
run: |
$versionSuffix = "${{ inputs.version_suffix }}"
if ($versionSuffix -eq "") {
$date = [datetime]::Today
$dateString = $date.ToString('yyyyMMdd')
$versionSuffix = "ci$dateString-${env:GITHUB_RUN_NUMBER}"
}
else {
$versionSuffix = "$versionSuffix-${env:GITHUB_RUN_NUMBER}"
}
Write-Output "product_version_suffix=$versionSuffix" >> $env:GITHUB_OUTPUT
Write-Output "Product Suffix: $versionSuffix"
$productConfig = "${{ inputs.configuration }}"
if ($productConfig -eq "") {
$productConfig = "Debug"
}
Write-Output "product_configuration=$productConfig" >> $env:GITHUB_OUTPUT
Write-Output "Product Configuration: $productConfig"
$specsFilter = "${{ inputs.specs_filter }}"
if ($specsFilter -ne "") {
$specsFilter = "&$specsFilter"
}
else {
$specsFilter = $envSPECS_FILTER
}
Write-Output "specs_filter=$specsFilter" >> $env:GITHUB_OUTPUT
Write-Output "Specs Filter: $specsFilter"
$buildParams = "-p:VersionSuffix=$versionSuffix -c $productConfig"
Write-Output "build_params=$buildParams" >> $env:GITHUB_OUTPUT
Write-Output "Build Params: $buildParams"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore ${{ steps.versions.outputs.build_params }}
- name: Runtime Tests
run: dotnet test ./Tests/Reqnroll.RuntimeTests/Reqnroll.RuntimeTests.csproj --no-build --verbosity normal -f net6.0
- name: Plugin Tests
Expand All @@ -37,6 +95,11 @@ jobs:
run: dotnet test ./Tests/Reqnroll.GeneratorTests/Reqnroll.GeneratorTests.csproj --no-build --verbosity normal -f net6.0
- name: ExternalData Plugin Tests
run: dotnet test ./Plugins/Reqnroll.ExternalData/Reqnroll.ExternalData.ReqnrollPlugin.UnitTests/Reqnroll.ExternalData.ReqnrollPlugin.UnitTests.csproj --no-build --verbosity normal -f net6.0
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: packages
path: "GeneratedNuGetPackages/**/*.nupkg"

specs-xunit:
runs-on: ubuntu-latest
Expand All @@ -54,12 +117,12 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: xUnit Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=xUnit&Category=Net60&Category!=requiresMsBuild$env:SPECS_FILTER" --logger "trx;LogFileName=specs-xunit-results.trx"
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=xUnit&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-xunit-results.trx"
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
Expand Down Expand Up @@ -89,12 +152,12 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: NUnit Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=NUnit3&Category=Net60&Category!=requiresMsBuild$env:SPECS_FILTER" --logger "trx;LogFileName=specs-nunit-results.trx"
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=NUnit3&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-nunit-results.trx"
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
Expand Down Expand Up @@ -125,12 +188,12 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: MsTest Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=MsTest&Category=Net60&Category!=requiresMsBuild$env:SPECS_FILTER" --logger "trx;LogFileName=specs-mstest-results.trx"
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj --no-build --verbosity normal -f net6.0 --filter "Category=MsTest&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-mstest-results.trx"
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ GitExtensions.settings.backup
*.AssemblyHooks.cs
*.AssemblyHooks.vb

# Nerdbank.GitVersioning
# Version for Specs
Tests/Reqnroll.Specs/NuGetPackageVersion.cs

#Analytics
Expand Down
9 changes: 7 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
<Reqnroll_Owners>Reqnroll</Reqnroll_Owners>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>local</VersionSuffix>
<AssemblyVersion>1.0.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107" PrivateAssets="all"/>
<None Include="$(MSBuildThisFileDirectory)/LICENSE.txt" Pack="true" PackagePath=""/>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -19,7 +24,7 @@

<PropertyGroup>
<Authors>$(Reqnroll_Authors)</Authors>
<Company>Tricentis</Company>
<Company>Reqnroll</Company>
<Product />
<PackageProjectUrl>https://reqnroll.net</PackageProjectUrl>
<PackageIcon>images/reqnroll-icon.png</PackageIcon>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(NuGetPackageVersion)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);SolutionDir=$(MSBuildThisFileDirectory)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);copyright=$(Reqnroll_Copyright)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);author=$(Reqnroll_Authors)</NuspecProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@


<Target Name="WriteAssemblyHooksVersion" AfterTargets="GetBuildVersion" BeforeTargets="BeforeCompile" Condition="$(DesignTimeBuild) != 'true' or '$(BuildingProject)' == 'true'">
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\MSTest.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</ItemGroup>

<Target Name="WriteAssemblyHooksVersion" AfterTargets="GetBuildVersion" BeforeTargets="BeforeCompile" Condition="$(DesignTimeBuild) != 'true' or '$(BuildingProject)' == 'true'">
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\NUnit.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<_Reqnroll_SpecFlowCompatibilityGeneratorPlugin Condition=" '$(MSBuildRuntimeType)' != 'Core'">net462</_Reqnroll_SpecFlowCompatibilityGeneratorPlugin>
<_Reqnroll_SpecFlowCompatibilityGeneratorPluginPath>$(MSBuildThisFileDirectory)\$(_Reqnroll_SpecFlowCompatibilityGeneratorPlugin)\Reqnroll.SpecFlowCompatibility.Generator.ReqnrollPlugin.dll</_Reqnroll_SpecFlowCompatibilityGeneratorPluginPath>

<_Reqnroll_SpecFlowCompatibilityRuntimePlugin Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">netstandard2.0</_Reqnroll_SpecFlowCompatibilityRuntimePlugin>
<_Reqnroll_SpecFlowCompatibilityRuntimePlugin Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">net462</_Reqnroll_SpecFlowCompatibilityRuntimePlugin>
<_Reqnroll_SpecFlowCompatibilityRuntimePlugin Condition=" '$(TargetFrameworkIdentifier)' != '.NETFramework' ">netstandard2.0</_Reqnroll_SpecFlowCompatibilityRuntimePlugin>
<_Reqnroll_SpecFlowCompatibilityRuntimePluginPath>$(MSBuildThisFileDirectory)\..\lib\$(_Reqnroll_SpecFlowCompatibilityRuntimePlugin)\Reqnroll.SpecFlowCompatibility.ReqnrollPlugin.dll</_Reqnroll_SpecFlowCompatibilityRuntimePluginPath>

</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Reqnroll;

// ReSharper disable once CheckNamespace
namespace TechTalk.SpecFlow.Infrastructure;

public class NotUsedClassToPreserveInfrastructureNamespace;
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</ItemGroup>

<Target Name="WriteAssemblyHooksVersion" AfterTargets="GetBuildVersion" BeforeTargets="BeforeCompile" Condition="$(DesignTimeBuild) != 'true' or '$(BuildingProject)' == 'true'">
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.template.cs" OutputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.cs" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.template.vb" OutputFile="$(MSBuildThisFileDirectory)\build\xUnit.AssemblyHooks.vb" TextToReplace="REQNROLL_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />

</Target>

Expand Down
2 changes: 1 addition & 1 deletion Reqnroll/Analytics/AnalyticsEventProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private bool IsRunningInDockerContainer()

private string GetReqnrollVersion()
{
return ThisAssembly.AssemblyInformationalVersion;
return VersionInfo.AssemblyInformationalVersion;
}

private string ToSha256(string inputString)
Expand Down
24 changes: 17 additions & 7 deletions Reqnroll/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace Reqnroll
using System.Reflection;

namespace Reqnroll;

internal class VersionInfo
{
internal class VersionInfo
internal static string AssemblyVersion { get; }
internal static string AssemblyFileVersion { get; }
internal static string AssemblyInformationalVersion { get; }
internal static string NuGetVersion { get; }

static VersionInfo()
{
internal static string AssemblyVersion => ThisAssembly.AssemblyVersion;
internal static string AssemblyFileVersion => ThisAssembly.AssemblyFileVersion;
internal static string AssemblyInformationalVersion => ThisAssembly.AssemblyInformationalVersion;
internal static string NuGetVersion => ThisAssembly.AssemblyInformationalVersion.Replace("+", "-");
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
AssemblyVersion = assembly.GetName().Version.ToString();
AssemblyFileVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
AssemblyInformationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
NuGetVersion = AssemblyInformationalVersion?.Split(new[] { '+' }, 2)[0];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</ItemGroup>

<Target Name="PopulateMetaTemplate" AfterTargets="CoreCompile">
<WriteLinesToFile File="$(OutDir)\templates\%(MetaTemplate.RecursiveDir)\%(MetaTemplate.FileName)%(MetaTemplate.Extension)" Lines="$([System.IO.File]::ReadAllText(%(MetaTemplate.FullPath)).Replace('$$$NuGetPackageVersion$$$',$(NuGetPackageVersion)).Replace('$$$MajorMinorVersion$$$',$(MajorMinorVersion)))" Overwrite="true" />
<WriteLinesToFile File="$(OutDir)\templates\%(MetaTemplate.RecursiveDir)\%(MetaTemplate.FileName)%(MetaTemplate.Extension)" Lines="$([System.IO.File]::ReadAllText(%(MetaTemplate.FullPath)).Replace('$$$NuGetPackageVersion$$$',$(PackageVersion)).Replace('$$$MajorMinorVersion$$$',$(MajorMinorVersion)))" Overwrite="true" />
<ItemGroup>
<Content Include="$(OutDir)\templates\**\*" PackagePath="content" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Reqnroll.Specs/Reqnroll.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@


<Target Name="WriteNuGetVersion" AfterTargets="GetBuildVersion" BeforeTargets="BeforeCompile" Condition="$(DesignTimeBuild) != 'true' OR '$(BuildingProject)' == 'true'">
<ReplaceTextInFileTask InputFile="$(ProjectDir)\\NuGetPackageVersion.template.cs" OutputFile="$(ProjectDir)\\NuGetPackageVersion.cs" TextToReplace="NUGET_VERSION" TextToReplaceWith="$(NuGetPackageVersion)" WriteOnlyWhenChanged="true" />
<ReplaceTextInFileTask InputFile="$(ProjectDir)\\NuGetPackageVersion.template.cs" OutputFile="$(ProjectDir)\\NuGetPackageVersion.cs" TextToReplace="NUGET_VERSION" TextToReplaceWith="$(PackageVersion)" WriteOnlyWhenChanged="true" />

<ItemGroup>
<Compile Include="$(ProjectDir)\\NuGetPackageVersion.cs" />
Expand Down
13 changes: 0 additions & 13 deletions version.json

This file was deleted.

0 comments on commit 2c9fc7b

Please sign in to comment.