From 000b90bba028af290eee1e4ddba77b604482972c Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 13 Jul 2026 10:23:00 +1000 Subject: [PATCH 1/5] Delete appveyor.yml [skip ci] --- appveyor.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 3b6e646..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '{build}' -skip_tags: true -image: Visual Studio 2022 -build_script: -- ps: ./Build.ps1 -test: off -artifacts: -- path: artifacts/Seq.Api.*.nupkg -deploy: -- provider: NuGet - api_key: - secure: Jxi/gameJWSW1ncE+SpU6C51kENE7mSxtKYPnM5CrvTYnfpaf8Y5B7PsROv2Oglg - skip_symbols: true - on: - branch: /^(main|dev)$/ -- provider: GitHub - auth_token: - secure: hX+cZmW+9BCXy7vyH8myWsYdtQHyzzil9K5yvjJv7dK9XmyrGYYDj/DPzMqsXSjo - artifact: /Seq.Api.*\.nupkg/ - tag: v$(appveyor_build_version) - on: - branch: main From 5f9b5b5db8adc4c628220fb0a2fee9b71600efe5 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 13 Jul 2026 10:23:40 +1000 Subject: [PATCH 2/5] Dev version bump [skip ci] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index c86a925..3ad4194 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ latest true - 2026.1.0 + 2026.1.1 true true snupkg From 4ce465a46f14c5332eff3e14a6bc14a242725dfd Mon Sep 17 00:00:00 2001 From: liammclennan-ro Date: Wed, 18 Nov 2026 15:28:26 +1000 Subject: [PATCH 3/5] Change from seq/extern/Seq.Api --- example/SeqEnableAAD/Program.cs | 8 +- src/Seq.Api/Client/SeqApiClient.cs | 2 +- src/Seq.Api/Model/Events/EventEntity.cs | 6 ++ src/Seq.Api/Model/Indexes/IndexEntity.cs | 5 + .../AuthenticationSettingsTestResultPart.cs | 33 +++++++ src/Seq.Api/Model/Settings/SettingEntity.cs | 14 +++ src/Seq.Api/Model/Settings/SettingName.cs | 93 +++++++++++++++++-- .../Model/Settings/SettingsValuesPart.cs | 48 ++++++++++ src/Seq.Api/Model/Users/UserEntity.cs | 22 ++++- .../DiagnosticsResourceGroup.cs | 9 +- .../ResourceGroups/SettingsResourceGroup.cs | 28 ++++++ .../ResourceGroups/UsersResourceGroup.cs | 23 ++++- src/Seq.Api/Seq.Api.csproj | 4 +- test/Seq.Api.Tests/Seq.Api.Tests.csproj | 6 +- 14 files changed, 274 insertions(+), 27 deletions(-) create mode 100644 src/Seq.Api/Model/Settings/AuthenticationSettingsTestResultPart.cs create mode 100644 src/Seq.Api/Model/Settings/SettingsValuesPart.cs diff --git a/example/SeqEnableAAD/Program.cs b/example/SeqEnableAAD/Program.cs index 1e8523f..4d10d6a 100644 --- a/example/SeqEnableAAD/Program.cs +++ b/example/SeqEnableAAD/Program.cs @@ -54,10 +54,10 @@ static async Task Run(string server, string? username, string? tenantId, string? var user = await connection.Users.FindCurrentAsync(); var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider); - var cid = await connection.Settings.FindNamedAsync(SettingName.EntraIDClientId); - var ckey = await connection.Settings.FindNamedAsync(SettingName.EntraIDClientKey); - var aut = await connection.Settings.FindNamedAsync(SettingName.EntraIDAuthority); - var tid = await connection.Settings.FindNamedAsync(SettingName.EntraIDTenantId); + var cid = await connection.Settings.FindNamedAsync(SettingName.EntraIdClientId); + var ckey = await connection.Settings.FindNamedAsync(SettingName.EntraIdClientKey); + var aut = await connection.Settings.FindNamedAsync(SettingName.EntraIdAuthority); + var tid = await connection.Settings.FindNamedAsync(SettingName.EntraIdTenantId); user.Username = username; provider.Value = "Microsoft Entra ID"; diff --git a/src/Seq.Api/Client/SeqApiClient.cs b/src/Seq.Api/Client/SeqApiClient.cs index 14f2c70..ab4f659 100644 --- a/src/Seq.Api/Client/SeqApiClient.cs +++ b/src/Seq.Api/Client/SeqApiClient.cs @@ -41,7 +41,7 @@ public sealed class SeqApiClient : IDisposable // Future versions of Seq may not completely support vN-1 features, however // providing this as an Accept header will ensure what compatibility is available // can be utilized. - const string SeqApiVersionedMediaType = "application/vnd.datalust.seq.v14+json"; + const string SeqApiVersionedMediaType = "application/vnd.datalust.seq.v15+json"; const string ApiKeyHeaderName = "X-Seq-ApiKey"; const string CsrfTokenHeaderName = "X-Seq-CsrfToken"; diff --git a/src/Seq.Api/Model/Events/EventEntity.cs b/src/Seq.Api/Model/Events/EventEntity.cs index fbfa96b..3ee1cad 100644 --- a/src/Seq.Api/Model/Events/EventEntity.cs +++ b/src/Seq.Api/Model/Events/EventEntity.cs @@ -95,6 +95,12 @@ public class EventEntity : Entity /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public string SpanKind { get; set; } + + /// + /// If the event is a span, any links it carries. + /// + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public List SpanLinks { get; set; } /// /// A collection of properties describing the origin of the event, if any. These correspond to resource diff --git a/src/Seq.Api/Model/Indexes/IndexEntity.cs b/src/Seq.Api/Model/Indexes/IndexEntity.cs index 6b92295..7da1ee4 100644 --- a/src/Seq.Api/Model/Indexes/IndexEntity.cs +++ b/src/Seq.Api/Model/Indexes/IndexEntity.cs @@ -29,5 +29,10 @@ public class IndexEntity: Entity /// The storage used by this index. /// public ulong StorageBytes { get; set; } + + /// + /// If the last attempt at indexing failed to build this index. + /// + public bool IsIndexingFailing { get; set; } } } diff --git a/src/Seq.Api/Model/Settings/AuthenticationSettingsTestResultPart.cs b/src/Seq.Api/Model/Settings/AuthenticationSettingsTestResultPart.cs new file mode 100644 index 0000000..3273b58 --- /dev/null +++ b/src/Seq.Api/Model/Settings/AuthenticationSettingsTestResultPart.cs @@ -0,0 +1,33 @@ +// Copyright © Datalust and contributors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Seq.Api.Model.Settings +{ + /// + /// The outcome of testing proposed authentication settings. + /// + public class AuthenticationSettingsTestResultPart + { + /// + /// If true, the settings passed testing. Some aspects of the configuration can only be verified + /// by signing in, so passing does not guarantee that sign-in will work. + /// + public bool Passed { get; set; } + + /// + /// If the test failed, a human-readable description of the problem. + /// + public string Error { get; set; } + } +} diff --git a/src/Seq.Api/Model/Settings/SettingEntity.cs b/src/Seq.Api/Model/Settings/SettingEntity.cs index 11e4153..b399e61 100644 --- a/src/Seq.Api/Model/Settings/SettingEntity.cs +++ b/src/Seq.Api/Model/Settings/SettingEntity.cs @@ -31,5 +31,19 @@ public class SettingEntity : Entity /// The value of the setting. /// public object Value { get; set; } + + /// + /// Indicates that the setting has a value, even when the server redacts that value and + /// returns it as null (the case for passwords and similar secrets). Ignored when + /// saving values: null will always clear a setting, irrespective of the value sent + /// for this property. + /// + public bool HasValue { get; set; } + + /// + /// Indicates that the setting's value is overridden in the server's configuration, and can't be changed through + /// the API. Ignored when saving values. + /// + public bool IsReadOnly { get; set; } } } diff --git a/src/Seq.Api/Model/Settings/SettingName.cs b/src/Seq.Api/Model/Settings/SettingName.cs index 3fc11d4..920fb6c 100644 --- a/src/Seq.Api/Model/Settings/SettingName.cs +++ b/src/Seq.Api/Model/Settings/SettingName.cs @@ -58,29 +58,64 @@ public enum SettingName DataAgeWarningThresholdMilliseconds, /// - /// The Microsoft Entra ID authority. The default is login.windows.net; government cloud users may + /// The Microsoft Entra ID authority. The default is login.microsoftonline.com; government cloud users may /// require login.microsoftonline.us or similar. /// - // ReSharper disable once InconsistentNaming - EntraIDAuthority, + EntraIdAuthority, /// /// The Microsoft Entra ID client id. /// - // ReSharper disable once InconsistentNaming - EntraIDClientId, + EntraIdClientId, /// /// The Microsoft Entra ID client key. /// - // ReSharper disable once InconsistentNaming - EntraIDClientKey, + EntraIdClientKey, /// /// The Microsoft Entra ID tenant id. /// - // ReSharper disable once InconsistentNaming - EntraIDTenantId, + EntraIdTenantId, + + /// + /// The Microsoft Entra ID credential source type. By default (ClientSecret), a client key (client + /// secret) is expected in . Specify SignedAssertionFromManagedIdentity + /// and, optionally, a value for to authenticate using a + /// managed identity instead. If no is specified, the + /// system-assigned managed identity is used. Specify SignedAssertionFile to authenticate using + /// a signed assertion (for example, a Kubernetes projected service account token) read from the file named + /// by the AZURE_FEDERATED_TOKEN_FILE environment variable; the file is re-read on each sign-in so + /// that rotated tokens are picked up. Specify CertificateFile to authenticate using a client + /// certificate and private key from the Seq server's certificates folder. + /// Specify CertificateThumbprint or CertificateSubject to authenticate using a client + /// certificate identified by or + /// , respectively; these options are only supported on Windows. + /// + EntraIdCredentialType, + + /// + /// The client id of the user-assigned managed identity that the app registration's federated identity + /// credential trusts. Considered only when is + /// SignedAssertionFromManagedIdentity. + /// + EntraIdManagedIdentityClientId, + + /// + /// The SHA-1 thumbprint of a client certificate, with private key, in the LocalMachine or + /// CurrentUser Personal (My) Windows certificate store. Considered only when + /// is CertificateThumbprint. + /// + EntraIdClientCertificateThumbprint, + + /// + /// The subject common name, or full distinguished name, of a client certificate in the + /// LocalMachine or CurrentUser Personal (My) Windows certificate store. The newest + /// currently-valid matching certificate with a private key is used, so that rolled-over certificates are + /// picked up automatically. Considered only when is + /// CertificateSubject. + /// + EntraIdClientCertificateSubject, /// /// Server-local filesystem location where automatic backups are stored. @@ -131,6 +166,11 @@ public enum SettingName /// Seq will stop accepting new events. /// MinimumFreeStorageSpace, + + /// + /// The minimum length of passwords for local username/password authentication. + /// + MinimumPasswordLength, /// /// A dictionary of `(string, string)` pairs that will be used to initialize the @@ -192,11 +232,23 @@ public enum SettingName /// list. For example, openid, profile, email. /// OpenIdConnectScopes, + + /// + /// If using OpenID Connect, the URI that the provider will redirect to after the user signs out. + /// + OpenIdConnectEndSessionRedirectUri, /// /// If using OpenID Connect, overrides the URI of the provider's metadata endpoint. /// OpenIdConnectMetadataAddress, + + /// + /// The character classes that local username/password authentication passwords must include, as a string + /// containing any of a (lowercase letter), A (uppercase letter), 0 (digit), and + /// ! (punctuation). + /// + PasswordRequiredCharacterClasses, /// /// If true, ingestion requests incoming via HTTP must be authenticated using an API key or @@ -214,6 +266,22 @@ public enum SettingName /// RawPayloadMaximumContentLength, + /// + /// If true, the SCIM 2.0 user provisioning endpoints under /scim/v2 are enabled. Only + /// effective when is true. + /// + ScimEnabled, + + /// + /// The default duration, in seconds, that searches will cover. + /// + SearchDurationSeconds, + + /// + /// An expression that identifies the service associated with an event or span. + /// + ServiceNameExpression, + /// /// Tracks whether an admin user has dismissed the secret key backup warning. /// @@ -228,6 +296,11 @@ public enum SettingName /// /// A snippet of CSS that will be included in the front-end's user interface styles. /// - ThemeStyles + ThemeStyles, + + /// + /// If true, user avatars will be retrieved from Gravatar. + /// + UseGravatar } } diff --git a/src/Seq.Api/Model/Settings/SettingsValuesPart.cs b/src/Seq.Api/Model/Settings/SettingsValuesPart.cs new file mode 100644 index 0000000..60bd76e --- /dev/null +++ b/src/Seq.Api/Model/Settings/SettingsValuesPart.cs @@ -0,0 +1,48 @@ +// Copyright © Datalust and contributors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Seq.Api.Model.Settings +{ + /// + /// A set of related setting values, to be applied together, or (for authentication settings) tested without being + /// applied. + /// + public class SettingsValuesPart + { + /// + /// Setting values keyed by setting name (see ). Settings that are omitted keep their + /// current values. Settings that are read-only (see ) must be omitted. + /// + /// When testing authentication settings, the AuthenticationProvider setting determines which + /// provider is tested, and settings that don't apply to that provider are ignored. + public Dictionary Settings { get; set; } = new(); + + /// + /// When testing settings for providers that check credentials locally (Active Directory), the username to + /// sign in with. Must be null when applying settings. + /// + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public string Username { get; set; } + + /// + /// When testing settings for providers that check credentials locally (Active Directory), the password to + /// sign in with. Must be null when applying settings. + /// + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public string Password { get; set; } + } +} diff --git a/src/Seq.Api/Model/Users/UserEntity.cs b/src/Seq.Api/Model/Users/UserEntity.cs index a86346d..79b9891 100644 --- a/src/Seq.Api/Model/Users/UserEntity.cs +++ b/src/Seq.Api/Model/Users/UserEntity.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using Seq.Api.Model.Shared; +using Seq.Api.ResourceGroups; namespace Seq.Api.Model.Users { @@ -69,7 +70,17 @@ public class UserEntity : Entity /// The ids of one or more roles that grant permissions to the user. Note that /// the Seq UI currently only supports a single role when editing users. /// - public HashSet RoleIds { get; set; } = new HashSet(); + public HashSet RoleIds { get; set; } = new(); + + /// + /// If true, the user account is deactivated: the user cannot log in. The account and the entities + /// it owns are retained, and the account can be reactivated later. + /// + /// Read-only; changes to this property are ignored when the entity is updated. Use + /// the and actions + /// to change it. + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public bool IsDeactivated { get; set; } /// /// The authentication provider associated with the user account. This will normally be @@ -86,6 +97,15 @@ public class UserEntity : Entity /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string AuthenticationProviderUniqueIdentifier { get; set; } + + /// + /// The identifier assigned to the user by an external provisioning system (the SCIM externalId), + /// if the account is managed through SCIM. + /// + /// Read-only; the value is set by the provisioning system and changes to this property are + /// ignored when the entity is updated. + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public string ScimExternalId { get; set; } /// /// Because the api/users/login endpoint returns a in the JSON response diff --git a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs index 1d905f8..30ddf5f 100644 --- a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs @@ -80,11 +80,10 @@ public async Task GetMeasurementTimeseriesAsync(strin /// extended to account for the resolution of the underlying data. /// /// The (inclusive) start of the range to report on. If omitted, the results will report from the - /// earliest stored data. The range start must land on a five-minute boundary. - /// The (exclusive) end of the range to report on. If omitted, the results will report from the - /// earliest stored data. The range must be a multiple of the interval size, or a whole number of days if - /// no interval is specified. - /// The bucket size to use. Must be a multiple of 5 minutes. Defaults to 1440 (one day). + /// earliest stored data. The range start must land on a storage tick-aligned boundary. + /// The (exclusive) end of the range to report on. If omitted, the results will report to the + /// latest stored data. The range end must lane on a storage tick-aligned boundary. + /// The bucket size to use. Must be a multiple of storage ticks. Defaults to 1440 (one day). A safe minimum value is 300 (5 minutes). /// A allowing the operation to be canceled. /// Storage consumption information. public async Task GetStorageConsumptionAsync( diff --git a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs index 7d4b0e2..6be4907 100644 --- a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs @@ -84,5 +84,33 @@ public async Task UpdateInternalErrorReportingAsync(InternalErrorReportingSettin { await GroupPutAsync("InternalErrorReporting", internalErrorReporting, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Update a set of related settings together. Either all of the settings are updated, or none are. Changes to + /// authentication provider settings are applied by reloading the provider, which ends all existing sessions + /// when the provider is OpenID Connect-based. Requires the System permission. + /// + /// The settings to update. The and + /// properties must be null. + /// A allowing the operation to be canceled. + /// A task indicating completion. + public async Task ApplyAsync(SettingsValuesPart values, CancellationToken cancellationToken = default) + { + if (values == null) throw new ArgumentNullException(nameof(values)); + await GroupPostAsync("Apply", values, cancellationToken: cancellationToken).ConfigureAwait(false); + } + + /// + /// Check that proposed authentication settings can be used successfully, without applying them. Requires + /// the System permission. + /// + /// The proposed settings. + /// A allowing the operation to be canceled. + /// The outcome of the test. + public async Task TestAuthenticationSettingsAsync(SettingsValuesPart test, CancellationToken cancellationToken = default) + { + if (test == null) throw new ArgumentNullException(nameof(test)); + return await GroupPostAsync("AuthTest", test, cancellationToken: cancellationToken).ConfigureAwait(false); + } } } diff --git a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs index cf8496f..80e3649 100644 --- a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs @@ -187,8 +187,29 @@ public async Task LoginWindowsIntegratedAsync(CancellationToken canc /// A allowing the operation to be canceled. /// A task signalling completion. public async Task UnlinkAuthenticationProviderAsync(UserEntity entity, CancellationToken cancellationToken = default) - { + { await Client.PostAsync(entity, "UnlinkAuthenticationProvider", new {}, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// Deactivate . The user will be unable to log in, their existing + /// sessions are revoked, and API keys they own stop working. The account and everything it owns + /// is retained, and the account can be reactivated with . + /// The user to deactivate. + /// A allowing the operation to be canceled. + /// The updated user. + /// The account the requesting principal acts on behalf of cannot be deactivated. + public async Task DeactivateAsync(UserEntity entity, CancellationToken cancellationToken = default) + { + return await Client.PostAsync(entity, "Deactivate", new {}, cancellationToken: cancellationToken).ConfigureAwait(false); + } + + /// Reactivate a user deactivated with . + /// The user to reactivate. + /// A allowing the operation to be canceled. + /// The updated user. + public async Task ReactivateAsync(UserEntity entity, CancellationToken cancellationToken = default) + { + return await Client.PostAsync(entity, "Reactivate", new {}, cancellationToken: cancellationToken).ConfigureAwait(false); + } } } diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 157f69a..6a269d4 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -27,8 +27,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 603b80b..81bdf70 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -12,12 +12,12 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file From f4711dc2dbf77e53b519f6cb6486cb0f03dd2932 Mon Sep 17 00:00:00 2001 From: liammclennan-ro Date: Wed, 18 Nov 2026 16:03:42 +1000 Subject: [PATCH 4/5] Update version prefix. --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3ad4194..e8729ad 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ latest true - 2026.1.1 + 2026.2.0 true true snupkg From e9da1f780cd7dc79d9db653c3a9df2e2602c4136 Mon Sep 17 00:00:00 2001 From: Liam McLennan ro Date: Thu, 19 Nov 2026 09:49:08 +1000 Subject: [PATCH 5/5] Configure trusted publishing to nuget. --- .github/workflows/ci.yml | 20 ++++------- .github/workflows/publish.yml | 65 +++++++++++++++++++++++++++++++++++ Build.ps1 | 18 ---------- 3 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6376137..5527601 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,16 +1,13 @@ -# If this file is renamed, the incrementing run attempt number will be reset. - name: CI +# Pull requests only: pushes to `dev` and `main` are built, tested, and published by `publish.yml`. on: - push: - branches: [ "dev", "main" ] pull_request: branches: [ "dev", "main" ] - + env: - CI_BUILD_NUMBER_BASE: ${{ github.run_number }} - CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }} + CI_BUILD_NUMBER: ${{ github.run_number }} + CI_TARGET_BRANCH: ${{ github.head_ref }} jobs: build: @@ -18,7 +15,7 @@ jobs: runs-on: ubuntu-24.04 permissions: - contents: write + contents: read steps: - uses: actions/checkout@v4 @@ -26,14 +23,9 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 10.0.x - - name: Compute build number - run: | - echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+200))" >> $GITHUB_ENV - - name: Build and Publish + - name: Build env: DOTNET_CLI_TELEMETRY_OPTOUT: true - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} shell: pwsh run: | ./Build.ps1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e87bdff --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +# Publishes packages to NuGet.org using trusted publishing. The NuGet.org trusted publishing policy +# identifies this workflow by file name; if this file is renamed, the policy must be updated, and the +# incrementing run number used to version pre-release packages will be reset. + +name: Publish + +on: + push: + branches: [ "dev", "main" ] + +env: + CI_BUILD_NUMBER_BASE: ${{ github.run_number }} + CI_TARGET_BRANCH: ${{ github.ref_name }} + +jobs: + publish: + + runs-on: ubuntu-24.04 + + permissions: + # Required for NuGet.org trusted publishing. + id-token: write + # Required for creating GitHub releases. + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 10.0.x + - name: Compute build number + shell: bash + run: | + echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+500))" >> $GITHUB_ENV + - name: Build + env: + DOTNET_CLI_TELEMETRY_OPTOUT: true + shell: pwsh + run: | + ./Build.ps1 + - name: Log in to NuGet + uses: NuGet/login@v1 + id: login + with: + user: ${{ secrets.NUGET_USER }} + - name: Push to NuGet + shell: pwsh + run: | + $packages = @(Get-ChildItem ./artifacts/*.nupkg) + if ($packages.Count -eq 0) { throw "No packages found in ./artifacts" } + foreach ($nupkg in $packages) { + dotnet nuget push "$nupkg" --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json + if ($LASTEXITCODE -ne 0) { throw "Publishing failed" } + } + - name: Create GitHub release + # Builds from `main` are versioned without a pre-release suffix; see `Build.ps1`. + if: github.ref_name == 'main' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + run: | + $version = ([Xml] (Get-Content ./Directory.Build.props)).Project.PropertyGroup.VersionPrefix + gh release create "v$version" --title "v$version" --target "${{ github.sha }}" --generate-notes (Get-Item ./artifacts/*.nupkg, ./artifacts/*.snupkg) + if ($LASTEXITCODE -ne 0) { throw "Release creation failed" } diff --git a/Build.ps1 b/Build.ps1 index 952dce0..5c26f6c 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -57,21 +57,3 @@ foreach ($test in Get-ChildItem test/*.Tests) { } Pop-Location - -if ($env:NUGET_API_KEY) { - # GitHub Actions will only supply this to branch builds and not PRs. We publish - # builds from any branch this action targets (i.e. main and dev). - - Write-Output "build: Publishing NuGet packages" - - foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) { - & dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" - if($LASTEXITCODE -ne 0) { throw "Publishing failed" } - } - - if (!($suffix)) { - Write-Output "build: Creating release for version $versionPrefix" - - iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" - } -}