Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ name: Publish Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag of the GitHub release whose packages to publish, for example v3.2.3'
required: true
type: string

permissions:
contents: read
packages: write

jobs:
publish-nuget:
name: Publish to NuGet.org
runs-on: ubuntu-latest
permissions:
contents: read # Download the release assets
id-token: write # Request the GitHub OIDC token for NuGet Trusted Publishing

steps:
- name: Download release assets
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
run: |
gh release download "${{ github.event.release.tag_name }}" \
gh release download "$RELEASE_TAG" \
--pattern "*.nupkg" \
--dir ./artifacts \
--repo "${{ github.repository }}"
Expand Down Expand Up @@ -46,9 +55,19 @@ jobs:

echo "Found $PACKAGE_COUNT package(s) to publish"

# Trusted Publishing: exchanges the GitHub OIDC token for a NuGet API key that is valid for one hour.
# Requires a Trusted Publishing policy on nuget.org for this repository and release-publish.yml,
# and the NUGET_USER secret with the nuget.org profile name of the account that created the policy.
# https://learn.microsoft.com/nuget/nuget-org/trusted-publishing
- name: NuGet login (Trusted Publishing)
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ secrets.NUGET_USER }}

- name: Publish to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
run: |
for package in ./artifacts/*.nupkg; do
echo "Publishing $package to NuGet.org..."
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ dotnet test -c Release --no-build

Line and branch coverage must stay at or above 90 %. CI collects coverage on every build and fails below this threshold. Run the same check locally with `just test-cov`, or call `./eng/Assert-CodeCoverage.ps1` after a test run with `--coverage --coverage-output-format cobertura`.

## Release

Every push to `main` builds and tests the solution and creates a draft GitHub release with the NuGet packages. Publishing that release runs `.github/workflows/release-publish.yml`, which pushes the packages to NuGet.org with [Trusted Publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing). The workflow exchanges a GitHub OIDC token for a NuGet API key that is valid for one hour, so the repository stores no NuGet API key.

To publish the packages of an existing release again, run the workflow manually with the release tag:

```shell
gh workflow run release-publish.yml -f tag=v3.2.3
```

The workflow requires a Trusted Publishing policy on NuGet.org for the `MyCSharp` organization with the repository `mycsharp/HttpClientHints` and the workflow file `release-publish.yml`, and the repository secret `NUGET_USER` with the NuGet.org profile name of the member who created the policy.

## Benchmark

Reading header values from the view does not allocate, and a snapshot allocates only the record. A `Decoded*` property allocates the decoded string of a quoted value on every access. Run the benchmarks with `dotnet run -c Release --project perf/HttpClientHints.Benchmarks --framework net11.0 -- --filter '*' --iterationCount 15 --iterationTime 200 --launchCount 2 --warmupCount 6`.
Expand Down