Skip to content

Add a release workflow using nuget.org trusted publishing - #4123

Merged
AArnott merged 8 commits into
masterfrom
release-workflow
Oct 12, 2026
Merged

AArnott merged 8 commits into
masterfrom
release-workflow

Conversation

@AArnott

@AArnott AArnott commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Adds a release workflow that publishes the single StyleCop.Analyzers package to nuget.org using nuget.org Trusted Publishing. GitHub OIDC is exchanged for a short-lived API key by NuGet/login; no API key secret is stored.

Release flow

  1. nbgv tag origin/master creates the release tag, then the tag is pushed.
  2. A draft GitHub release is created and its notes are curated.
  3. Once the Build workflow has passed for that exact commit on master or the applicable vX.Y servicing branch, the release is published.
  4. release.yml runs:
    • prepare (actions: read, contents: read): resolves the tag to a commit, derives the matching vX.Y servicing branch from the tag, finds the successful Build run for that commit on master or that servicing branch, downloads its nuget-packages artifact, and validates that it contains exactly one public StyleCop.Analyzers package whose version matches the tag.
    • publish (environment release, id-token: write only): waits for approval, obtains a short-lived NuGet API key with NuGet/login, and pushes the package with --skip-duplicate.
    • attach (contents: write): uploads the package to the GitHub release when one exists.

The workflow can also be started with workflow_dispatch and a tag input to retry a release. Reusing the successful CI artifact ensures that the package being published is exactly the package that was tested. A release-tag build is not used because Nerdbank.GitVersioning produces private build metadata outside the configured public release refs.

CI trigger changes

The Build workflow intentionally runs on pushes to master, vX.Y servicing branches, and validate/* branches, and runs for pull requests regardless of their base branch. This ensures that release, servicing, and validation-branch changes are built and tested by the same workflow.

Package and version changes

  • The build now produces only StyleCop.Analyzers; StyleCop.Analyzers.Unstable and the separate metadata package are no longer created.
  • The single package contains the analyzer and code-fix assemblies directly and has no package dependency indirection.
  • The old assembly revision override and metadata-pack recursion, which existed only to support the unstable package pair, were removed.
  • Release builds embed PDBs, so no legacy symbols package is produced.
  • The version bump to 1.3-beta is included.
  • Public release refs remain master and vX.Y servicing branches; the version policy explicitly matches the repository's vX.Y servicing-branch convention.

Validation and maintenance

  • Every executable block in release.yml uses PowerShell (pwsh).
  • Package validation remains immediately before publishing to prevent a mistagged commit, wrong package ID/version, private build, or unexpected extra package from reaching nuget.org. It also rejects private .g<sha> package versions.
  • Actions are pinned by full commit SHA.
  • dotnet build of the release package succeeds with zero warnings and zero errors.
  • The workflow YAML and all PowerShell run blocks were parser-validated.

One-time setup

Maintainers must configure:

  1. A nuget.org trusted publishing policy for DotNetAnalyzers/StyleCopAnalyzers, workflow release.yml, and environment release.
  2. A GitHub release environment with required reviewers.
  3. The NUGET_USER repository variable containing the nuget.org account that owns the policy.

Nerdbank.GitVersioning 3.x (adopted in e1d8e52) stopped putting the git
height in the fourth component when version.json already uses {height} in
the prerelease tag. Since then every build has had AssemblyVersion 1.2.0.0,
and because StyleCop.Analyzers.CodeFixes.csproj derives the
StyleCop.Analyzers.Unstable package version from AssemblyVersion, every
build produced StyleCop.Analyzers.Unstable 1.2.0 (instead of 1.2.0.N) and a
StyleCop.Analyzers 1.2.0-beta.N metadata package depending on it.

Set AssemblyVersion and AssemblyFileVersion back to major.minor.patch.height,
matching the 1.2.0-beta.556 release (1.2.0.556).
Releases have always been tagged with the bare version (1.2.0-beta.556), and
the nuspec release notes link to releases/<version>. nbgv tag defaults to
v{version}.
@AArnott
AArnott marked this pull request as ready for review October 7, 2026 21:39
Copilot AI balanced review requested due to automatic review settings October 11, 2026 19:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The CI trigger no longer builds master, blocking releases, and the package version contradicts the stated release scope.

2 open findings
What changed in this PR

Adds trusted NuGet publishing via GitHub OIDC and restores unique unstable package versions.

Changes:

  • Adds package collection, validation, publishing, and release attachment.
  • Restores Git height in assembly versions.
  • Updates versioning and CI branch configuration.
File Description
.github/​workflows/​release.yml Adds the trusted publishing workflow.
.github/​workflows/​build.yml Changes CI branch triggers.
StyleCop.Analyzers/​Directory.Build.targets Restores Git height in assembly versions.
StyleCop.Analyzers/​version.json Changes version and release-tag configuration.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/build.yml Resolved
Comment thread StyleCop.Analyzers/version.json Resolved
Copilot AI balanced review requested due to automatic review settings October 11, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The CI trigger misses supported major-version branches, and the changed branch policies contradict the documented release behavior.

3 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread .github/workflows/build.yml Resolved
Comment thread .github/workflows/build.yml Resolved
Comment thread StyleCop.Analyzers/version.json Resolved
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (65a0d26) to head (e123511).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4123   +/-   ##
=======================================
  Coverage   97.62%   97.62%           
=======================================
  Files        1283     1283           
  Lines      136089   136089           
  Branches     4369     4369           
=======================================
  Hits       132857   132857           
  Misses       2086     2086           
  Partials     1146     1146           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The release and packaging flow is coherent; only minor documentation corrections remain.

4 open findings

🧠 Review effort: Balanced

Comment thread .github/workflows/release.yml Resolved
Copilot AI balanced review requested due to automatic review settings October 11, 2026 20:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Publishing infrastructure and package restructuring require final human verification of CI, environment protections, and trusted-publisher configuration.

0 open findings

4 resolved since last review

🧠 Review effort: Balanced

@AArnott
AArnott merged commit fc13ffb into master Oct 12, 2026
30 checks passed
@AArnott
AArnott deleted the release-workflow branch October 12, 2026 17:30
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants