Skip to content

Add NuGet package to write git.properties file - #1717

Merged
bart-vmware merged 9 commits into
mainfrom
git-properties-msbuild
Jul 29, 2026
Merged

Add NuGet package to write git.properties file#1717
bart-vmware merged 9 commits into
mainfrom
git-properties-msbuild

Conversation

@bart-vmware

@bart-vmware bart-vmware commented Jul 13, 2026

Copy link
Copy Markdown
Member

Description

Adds a new build-time-only package, Steeltoe.Management.GitProperties.Build, that generates a git.properties file compatible with the Spring Boot Actuator format, and wires it into the existing Info actuator endpoint (GitInfoContributor) so the values are automatically exposed at runtime.

How it works

  • New MSBuild tasks project (src/Management/src/GitProperties.Build) hooks into the build pipeline, auto-detected when a project references Steeltoe.Management.Endpoint (configurable via GenerateGitProperties/GitPropertiesConsumingPackageIds).
  • Repository-wide info (commit id, branch, tags, remote URL, dirty state, etc.) is computed at most once per build and cached in a shared obj/git.properties.cache file at the repo root, reused by every project/TFM in a solution. The cache refreshes automatically via MSBuild incremental-build Inputs tracking (HEAD, config, packed-refs, refs/**) whenever something changes in the repo.
  • Git worktrees and submodules are each treated as independent repositories with their own shared cache.
  • For deployments that don't carry .git along (e.g. cf push), dotnet build -t:WriteGitPropertiesFallbackFile writes a durable fallback copy that's used automatically whenever no live .git is available.
  • GitInfoContributor (runtime side) now checks next to the app's own assembly first, falling back to the current working directory, so it finds git.properties regardless of how the app is launched.

Diagnostics

Seven GITPROPS00x codes cover every place generation can be skipped or left partial (repository not found, invalid, git executable missing, incompatible version, no commits, shallow clone, dirty-state unknown) — see the package's Diagnostics table. All are forgiving by default: generation is skipped with a suppressible warning instead of failing the build, so it's safe to add this package to projects that aren't always built inside a git checkout (e.g. a Docker build stage).

Known, documented limitations

Called out explicitly in the package readme's "Good to know" section:

  • File deletions inside .git (e.g. git tag -d, git fetch --unshallow) don't invalidate the shared cache by themselves — it catches up the next time something else changes.
  • Changing your global git username/email isn't tracked by the shared cache either, for the same reason.

CI changes

  • The test suite spawns real nested dotnet build/publish subprocesses per test, which fragments coverage data (ephemeral temp paths, duplicate <class> entries per subprocess); merge-subprocess-coverage.ps1 repairs that before upload.
  • A Category=GitProperties xUnit trait (on the test project's shared base class) is used to run the tests isolated in cibuilds, which is needed because coverage is collected differently: Coverlet is unable to instrument subprocesses.
  • COMMON_TEST_ARGS/SONAR_TEST_ARGS now only contain flags genuinely shared by every dotnet test invocation in each workflow; VSTest-coverage-collector-specific flags moved to their own COVERAGE_COLLECT_ARGS var, since this suite collects coverage its own way and can't use them.

Test plan

  • 43 new tests in GitProperties.Build.Test, covering auto-detection, all 7 diagnostics (including both trigger paths for the 3 diagnostics that can fire for two different reasons), the shared cache (multi-project, multi-TFM, incremental build, build-time-vs-commit-time), the fallback file (including .gitignore interaction), worktrees, submodules, publish/push scenarios, and property-content correctness (branch env var fallback, non-ASCII data, multiple remotes, shallow clones).
  • 1 new unit test (GitInfoContributorTest) for the runtime path-resolution change.

Quality checklist

  • Your code complies with our Coding Style.
  • You've updated unit and/or integration tests for your change, where applicable.
  • You've updated documentation for your change, where applicable.
    If your change affects other repositories, such as Documentation and/or Samples, add linked PRs here.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.
  • You've added required license files and/or file headers (explaining where the code came from with proper attribution), where code is copied from StackOverflow, a blog, or OSS.

@bart-vmware
bart-vmware force-pushed the git-properties-msbuild branch 2 times, most recently from 6ded66c to c2ae488 Compare July 13, 2026 15:09
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary - All Code Coverage (ubuntu-latest)

Line coverage Branch coverage

Assembly Line coverage Branch coverage
Steeltoe.Bootstrap.AutoConfiguration 97.4% 83.3%
Steeltoe.Common 86.4% 77%
Steeltoe.Common.Certificates 97.2% 80.2%
Steeltoe.Common.Hosting 83.5% 65%
Steeltoe.Common.Http 97.4% 80.9%
Steeltoe.Common.Logging 81.1% 56.2%
Steeltoe.Common.Net 64.5% 66.6%
Steeltoe.Configuration.Abstractions 96.3% 89.4%
Steeltoe.Configuration.CloudFoundry 97.8% 92.7%
Steeltoe.Configuration.ConfigServer 91.6% 86.2%
Steeltoe.Configuration.Encryption 97.6% 87.8%
Steeltoe.Configuration.Kubernetes.ServiceBindings 95.6% 82.6%
Steeltoe.Configuration.Placeholder 93.8% 82.6%
Steeltoe.Configuration.RandomValue 93.2% 83.3%
Steeltoe.Configuration.SpringBoot 98.3% 85%
Steeltoe.Connectors 94.5% 85.6%
Steeltoe.Connectors.EntityFrameworkCore 79.7% 65.3%
Steeltoe.Discovery.Configuration 96.3% 75%
Steeltoe.Discovery.Consul 91.5% 84%
Steeltoe.Discovery.Eureka 91.6% 81.3%
Steeltoe.Discovery.HttpClients 89.9% 91.4%
Steeltoe.Logging.Abstractions 99.4% 95.6%
Steeltoe.Logging.DynamicConsole 100% 92.3%
Steeltoe.Logging.DynamicSerilog 99.1% 95.4%
Steeltoe.Management.Abstractions 100% 100%
Steeltoe.Management.Endpoint 96% 87.1%
Steeltoe.Management.GitProperties.Build 94.7% 83%
Steeltoe.Management.Prometheus 95.8% 76.9%
Steeltoe.Management.Tasks 95.2% 80%
Steeltoe.Management.Tracing 100% 75%
Steeltoe.Security.Authentication.JwtBearer 100% 93.7%
Steeltoe.Security.Authentication.OpenIdConnect 87.7% 66.6%
Steeltoe.Security.Authorization.Certificate 95.6% 61.5%
Steeltoe.Security.DataProtection.Redis 100% ****

@bart-vmware
bart-vmware force-pushed the git-properties-msbuild branch 3 times, most recently from a045fa7 to 5541b47 Compare July 15, 2026 13:41
@bart-vmware
bart-vmware force-pushed the git-properties-msbuild branch 4 times, most recently from ea002dc to 4bde509 Compare July 28, 2026 14:27
@bart-vmware
bart-vmware force-pushed the git-properties-msbuild branch from 4bde509 to 5fe27dc Compare July 28, 2026 15:28
@bart-vmware
bart-vmware marked this pull request as ready for review July 28, 2026 15:39
@bart-vmware
bart-vmware requested a review from TimHess July 28, 2026 15:39
Comment thread .github/workflows/sonarcube.yml
Comment thread .github/workflows/Steeltoe.All.yml
Comment thread src/Management/src/GitProperties.Build/AtomicFile.cs Outdated
Comment thread src/Management/src/GitProperties.Build/GitPropertiesFormat.cs
@bart-vmware
bart-vmware requested a review from TimHess July 29, 2026 12:52
@sonarqubecloud

Copy link
Copy Markdown

@TimHess TimHess left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bart-vmware
bart-vmware merged commit c82ef38 into main Jul 29, 2026
25 checks passed
@bart-vmware
bart-vmware deleted the git-properties-msbuild branch July 29, 2026 14:07
@TimHess TimHess added this to the 4.3.0 milestone Jul 29, 2026
@TimHess TimHess added the Type/enhancement New feature or request label Jul 29, 2026
@TimHess TimHess added Component/Management Issues related to Steeltoe Management (actuators) ReleaseLine/4.x Identified as a feature/fix for the 4.x release line labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component/Management Issues related to Steeltoe Management (actuators) ReleaseLine/4.x Identified as a feature/fix for the 4.x release line Type/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants