Skip to content

Commit 6bd17db

Browse files
authored
Simplify/update build (#167)
* Simplify/update build * Add fallback for NUGET_TOKEN - I _think_ this is a bug in Nuke, but need to verify * Extract some common code in test projects Drop .NET 5 testing because meh * Add artifacts layout * Add missing results exporter * Try fix out dir
1 parent 340b598 commit 6bd17db

File tree

12 files changed

+84
-126
lines changed

12 files changed

+84
-126
lines changed

.github/workflows/BuildAndPack.yml

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ on:
2828
- '*'
2929

3030
jobs:
31-
ubuntu-latest:
32-
name: ubuntu-latest
33-
runs-on: ubuntu-22.04 # 24.04 can't run < net6.0
31+
build-and-test:
32+
strategy:
33+
matrix:
34+
include:
35+
- os: windows
36+
vm: windows-latest
37+
- os: linux
38+
vm: ubuntu-latest
39+
- os: macos
40+
vm: macos-13 # latest is arm64, and it breaks a bunch of stuff
41+
env:
42+
MSBuildEnableWorkloadResolver: false
43+
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: "true"
44+
name: ${{ matrix.os}}
45+
runs-on: ${{ matrix.vm}}
3446
steps:
3547
- uses: actions/checkout@v4
3648
- uses: actions/setup-dotnet@v4
@@ -40,87 +52,51 @@ jobs:
4052
8.0.x
4153
7.0.x
4254
6.0.x
43-
5.0.x
4455
3.1.x
56+
4557
- name: Cache .nuke/temp, ~/.nuget/packages
46-
uses: actions/cache@v2
58+
uses: actions/cache@v3
4759
with:
4860
path: |
4961
.nuke/temp
5062
~/.nuget/packages
5163
!~/.nuget/packages/stronglytypeid
5264
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
65+
5366
- name: Run './build.cmd Clean Test TestPackages PushToNuGet'
5467
run: ./build.cmd Clean Test TestPackages PushToNuGet
5568
env:
56-
GithubToken: ${{ secrets.GITHUB_TOKEN }}
57-
NuGetToken: ${{ secrets.NUGET_TOKEN }}
58-
MSBuildEnableWorkloadResolver: false
69+
NuGetToken: ${{ secrets.NUGET_TOKEN || 'NOT_SET'}}
70+
5971
- uses: actions/upload-artifact@v4
6072
with:
61-
name: artifacts-linux
62-
path: artifacts
63-
windows-latest:
64-
name: windows-latest
65-
runs-on: windows-latest
66-
steps:
67-
- uses: actions/checkout@v4
68-
- uses: actions/setup-dotnet@v4
69-
with:
70-
dotnet-version: |
71-
9.0.x
72-
8.0.x
73-
7.0.x
74-
6.0.x
75-
5.0.x
76-
3.1.x
77-
- name: Cache .nuke/temp, ~/.nuget/packages
78-
uses: actions/cache@v2
79-
with:
80-
path: |
81-
.nuke/temp
82-
~/.nuget/packages
83-
!~/.nuget/packages/stronglytypeid
84-
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
85-
- name: Run './build.cmd Clean Test TestPackages PushToNuGet'
86-
run: ./build.cmd Clean Test TestPackages PushToNuGet
87-
env:
88-
GithubToken: ${{ secrets.GITHUB_TOKEN }}
89-
NuGetToken: ${{ secrets.NUGET_TOKEN }}
90-
MSBuildEnableWorkloadResolver: false
73+
name: packages-${{ matrix.os}}
74+
path: artifacts/packages
9175
- uses: actions/upload-artifact@v4
9276
with:
93-
name: artifacts-windows
94-
path: artifacts
95-
macOS-latest:
96-
name: macos-13 # latest is arm64, and it breaks a bunch of stuff
97-
runs-on: macos-13 # latest is arm64, and it breaks a bunch of stuff
77+
name: results-${{ matrix.os}}
78+
path: artifacts/results
79+
80+
publish-test-results:
81+
name: "Publish Tests Results"
82+
needs: build-and-test
83+
runs-on: ubuntu-latest
84+
permissions:
85+
checks: write
86+
pull-requests: write # needed unless run with comment_mode: off
87+
# contents: read # only needed for private repository
88+
# issues: read # only needed for private repository
89+
if: always()
90+
9891
steps:
99-
- uses: actions/checkout@v4
100-
- uses: actions/setup-dotnet@v4
101-
with:
102-
dotnet-version: |
103-
9.0.x
104-
8.0.x
105-
7.0.x
106-
6.0.x
107-
5.0.x
108-
3.1.x
109-
- name: Cache .nuke/temp, ~/.nuget/packages
110-
uses: actions/cache@v2
92+
- name: Download Artifacts
93+
uses: actions/download-artifact@v4
11194
with:
112-
path: |
113-
.nuke/temp
114-
~/.nuget/packages
115-
!~/.nuget/packages/stronglytypeid
116-
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
117-
- name: Run './build.cmd Clean Test TestPackages PushToNuGet'
118-
run: ./build.cmd Clean Test TestPackages PushToNuGet
119-
env:
120-
GithubToken: ${{ secrets.GITHUB_TOKEN }}
121-
NuGetToken: ${{ secrets.NUGET_TOKEN }}
122-
MSBuildEnableWorkloadResolver: false
123-
- uses: actions/upload-artifact@v4
95+
path: artifacts/results
96+
97+
- name: Publish Test Results
98+
uses: EnricoMi/publish-unit-test-result-action@v2
12499
with:
125-
name: artifacts-macos
126-
path: artifacts
100+
files: "artifacts/**/*.trx"
101+
json_thousands_separator: ","
102+
check_run_annotations_branch: "*"

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<RepositoryUrl>https://github.com/andrewlock/StronglyTypedId</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
1717
<CheckEolTargetFramework>false</CheckEolTargetFramework>
18+
<UseArtifactsOutput>true</UseArtifactsOutput>
19+
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
1820
</PropertyGroup>
1921

2022
<PropertyGroup>

StronglyTypedId.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D1907D86-8FFC-4178-A3DB-0ADBDD282C64}"
99
ProjectSection(SolutionItems) = preProject
1010
test\IntegrationLibraries.props = test\IntegrationLibraries.props
11+
test\Directory.Build.props = test\Directory.Build.props
1112
EndProjectSection
1213
EndProject
1314
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C4F0391-8A5A-4225-B356-01EFA94672AB}"

build/Build.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Build : NukeBuild
2828
AbsolutePath SourceDirectory => RootDirectory / "src";
2929
AbsolutePath TestsDirectory => RootDirectory / "test";
3030
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
31+
AbsolutePath TestResultsDirectory => ArtifactsDirectory / "results";
32+
AbsolutePath OutputPackagesDirectory => ArtifactsDirectory / "packages";
3133

3234
[Parameter] readonly string GithubToken;
3335
[Parameter] readonly string NuGetToken;
@@ -72,19 +74,23 @@ class Build : NukeBuild
7274
DotNetTest(s => s
7375
.SetProjectFile(Solution)
7476
.SetConfiguration(Configuration)
77+
.When(_ => IsServerBuild, x => x.SetProperty("ContinuousIntegrationBuild", "true"))
78+
.When(_ => IsServerBuild, x => x
79+
.SetLoggers("trx")
80+
.SetResultsDirectory(TestResultsDirectory))
7581
.EnableNoBuild()
7682
.EnableNoRestore());
7783
});
7884

7985
Target Pack => _ => _
8086
.DependsOn(Compile)
8187
.After(Test)
82-
.Produces(ArtifactsDirectory)
88+
.Produces(OutputPackagesDirectory)
8389
.Executes(() =>
8490
{
8591
DotNetPack(s => s
8692
.SetConfiguration(Configuration)
87-
.SetOutputDirectory(ArtifactsDirectory)
93+
.SetOutputDirectory(OutputPackagesDirectory)
8894
.When(_ => IsServerBuild, x => x.SetProperty("ContinuousIntegrationBuild", "true"))
8995
.EnableNoBuild()
9096
.EnableNoRestore()
@@ -94,7 +100,7 @@ class Build : NukeBuild
94100
Target TestPackages => _ => _
95101
.DependsOn(Pack)
96102
.After(Test)
97-
.Produces(ArtifactsDirectory)
103+
.Produces(OutputPackagesDirectory)
98104
.Executes(() =>
99105
{
100106
var projectFiles = new[]
@@ -124,6 +130,9 @@ class Build : NukeBuild
124130
.SetConfiguration(Configuration)
125131
.EnableNoBuild()
126132
.EnableNoRestore()
133+
.When(_ => IsServerBuild, x => x
134+
.SetLoggers("trx")
135+
.SetResultsDirectory(TestResultsDirectory))
127136
.CombineWith(projectFiles, (s, p) => s.SetProjectFile(p)));
128137

129138
});
@@ -135,7 +144,7 @@ class Build : NukeBuild
135144
.After(Pack)
136145
.Executes(() =>
137146
{
138-
var packages = ArtifactsDirectory.GlobFiles("*.nupkg");
147+
var packages = OutputPackagesDirectory.GlobFiles("*.nupkg");
139148
DotNetNuGetPush(s => s
140149
.SetApiKey(NuGetToken)
141150
.SetSource(NugetOrgUrl)

test/Directory.Build.props

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
3+
4+
<PropertyGroup>
5+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
6+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;netcoreapp3.1;$(TargetFrameworks)</TargetFrameworks>
7+
<IsPackable>false</IsPackable>
8+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
13+
<PackageReference Include="xunit" Version="2.4.2" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="3.2.0">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
</Project>

test/IntegrationLibraries.props

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,7 @@
3333
<ItemGroup>
3434
<PackageReference Include="NewId" Version="4.0.0-develop.44" />
3535
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
36-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
3736
<PackageReference Include="Dapper" Version="2.0.90" />
3837
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
39-
<PackageReference Include="xunit" Version="2.4.2" />
40-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
41-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
42-
<PrivateAssets>all</PrivateAssets>
43-
</PackageReference>
44-
<PackageReference Include="coverlet.collector" Version="3.2.0">
45-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
46-
<PrivateAssets>all</PrivateAssets>
47-
</PackageReference>
4838
</ItemGroup>
4939
</Project>

test/StronglyTypedIds.IntegrationTests.ExternalIds/StronglyTypedIds.IntegrationTests.ExternalIds.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
5-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
6-
<IsPackable>false</IsPackable>
7-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
8-
</PropertyGroup>
9-
103
<ItemGroup>
114
<Compile Include="..\StronglyTypedIds.IntegrationTests\*.cs" Link="%(Filename)%(Extension)" />
125
<Compile Remove="..\StronglyTypedIds.IntegrationTests\Enums.cs" />

test/StronglyTypedIds.IntegrationTests.Types/StronglyTypedIds.IntegrationTests.Types.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
<Import Project="..\..\src\StronglyTypedIds\StronglyTypedId.props" />
44

55
<PropertyGroup>
6-
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
7-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
8-
<IsPackable>false</IsPackable>
9-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
106
<IsTestProject>false</IsTestProject>
117
</PropertyGroup>
128

test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\src\StronglyTypedIds\StronglyTypedId.props" />
33

4-
<PropertyGroup>
5-
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
6-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
7-
<IsPackable>false</IsPackable>
8-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
9-
</PropertyGroup>
10-
114
<ItemGroup>
125
<ProjectReference Include="..\..\src\StronglyTypedIds\StronglyTypedIds.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
136
<ProjectReference Include="..\..\src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />

test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
5-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
6-
<IsPackable>false</IsPackable>
74
<DefineConstants>STRONGLY_TYPED_ID_EMBED_ATTRIBUTES</DefineConstants>
85
</PropertyGroup>
96

0 commit comments

Comments
 (0)