- Add NUGET_PACKAGES env var at job level to pin package cache location - Change cache path from ~/.nuget/packages to runner.temp/.nuget/packages - Add id to cache steps and diagnostic 'Cache status' step to show hit/miss - Add DOTNET_NOLOGO and DOTNET_CLI_TELEMETRY_OPT_OUT for cleaner logs - Applied to build, test, and release jobs uniformly
161 lines
4.8 KiB
YAML
161 lines
4.8 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- "v*"
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: windows-latest
|
|
env:
|
|
NUGET_PACKAGES: ${{ runner.temp }}/.nuget/packages
|
|
DOTNET_NOLOGO: true
|
|
DOTNET_CLI_TELEMETRY_OPT_OUT: true
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Setup .NET 8 SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 8.0.424
|
|
env:
|
|
DOTNET_INSTALL_DIR: ${{ runner.temp }}\dotnet
|
|
|
|
- name: Cache NuGet packages
|
|
id: nuget-cache
|
|
uses: actions/cache@v4
|
|
continue-on-error: true
|
|
with:
|
|
path: ${{ runner.temp }}/.nuget/packages
|
|
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '.config/dotnet-tools.json') }}
|
|
restore-keys: |
|
|
nuget-${{ runner.os }}-
|
|
|
|
- name: Cache status
|
|
if: always()
|
|
shell: pwsh
|
|
run: |
|
|
Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}"
|
|
|
|
- name: Restore tools
|
|
run: dotnet tool restore
|
|
|
|
- name: Restore
|
|
run: dotnet restore src/RgbLedStripController/RgbLedStripController.csproj --configfile NuGet.Config
|
|
|
|
- name: Build (Release)
|
|
run: dotnet build src/RgbLedStripController/RgbLedStripController.csproj -c Release --no-restore
|
|
|
|
test:
|
|
runs-on: windows-latest
|
|
env:
|
|
NUGET_PACKAGES: ${{ runner.temp }}/.nuget/packages
|
|
DOTNET_NOLOGO: true
|
|
DOTNET_CLI_TELEMETRY_OPT_OUT: true
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Setup .NET 8 SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 8.0.424
|
|
env:
|
|
DOTNET_INSTALL_DIR: ${{ runner.temp }}\dotnet
|
|
|
|
- name: Cache NuGet packages
|
|
id: nuget-cache
|
|
uses: actions/cache@v4
|
|
continue-on-error: true
|
|
with:
|
|
path: ${{ runner.temp }}/.nuget/packages
|
|
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '.config/dotnet-tools.json') }}
|
|
restore-keys: |
|
|
nuget-${{ runner.os }}-
|
|
|
|
- name: Cache status
|
|
if: always()
|
|
shell: pwsh
|
|
run: |
|
|
Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}"
|
|
|
|
- name: Run tests (if any test projects exist)
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$tests = @(Get-ChildItem -Recurse -Filter "*Tests.csproj" | Where-Object { $_.FullName -notlike "*\obj\*" -and $_.FullName -notlike "*\bin\*" })
|
|
if ($tests.Count -eq 0) {
|
|
Write-Host "No test projects found yet; skipping dotnet test."
|
|
exit 0
|
|
}
|
|
foreach ($t in $tests) {
|
|
dotnet test $t.FullName -c Release
|
|
if ($LASTEXITCODE -ne 0) { throw "dotnet test failed for $($t.FullName)" }
|
|
}
|
|
|
|
release:
|
|
needs:
|
|
- build
|
|
- test
|
|
if: startsWith(gitea.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
|
runs-on: windows-latest
|
|
env:
|
|
NUGET_PACKAGES: ${{ runner.temp }}/.nuget/packages
|
|
DOTNET_NOLOGO: true
|
|
DOTNET_CLI_TELEMETRY_OPT_OUT: true
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Setup .NET 8 SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 8.0.424
|
|
env:
|
|
DOTNET_INSTALL_DIR: ${{ runner.temp }}\dotnet
|
|
|
|
- name: Cache NuGet packages
|
|
id: nuget-cache
|
|
uses: actions/cache@v4
|
|
continue-on-error: true
|
|
with:
|
|
path: ${{ runner.temp }}/.nuget/packages
|
|
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '.config/dotnet-tools.json') }}
|
|
restore-keys: |
|
|
nuget-${{ runner.os }}-
|
|
|
|
- name: Cache status
|
|
if: always()
|
|
shell: pwsh
|
|
run: |
|
|
Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}"
|
|
|
|
- name: Restore tools
|
|
run: dotnet tool restore
|
|
|
|
- name: Publish (Release, self-contained, single file)
|
|
run: dotnet publish src/RgbLedStripController/RgbLedStripController.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true --configfile NuGet.Config
|
|
|
|
- name: Upload release artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: rgb-led-strip-controller-${{ gitea.ref_name || 'manual' }}-win-x64
|
|
path: |
|
|
src/RgbLedStripController/bin/Release/net8.0-windows10.0.19041.0/win-x64/publish/RgbLedStripController.exe
|
|
src/RgbLedStripController/bin/Release/net8.0-windows10.0.19041.0/win-x64/publish/RgbLedStripController.pdb
|
|
if-no-files-found: error
|