Update CI, .NET SDK, and .NET tools #45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
pull_request: | |
jobs: | |
# Enforces the consistency of code formatting using `.editorconfig` and the `dotnet-format` tool. | |
check-format: | |
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.404 | |
- name: Pin .NET Core SDK | |
run: dotnet new globaljson --sdk-version 8.0.404 | |
- name: Restore tools | |
run: dotnet tool restore | |
- name: Check format | |
run: dotnet tool run dotnet-format --check --folder T4.Build | |
build: | |
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.404 | |
- name: Pin .NET Core SDK | |
run: dotnet new globaljson --sdk-version 8.0.404 | |
- name: Create package | |
shell: pwsh | |
run: | | |
if ("${{ github.ref }}" -like "refs/tags/v*") { | |
$tag = "${{ github.ref }}".SubString(11) | |
$version = (Select-Xml -path T4.Build/T4.Build.csproj -XPath "/Project/PropertyGroup/VersionPrefix/text()").node.Value | |
if (-not ($tag -eq $version)) { | |
echo "There is a mismatch between the project version ($version) and the tag ($tag)" | |
exit 1 | |
} | |
} else { | |
$suffix = 'g' + $(git rev-parse --short HEAD) | |
$params = "--version-suffix", $suffix | |
} | |
dotnet pack --configuration=Release @params | |
- name: Upload NuGet package artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget-package | |
path: T4.Build/bin/Release/T4.Build.*.nupkg | |
publish: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [check-format, build] | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Download NuGet package artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: nuget-package | |
- name: Publish to NuGet | |
run: dotnet nuget push T4.Build.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json |