Skip to content

Commit f6487f7

Browse files
committed
refactor: improve CI workflow, build system, docs, and init scripts
- Simplify VERSION_SUFFIX handling in CI by removing if/else branching - Merge OIDC and API key NuGet push steps into a single conditional step - Extract ApplyVersionSuffix helper to eliminate repetition across NUKE targets - Add dotnet-stryker to tool manifest for mutation testing - Add RefreshLockFiles NUKE target for lock file regeneration - Set explicit IsPackable=false on test project - Fix double-slash paths in build.sh - Fix Calculator API docs (static class, correct parameter names) - Migrate init script logic to NUKE Init target, simplify shell wrappers Made-with: Cursor
1 parent 7570b17 commit f6487f7

20 files changed

Lines changed: 306 additions & 386 deletions

.config/dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"reportgenerator"
99
],
1010
"rollForward": false
11+
},
12+
"dotnet-stryker": {
13+
"version": "4.13.0",
14+
"commands": [
15+
"stryker"
16+
],
17+
"rollForward": false
1118
}
1219
}
1320
}

.github/workflows/ci.yml

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,12 @@ jobs:
260260
- name: Build and test
261261
if: runner.os != 'Windows'
262262
shell: bash
263-
env:
264-
VERSION_SUFFIX: ${{ needs.resolve-version.outputs.version_suffix }}
265-
run: |
266-
if [ -n "$VERSION_SUFFIX" ]; then
267-
./build.sh Test --VersionSuffix "$VERSION_SUFFIX"
268-
else
269-
./build.sh Test
270-
fi
263+
run: ./build.sh Test --VersionSuffix "${{ needs.resolve-version.outputs.version_suffix }}"
271264

272265
- name: Build and test (Windows)
273266
if: runner.os == 'Windows'
274267
shell: pwsh
275-
env:
276-
VERSION_SUFFIX: ${{ needs.resolve-version.outputs.version_suffix }}
277-
run: |
278-
if ($env:VERSION_SUFFIX) {
279-
./build.ps1 Test --VersionSuffix "$env:VERSION_SUFFIX"
280-
} else {
281-
./build.ps1 Test
282-
}
268+
run: ./build.ps1 Test --VersionSuffix "${{ needs.resolve-version.outputs.version_suffix }}"
283269

284270
- name: Generate coverage report
285271
if: matrix.runtime == 'linux-x64'
@@ -468,35 +454,14 @@ jobs:
468454
with:
469455
user: ${{ vars.NUGET_USER || github.repository_owner }}
470456

471-
- name: Push to NuGet.org (OIDC)
472-
if: env.ENABLE_NUGET == 'true' && env.NUGET_USE_OIDC == 'true'
473-
shell: bash
474-
env:
475-
API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
476-
run: |
477-
shopt -s nullglob
478-
PACKAGES=(artifacts/packages/*.nupkg)
479-
if [ ${#PACKAGES[@]} -eq 0 ]; then
480-
echo "::error::No .nupkg files found"
481-
exit 1
482-
fi
483-
for pkg in "${PACKAGES[@]}"; do
484-
echo "Pushing $pkg"
485-
dotnet nuget push "$pkg" \
486-
--api-key "$API_KEY" \
487-
--source https://api.nuget.org/v3/index.json \
488-
--skip-duplicate
489-
done
490-
echo "All packages pushed to NuGet.org via Trusted Publishing"
491-
492-
- name: Push to NuGet.org (API key)
493-
if: env.ENABLE_NUGET == 'true' && env.NUGET_USE_OIDC != 'true'
457+
- name: Push to NuGet.org
458+
if: env.ENABLE_NUGET == 'true'
494459
shell: bash
495460
env:
496-
API_KEY: ${{ secrets.NUGET_API_KEY }}
461+
API_KEY: ${{ env.NUGET_USE_OIDC == 'true' && steps.nuget-login.outputs.NUGET_API_KEY || secrets.NUGET_API_KEY }}
497462
run: |
498463
if [ -z "$API_KEY" ]; then
499-
echo "::error::ENABLE_NUGET is true but NUGET_API_KEY secret is not set. Either set the secret or change NUGET_USE_OIDC to true."
464+
echo "::error::NUGET_API_KEY is not available. Set the secret or enable OIDC."
500465
exit 1
501466
fi
502467
shopt -s nullglob
@@ -512,12 +477,6 @@ jobs:
512477
--source https://api.nuget.org/v3/index.json \
513478
--skip-duplicate
514479
done
515-
echo "All packages pushed to NuGet.org via API key"
516-
517-
- name: NuGet disabled
518-
if: env.ENABLE_NUGET != 'true'
519-
shell: bash
520-
run: echo "::notice::NuGet is disabled (ENABLE_NUGET != true). Skipping NuGet push."
521480
522481
- name: Generate SBOM
523482
uses: anchore/sbom-action@57aae528053a48a3f6235f2d9461b05fbcb7366d # v0.23.1

.nuke/build.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
"CoverageReport",
3131
"Format",
3232
"GenerateReleaseManifest",
33+
"Init",
3334
"MutationTest",
3435
"Pack",
3536
"PackageApp",
3637
"Publish",
38+
"RefreshLockFiles",
3739
"Restore",
3840
"ShowVersion",
3941
"Test",
@@ -113,6 +115,10 @@
113115
"allOf": [
114116
{
115117
"properties": {
118+
"Author": {
119+
"type": "string",
120+
"description": "Author / organization for Init target"
121+
},
116122
"BenchmarkFilter": {
117123
"type": "string",
118124
"description": "Filter expression for BenchmarkDotNet (e.g., '*Calculator*')"
@@ -135,6 +141,14 @@
135141
"description": "Minimum line coverage percentage (0-100). CoverageReport fails if below this threshold",
136142
"format": "int32"
137143
},
144+
"ProjectName": {
145+
"type": "string",
146+
"description": "New project name for Init target (e.g. Acme.Payments)"
147+
},
148+
"ResetGit": {
149+
"type": "boolean",
150+
"description": "Reset git history to a fresh commit during Init"
151+
},
138152
"Runtime": {
139153
"type": "string",
140154
"description": "Target runtime identifier used by Publish target"

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
3232
To publish an RC: trigger workflow_dispatch with prerelease_suffix=rc.1 -->
3333
<PropertyGroup>
34-
<VersionPrefix>0.2.7</VersionPrefix>
34+
<VersionPrefix>0.2.8</VersionPrefix>
3535
<FileVersion Condition="'$(BuildNumber)' != ''">$(VersionPrefix).$(BuildNumber)</FileVersion>
3636
</PropertyGroup>
3737

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
1010
###########################################################################
1111

1212
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13-
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
13+
TEMP_DIRECTORY="$SCRIPT_DIR/.nuke/temp"
1414

15-
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR/global.json"
1616
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
1717
DOTNET_CHANNEL="STS"
1818

build/BuildTask.Helpers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Nuke.Common.Tools.DotNet;
2+
3+
partial class BuildTask
4+
{
5+
DotNetBuildSettings ApplyVersionSuffix(DotNetBuildSettings settings) =>
6+
string.IsNullOrWhiteSpace(VersionSuffix) ? settings : settings.SetVersionSuffix(VersionSuffix);
7+
8+
DotNetPackSettings ApplyVersionSuffix(DotNetPackSettings settings) =>
9+
string.IsNullOrWhiteSpace(VersionSuffix) ? settings : settings.SetVersionSuffix(VersionSuffix);
10+
11+
DotNetPublishSettings ApplyVersionSuffix(DotNetPublishSettings settings) =>
12+
string.IsNullOrWhiteSpace(VersionSuffix) ? settings : settings.SetVersionSuffix(VersionSuffix);
13+
14+
DotNetTestSettings ApplyVersionSuffix(DotNetTestSettings settings) =>
15+
string.IsNullOrWhiteSpace(VersionSuffix) ? settings : settings.SetProperty("VersionSuffix", VersionSuffix);
16+
}

build/BuildTask.Parameters.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ partial class BuildTask
3232
[Parameter("Minimum branch coverage percentage (0-100). CoverageReport fails if below this threshold.")]
3333
readonly int BranchCoverageThreshold = 90;
3434

35+
[Parameter("New project name for Init target (e.g. Acme.Payments)")]
36+
readonly string ProjectName = string.Empty;
37+
38+
[Parameter("Author / organization for Init target")]
39+
readonly string Author = string.Empty;
40+
41+
[Parameter("Reset git history to a fresh commit during Init")]
42+
readonly bool ResetGit;
43+
3544
// Common output/input locations.
3645
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
3746
AbsolutePath TestResultsDirectory => ArtifactsDirectory / "test-results";

build/BuildTask.Targets.Build.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ partial class BuildTask
88
.DependsOn(Restore)
99
.Executes(() =>
1010
{
11-
DotNetBuild(settings =>
12-
{
13-
settings = settings
11+
DotNetBuild(settings => ApplyVersionSuffix(settings
1412
.SetProjectFile(BuildPath)
1513
.SetConfiguration(Configuration)
1614
.EnableNoRestore()
17-
.SetNoLogo(true);
18-
19-
if (!string.IsNullOrWhiteSpace(VersionSuffix))
20-
settings = settings.SetVersionSuffix(VersionSuffix);
21-
22-
return settings;
23-
});
15+
.SetNoLogo(true)));
2416

2517
WriteBuildOutputsMarker();
2618
});

0 commit comments

Comments
 (0)