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
20 changes: 6 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
# 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:

runs-on: ubuntu-24.04

permissions:
contents: write
contents: read

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
- 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
65 changes: 65 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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" }
18 changes: 0 additions & 18 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
Loading