diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f6aea0..e69ea33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,10 +6,15 @@ name: Release # for the package version and kept for the Docker tag, matching the convention # previously used by hand (see NOTES.md). # -# Both the package and the image go to GitHub: GitHub Packages for NuGet and -# GHCR for the container. Neither needs a stored secret — the automatic -# GITHUB_TOKEN authenticates to both, given the packages: write permission the -# jobs below declare. +# The package goes to nuget.org via Trusted Publishing and the image to GHCR. +# Neither uses a long-lived credential: +# +# nuget.org The job requests a GitHub OIDC token, NuGet/login exchanges it for +# an API key valid for one hour, and that key does the push. This +# requires a Trusted Publishing policy on nuget.org naming this +# repository owner, this repository and the workflow file +# `release.yml` — see CONTRIBUTING.md. +# GHCR The automatic GITHUB_TOKEN authenticates, given packages: write. # # No repository secrets are required. @@ -47,14 +52,15 @@ jobs: echo "Publishing version $VERSION" nuget: - name: Publish package to GitHub Packages + name: Publish package to nuget.org needs: version runs-on: ubuntu-latest - # What lets GITHUB_TOKEN push to the registry; without it the push is a 403. + # id-token lets the job mint the OIDC token that Trusted Publishing trades + # for a temporary API key. Without it NuGet/login has nothing to exchange. permissions: contents: read - packages: write + id-token: write steps: - uses: actions/checkout@v4 @@ -84,16 +90,25 @@ jobs: name: nuget-package path: ./artifacts/* - # GitHub Packages rejects a re-push of a version that already exists, so - # --skip-duplicate keeps a re-run of the workflow from failing the job. - # - # Symbol packages (.snupkg) are not supported by GitHub Packages; symbols - # travel inside the .nupkg instead, via the SourceLink settings in the csproj. - - name: Push to GitHub Packages + # Kept immediately before the push on purpose: the key it returns lasts an + # hour, and each OIDC token buys exactly one key, so requesting it early + # only risks it expiring behind a slow build. + - name: Exchange an OIDC token for a nuget.org API key + uses: NuGet/login@v1 + id: login + with: + # The nuget.org profile name that owns the package. Public information, + # and the policy on nuget.org is what actually authorises the push. + user: aptacode + + # --skip-duplicate so re-running the workflow on an already-published + # version reports success instead of failing the job. The .snupkg sitting + # alongside is pushed automatically. + - name: Push to nuget.org run: > dotnet nuget push "./artifacts/*.nupkg" - --api-key ${{ secrets.GITHUB_TOKEN }} - --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} + --source https://api.nuget.org/v3/index.json --skip-duplicate docker: diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d18ded..b780f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,15 @@ separately here. ## [Unreleased] -Nothing yet. +### Changed + +- **Publishing returned to [nuget.org](https://www.nuget.org/packages/Fortitude)**, using + Trusted Publishing rather than a stored API key: the release workflow exchanges a GitHub + OIDC token for a key that lasts an hour. Installing is plain `dotnet add package Fortitude` + again, with no feed to add and no token to create. +- Symbol packages are published again as `.snupkg`, which nuget.org's symbol server accepts; + they had been embedded in the assembly because GitHub Packages has no symbol server. +- The container image stays on `ghcr.io/timmoth/fortitude`. ## [10.2.0] - 2026-11-20 @@ -73,6 +81,8 @@ Nothing yet. authenticating to the feed with a `read:packages` token even though the package is public; the README has the one-time setup. Symbols are embedded in the assembly rather than shipped as a `.snupkg`, which GitHub Packages does not support. + **Reverted in the next release** - publishing is back on nuget.org and needs no token. See + the Unreleased section above. - **The package targets `net10.0` only.** It previously multi-targeted `net8.0` and `net9.0` to reach the then-current LTS; both reached end of life in 2026. Breaking for consumers still on those runtimes. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f277e9f..693af81 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,9 +86,40 @@ cannot be merged. Dependabot opens grouped update pull requests weekly. Releases are automated. Pushing a tag of the form `v10.2.0` publishes the package and the multi-arch Docker image; the tag is the source of the version number. -Both artefacts go to GitHub: the package to GitHub Packages and the image to GHCR. Neither -needs a stored secret - the workflow's automatic `GITHUB_TOKEN` authenticates to both, given -the `packages: write` permission each job declares. **No repository secrets are required.** +The package goes to [nuget.org](https://www.nuget.org/packages/Fortitude) and the image to +GHCR. Neither uses a long-lived credential. + +### nuget.org, via Trusted Publishing + +The job mints a GitHub OIDC token, [`NuGet/login`](https://github.com/NuGet/login) exchanges +it for an API key valid for one hour, and that key does the push. There is no API key stored +anywhere. + +It depends on a policy that lives on nuget.org, not in this repository. Under +**nuget.org -> your username -> Trusted Publishing**, the policy must name: + +| Field | Value | +|---|---| +| Repository Owner | `Timmoth` | +| Repository | `Fortitude` | +| Workflow File | `release.yml` (the file name alone, no path) | +| Environment | leave empty - the workflow uses none | + +The policy has to be owned by the account that owns the package, which is `aptacode`, and its +scope must allow publishing new versions of `Fortitude`. + +The workflow names the publishing account (`aptacode`) inline. That is public information and +authorises nothing on its own - the policy on nuget.org is what does. **No repository secrets +are required.** + +> A new policy on a private repository starts *temporarily active* for 7 days and turns +> permanent on the first successful publish. If no publish happens in that window it goes +> inactive, and the 7 days can be restarted from the same page. + +### GHCR + +The automatic `GITHUB_TOKEN` authenticates, given the `packages: write` permission the job +declares. Nothing to configure. ## Building a client for another language diff --git a/Fortitude.Client/Fortitude.Client.csproj b/Fortitude.Client/Fortitude.Client.csproj index 5a043cc..5d19f14 100644 --- a/Fortitude.Client/Fortitude.Client.csproj +++ b/Fortitude.Client/Fortitude.Client.csproj @@ -27,12 +27,12 @@ Fortitude True - embedded + true + snupkg README.md icon.png Apache-2.0 diff --git a/README.md b/README.md index 6058aaf..984cd30 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,13 @@ _Fortitude spins up a local mock server so you can fluently configure HTTP route

CI - GitHub Packages + NuGet + NuGet downloads Container image License

-[Package](https://github.com/Timmoth/Fortitude/packages) - +[NuGet](https://www.nuget.org/packages/Fortitude) - [Container image](https://github.com/Timmoth/Fortitude/pkgs/container/fortitude) ## What is Fortitude? @@ -45,9 +46,8 @@ Fortitude keeps expected behavior close to the test code, increases code coverag ### Running the Fortitude Server via Docker -The image moves to GHCR with the next release and is not published there yet — see -[installation](./docs/installation.md) for what to use until it is, and for running the -server without Docker. +The image is public, so this needs no login — see +[installation](./docs/installation.md) for running the server without Docker. ```bash # Pull the latest Fortitude Server image: @@ -100,26 +100,14 @@ dotnet test ./Examples/Fortitude.Example.Tests **Make sure to add the NuGet package to your test project** -Fortitude is published to -[GitHub Packages](https://github.com/Timmoth?tab=packages&repo_name=Fortitude), not to -nuget.org, and GitHub Packages requires authentication even for public packages. Add the feed -once with a **classic** token carrying the `read:packages` scope: +[Fortitude on NuGet](https://www.nuget.org/packages/Fortitude) ```bash -dotnet nuget add source https://nuget.pkg.github.com/Timmoth/index.json \ - --name fortitude \ - --username \ - --password \ - --store-password-in-clear-text - +# Install via the .NET CLI: dotnet add package Fortitude ``` -In CI the repository's own `GITHUB_TOKEN` works as the password. - -**[installation](./docs/installation.md)** covers the committed `nuget.config` most teams -want instead, the click-through for Visual Studio, VS Code and Rider, and what each -authentication failure means. +[installation](./docs/installation.md) covers running the server, with or without Docker. ## Quick start diff --git a/docs/installation.md b/docs/installation.md index 475de89..c99f7b2 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,176 +1,44 @@ # Installation -Fortitude ships two things, both published from GitHub: +Fortitude ships two things: | Artefact | Where | Used for | |---|---|---| -| `Fortitude` NuGet package | [GitHub Packages](https://github.com/Timmoth?tab=packages&repo_name=Fortitude) | The library your tests reference. | -| `ghcr.io/timmoth/fortitude` image | [GHCR](https://github.com/Timmoth/Fortitude/pkgs/container/fortitude) | The standalone mock server. Awaiting its first release push — see [the server image](#the-server-image). | +| `Fortitude` NuGet package | [nuget.org](https://www.nuget.org/packages/Fortitude) | The library your tests reference. | +| `ghcr.io/timmoth/fortitude` image | [GHCR](https://github.com/Timmoth/Fortitude/pkgs/container/fortitude) | The standalone mock server. | -Neither is on nuget.org. The older `aptacode/fortitude-server` Docker Hub image still carries -the last hand-pushed build but will not be updated again. +Both are public and neither needs a credential to consume. --- ## The package -### Why a token is needed - -GitHub Packages requires authentication for NuGet **even when the package is public**. This is -a platform limitation, not a setting on this repository — there is no anonymous read. Every -developer and every CI job therefore needs a credential for the feed. - -Use a **classic** personal access token with the **`read:packages`** scope. GitHub's own -NuGet registry documentation calls for a classic token; fine-grained tokens are not reliably -supported here, so reach for classic first if a restore fails to authenticate. Create one at -[Settings → Developer settings → Personal access tokens → Tokens (classic)](https://github.com/settings/tokens). - -`read:packages` grants nothing beyond reading packages, though it does cover every package the -account can already see — so scope it to a machine account if that matters to you. - -### The recommended setup: a committed `nuget.config` - -Put this next to your solution file. It adds the feed and keeps the token out of the file: - -```xml - - - - - - - - - - - - - - - - - - - - - - - - - -``` - -`%GITHUB_USERNAME%` and `%GITHUB_TOKEN%` are expanded from the environment, so the file is safe -to commit. Each developer sets them once in their shell profile: - -```bash -export GITHUB_USERNAME=your-github-username -export GITHUB_TOKEN=ghp_your_classic_token_with_read_packages -``` - -On Windows (PowerShell): - -```powershell -setx GITHUB_USERNAME "your-github-username" -setx GITHUB_TOKEN "ghp_your_classic_token_with_read_packages" -``` - -> If the variables are missing, NuGet passes the literal `%GITHUB_TOKEN%` as the password and -> the restore fails with a 401. See [Troubleshooting](#troubleshooting). - -### Then install - ```bash dotnet add package Fortitude ``` ---- - -## Per-tool setup - -If you would rather not commit a `nuget.config`, each tool can hold the source itself. The -feed URL is the same everywhere: - -``` -https://nuget.pkg.github.com/Timmoth/index.json -``` - -and the credentials are always **your GitHub username** plus the **classic token** as the -password. - -### .NET CLI - -```bash -dotnet nuget add source https://nuget.pkg.github.com/Timmoth/index.json \ - --name fortitude \ - --username \ - --password \ - --store-password-in-clear-text -``` - -`--store-password-in-clear-text` is required on macOS and Linux, where NuGet has no encrypted -credential store. The value lands in your user-level `NuGet.Config` -(`~/.nuget/NuGet/NuGet.Config`), not in the repository. +That is the whole of it - nuget.org is configured out of the box, so there is no feed to add +and no token to create. The package targets `net10.0`. -Check it took: +> Versions `10.1.4` and `10.2.0` were published to GitHub Packages during a brief move off +> nuget.org. Publishing returned to nuget.org afterwards, so install from there; those two +> versions are the same code and are not worth chasing. -```bash -dotnet nuget list source -``` - -### Visual Studio (Windows) - -1. **Tools → NuGet Package Manager → Package Manager Settings**. -2. Select **Package Sources**, then **+**. -3. Name `fortitude`, Source `https://nuget.pkg.github.com/Timmoth/index.json`. **Update**, then **OK**. -4. The first restore shows a credentials prompt. Enter your GitHub username and paste the - classic token as the password. - -If the prompt never appears and the restore just fails, Windows has cached a bad credential: -open **Credential Manager → Windows Credentials** and delete any entry for -`nuget.pkg.github.com`, then restore again. - -### Visual Studio Code - -VS Code has no NuGet source UI. The C# Dev Kit and the `dotnet` CLI both read `nuget.config`, -so use either the committed file above or the CLI command, and VS Code picks it up. - -If VS Code was already open, run **Developer: Reload Window** afterwards so the language -server re-reads the configuration. - -### JetBrains Rider - -1. **Settings → Build, Execution, Deployment → NuGet**. -2. On the **Sources** tab, **+** under *Feeds*. -3. Name `fortitude`, URL `https://nuget.pkg.github.com/Timmoth/index.json`. -4. Fill **User** and **Password** in the same dialog with your GitHub username and the classic - token, then **Save**. -5. **Credentials** tab lets you correct a stored password later. - -### CI +### Behind a private feed -In GitHub Actions the repository's own token works and no secret is needed: - -```yaml -- run: dotnet nuget add source https://nuget.pkg.github.com/Timmoth/index.json - --name fortitude - --username ${{ github.actor }} - --password ${{ secrets.GITHUB_TOKEN }} - --store-password-in-clear-text -``` - -Anywhere else — Azure DevOps, TeamCity, GitLab — store a classic `read:packages` token as a -secret and pass it the same way, or set `GITHUB_USERNAME`/`GITHUB_TOKEN` and rely on the -committed `nuget.config`. +If your organisation mirrors nuget.org through Azure Artifacts, JFrog or similar, Fortitude +needs nothing special - it is an ordinary package. Point at your mirror the way you would for +any other dependency, and make sure `Fortitude` is allowed through if the mirror uses an +allowlist. --- ## The server image +The library can mock HTTP entirely in-process, in which case you need nothing below. The +server is for the cases where the system under test has to make a real network call - see +[mocking-apis](./mocking.md) for which mode fits. + ```bash # Pull docker pull ghcr.io/timmoth/fortitude:latest @@ -178,7 +46,7 @@ docker pull ghcr.io/timmoth/fortitude:latest # A single fixed port docker run -e PORT=5005 -p 5005:5005 ghcr.io/timmoth/fortitude:latest -# A port range — each connecting client reserves one, which is what keeps +# A port range - each connecting client reserves one, which is what keeps # parallel tests isolated from each other docker run -e PORTS=5000-5005 -p 5000-5005:5000-5005 ghcr.io/timmoth/fortitude:latest @@ -186,16 +54,9 @@ docker run -e PORTS=5000-5005 -p 5000-5005:5000-5005 ghcr.io/timmoth/fortitude:l docker run -e PORT=5005 -p 5005:5005 -v ./config:/app/config ghcr.io/timmoth/fortitude:latest ``` -Pulling a specific release is `ghcr.io/timmoth/fortitude:v10.1.4`. - -> **Not published yet.** The release workflow pushes this image, and no release has run since -> it was pointed at GHCR, so the tag does not exist today — `docker pull` returns a 403 until -> it does. In the meantime the last hand-pushed image is still on Docker Hub as -> `aptacode/fortitude-server:latest`, or build it yourself from a clone: -> `docker build -t fortitude .` -> -> The first push also creates the GHCR package **private**; it has to be made public once from -> its package settings page before an anonymous `docker pull` will work. +The image is public, so `docker pull` needs no login. Pulling a specific release is +`ghcr.io/timmoth/fortitude:v10.2.0`; `linux/amd64` and `linux/arm64` are both built, and the +container runs as a non-root user. Confirm it is up: @@ -205,8 +66,7 @@ curl http://localhost:5005/fortitude/health # -> server running Then open `http://localhost:5005/fortitude` for the live request monitor. -Every `PORT`, `PORTS` and `Settings:*` value is listed in -[configuration](./configuration.md). +Every `PORT`, `PORTS` and `Settings:*` value is listed in [configuration](./configuration.md). ### Without Docker @@ -224,22 +84,23 @@ starting the server from a test run rather than by hand. ## Troubleshooting -**`401 (Unauthorized)` on restore.** The token is missing, expired, or fine-grained rather -than classic. Confirm the variables are actually set in the shell doing the restore -(`echo $GITHUB_TOKEN`) — an IDE launched from the desktop does not always inherit a shell -profile, which is the usual reason it works in the terminal but not in the IDE. - -**`403 (Forbidden)`.** The token is valid but lacks `read:packages`. +**`Fortitude` is not found by `dotnet add package`.** Check that nuget.org is actually among +your sources - a `nuget.config` in the repository or a parent directory may have cleared it: -**`Unable to load the service index for source`.** Usually a typo in the URL: the path segment -is the **owner** (`Timmoth`), not the repository. - -**The restore asks the GitHub feed about unrelated packages.** Add the `packageSourceMapping` -block above; without it NuGet queries every source for every package. +```bash +dotnet nuget list source +``` -**Windows keeps reusing a bad credential.** Delete the `nuget.pkg.github.com` entry from -Credential Manager → Windows Credentials. +**An old version is resolved.** A `packageSourceMapping`, or a pinned version in +`Directory.Packages.props`, will hold it back. `dotnet list package --outdated` shows what is +available. -**`docker pull` returns 401.** The image should be public; if it is not yet, the owner needs to -change the package visibility once on its +**`docker pull` returns 401 or 404.** The image is public, so this should not happen. A new +GHCR package starts private by default, so if a future release publishes under a new name the +owner has to change its visibility once from its [package settings page](https://github.com/Timmoth/Fortitude/pkgs/container/fortitude). + +**The server starts but a test gets `503 No Fortitude client is connected`.** The request +arrived on a port no client had reserved. [architecture](./architecture.md) explains the +routing, and `Settings:Broadcast` in [configuration](./configuration.md) is the escape hatch +for when a single client should see everything.