From 921174236484f6cd43086b9827e46522d6119564 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 7 May 2026 16:32:04 +1000 Subject: [PATCH] Build with GitHub Actions --- .github/workflows/ci.yml | 39 ++++++++++++ Build.ps1 | 80 ++++++++++++++----------- Directory.Build.props | 15 +++-- README.md | 2 +- seq-api.sln | 1 - src/Seq.Api/Seq.Api.csproj | 6 +- test/Seq.Api.Tests/Seq.Api.Tests.csproj | 4 +- 7 files changed, 98 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6376137 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +# If this file is renamed, the incrementing run attempt number will be reset. + +name: CI + +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 }} + +jobs: + build: + + runs-on: ubuntu-24.04 + + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Setup + 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 + 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/Build.ps1 b/Build.ps1 index 40b95c7..952dce0 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,69 +1,77 @@ -# This script originally (c) 2016 Serilog Contributors - license Apache 2.0 - -echo "build: Build started" +Write-Output "build: Build started" Push-Location $PSScriptRoot +Write-Output "build: Tool versions follow" + +dotnet --version +dotnet --list-sdks + if(Test-Path .\artifacts) { - echo "build: Cleaning .\artifacts" - Remove-Item .\artifacts -Force -Recurse + Write-Output "build: Cleaning ./artifacts" + Remove-Item ./artifacts -Force -Recurse } & dotnet restore --no-cache -if($LASTEXITCODE -ne 0) { exit 1 } -$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; -$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] +$dbp = [Xml] (Get-Content .\Directory.Build.props) +$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix + +Write-Output "build: Package version prefix is $versionPrefix" + +$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH]; +$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER]; +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"] -echo "build: Version suffix is $suffix" +Write-Output "build: Package version suffix is $suffix" -foreach ($src in ls src/*) { +foreach ($src in Get-ChildItem src/*) { Push-Location $src - echo "build: Packaging project in $src" + Write-Output "build: Packaging project in $src" if ($suffix) { - & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix + & dotnet pack -c Release -o ../../artifacts --version-suffix=$suffix } else { - & dotnet pack -c Release -o ..\..\artifacts + & dotnet pack -c Release -o ../../artifacts } - if($LASTEXITCODE -ne 0) { exit 1 } + if($LASTEXITCODE -ne 0) { throw "Packaging failed" } Pop-Location } -foreach ($test in ls test/*.Tests) { - Push-Location $test - - echo "build: Testing project in $test" - - & dotnet test -c Release - if($LASTEXITCODE -ne 0) { exit 3 } +Write-Output "build: Checking complete solution builds" +& dotnet build +if($LASTEXITCODE -ne 0) { throw "Solution build failed" } - Pop-Location -} -foreach ($test in ls test/*.Benchmarks) { +foreach ($test in Get-ChildItem test/*.Tests) { Push-Location $test - echo "build: Building performance test project in $test" + Write-Output "build: Testing project in $test" - & dotnet build -c Release - if($LASTEXITCODE -ne 0) { exit 2 } + & dotnet test -c Release + if($LASTEXITCODE -ne 0) { throw "Testing failed" } Pop-Location } -foreach ($sample in ls example/*) { - Push-Location $sample +Pop-Location - echo "build: Building sample project in $sample" +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" } + } - & dotnet build -c Release - if($LASTEXITCODE -ne 0) { exit 2 } + if (!($suffix)) { + Write-Output "build: Creating release for version $versionPrefix" - Pop-Location + iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" + } } - -Pop-Location diff --git a/Directory.Build.props b/Directory.Build.props index 2deb00d..c86a925 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,11 @@ - - - latest - - \ No newline at end of file + + latest + true + 2026.1.0 + true + true + snupkg + NETSDK1138 + + diff --git a/README.md b/README.md index acda6e5..60f29ae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Seq HTTP API Client [![Build status](https://ci.appveyor.com/api/projects/status/bhtx25hyqmmdqhvt?svg=true)](https://ci.appveyor.com/project/datalust/seq-api) [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Seq.Api.svg)](https://nuget.org/packages/seq.api) +# Seq HTTP API Client [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Seq.Api.svg)](https://nuget.org/packages/seq.api) This library includes: diff --git a/seq-api.sln b/seq-api.sln index 883a5c6..2005812 100644 --- a/seq-api.sln +++ b/seq-api.sln @@ -9,7 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{1C66 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{7DCED657-7E83-4E6F-AB14-5753E044304D}" ProjectSection(SolutionItems) = preProject - appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 LICENSE = LICENSE README.md = README.md diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 8672c2c..503e234 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -1,17 +1,13 @@ Client library for the Seq HTTP API. - 2026.1.0 Datalust;Contributors - netstandard2.0;net6.0;net8.0 - true - true + netstandard2.0;net6.0;net8.0;net10.0 seq Copyright © Datalust Pty Ltd and Contributors seq-api-icon.png https://github.com/datalust/seq-api Apache-2.0 - latest diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 6c00170..603b80b 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -1,8 +1,10 @@  - net462;net6.0 + net48 + $(TargetFrameworks);net10.0 true + false