Skip to content

feat(ci): publish to NuGet with trusted publishing - #33

Merged
Sreini merged 1 commit into
masterfrom
feat/nuget-trusted-publishing
Nov 4, 2026
Merged

Sreini merged 1 commit into
masterfrom
feat/nuget-trusted-publishing

Conversation

@Sreini

@Sreini Sreini commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Replaces the long-lived NUGET_API_KEY with an OIDC token exchanged for a key that lives one hour.

The 1.10.0 release failed on it (run 41844611368):

403 (The specified API key is invalid, has expired, or does not have permission
to access the specified package.)

The package built fine; only the push was rejected, and nothing warned beforehand. NuGet caps keys at 365 days, so this recurs on a timer. A short-lived key removes both the rotation and the silent-expiry failure mode.

Changes

  • permissions: id-token: write on the publish job, plus contents: read — naming permissions drops everything else, which is all the job needs.
  • NuGet/login@v1 exchanges the token; the push uses steps.nuget-login.outputs.NUGET_API_KEY.
  • secrets.NUGET_API_KEY is gone.

Ref control is unchanged: the job's own if: already restricts to tags, pushes, and this repository.

Needs doing alongside the merge

  1. Trusted publishing policy on nuget.org, owned by the tinify organization (the Tinify package is owned by tinify, not a personal account):

    field value
    Repository Owner tinify
    Repository tinify-net
    Workflow File ci-cd.yml
    Environment (blank)
    Scopes Push new versions of existing packages
    Glob Tinify
  2. NUGET_USER secret — the nuget.org profile name, not an email. The action documents this only as "your NuGet account username" and says nothing about organization-owned policies, so if the exchange 401s, that value is the first thing to try changing.

  3. Delete NUGET_API_KEY once a publish has succeeded, not before.

The repo is public, so the 7-day "pending full activation" window that private repos get does not apply.

Still outstanding in this repo

  • on: [push, pull_request] runs everything twice on every PR branch.
  • Preserve_Should_IncludeOtherOptions_IfSet flakes through static state in Helper; it has failed on both Windows and macOS on identical commits.
  • The Check if properly tagged step prints "Version in tinify/version.py" while reading Tinify.csproj.

🤖 Generated with Claude Code

Replaces the long-lived NUGET_API_KEY with an OIDC token exchanged for a
key that lives one hour. The 1.10.0 release failed because that key had
expired or been revoked:

    403 (The specified API key is invalid, has expired, or does not have
    permission to access the specified package.)

Nothing warned; the package built fine and the push was rejected. A
short-lived key removes both the rotation and the silent-expiry problem.

The publish job now requests id-token: write, exchanges the token via
NuGet/login, and pushes with the key that returns. Declaring permissions
drops the job to contents: read for everything else, which is all the
rest of it needs.

Which refs may publish is still the job's own `if:` -- tags only, pushes
only, this repository only. The policy leaves Environment blank to match.
@Sreini
Sreini merged commit adf8627 into master Nov 4, 2026
26 checks passed
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.

1 participant