From 8d806d5bfff144b3186e23ccb9a1d8039e2940f5 Mon Sep 17 00:00:00 2001 From: fristyxd Date: Sat, 5 Sep 2026 14:51:21 +0300 Subject: [PATCH] ci: fix tool restore, enable cache, pin actions, merge build+test, guard releases --- .config/dotnet-tools.json | 5 +- .gitea/workflows/ci.yml | 166 +++++++++----------------------------- global.json | 6 ++ 3 files changed, 45 insertions(+), 132 deletions(-) create mode 100644 global.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index e38494d..c70d178 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -6,7 +6,8 @@ "version": "0.0.1298", "commands": [ "vpk" - ] + ], + "rollForward": false } } -} +} \ No newline at end of file diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index cfad238..8f5359b 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,5 +1,4 @@ name: CI - on: push: branches: @@ -9,112 +8,42 @@ on: pull_request: branches: - main - workflow_dispatch: - +concurrency: + group: ${{ gitea.workflow }}-${{ gitea.ref }} + cancel-in-progress: ${{ !startsWith(gitea.ref, 'refs/tags/') }} +env: + NUGET_PACKAGES: ${{ runner.temp }}\.nuget\packages + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPT_OUT: true jobs: - build: + build-and-test: runs-on: windows-latest - env: - NUGET_PACKAGES: ${{ runner.temp }}/.nuget/packages - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPT_OUT: true + timeout-minutes: 20 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with: fetch-depth: 1 - - name: Setup .NET 8 SDK - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 with: - dotnet-version: 8.0.424 - env: - DOTNET_INSTALL_DIR: ${{ runner.temp }}\dotnet - + dotnet-version: 8.0.x - name: Cache NuGet packages - id: nuget-cache - uses: actions/cache@v3 - continue-on-error: true + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 with: - path: ${{ runner.temp }}/.nuget/packages - key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '.config/dotnet-tools.json') }} + path: ${{ runner.temp }}\.nuget\packages + key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', 'global.json', '.config/dotnet-tools.json') }} restore-keys: | nuget-${{ runner.os }}- - - - name: Cache dotnet tools - id: tools-cache - uses: actions/cache@v3 - continue-on-error: true - with: - path: ${{ runner.temp }}/.dotnet/tools - key: tools-${{ runner.os }}-${{ hashFiles('.config/dotnet-tools.json') }} - restore-keys: | - tools-${{ runner.os }}- - - - name: Cache status - if: always() - shell: powershell - run: | - Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}" - Write-Host "Tools cache hit: ${{ steps.tools-cache.outputs.cache-hit }}" - - name: Restore tools shell: powershell run: dotnet tool restore - - name: Restore shell: powershell 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@v3 - 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 dotnet tools - id: tools-cache - uses: actions/cache@v3 - continue-on-error: true - with: - path: ${{ runner.temp }}/.dotnet/tools - key: tools-${{ runner.os }}-${{ hashFiles('.config/dotnet-tools.json') }} - restore-keys: | - tools-${{ runner.os }}- - - - name: Cache status - if: always() shell: powershell - run: | - Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}" - Write-Host "Tools cache hit: ${{ steps.tools-cache.outputs.cache-hit }}" - + run: dotnet build src/RgbLedStripController/RgbLedStripController.csproj -c Release --no-restore - name: Run tests (if any test projects exist) shell: powershell run: | @@ -128,69 +57,46 @@ jobs: 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' + - build-and-test + if: startsWith(gitea.ref, 'refs/tags/v') runs-on: windows-latest - env: - NUGET_PACKAGES: ${{ runner.temp }}/.nuget/packages - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPT_OUT: true + timeout-minutes: 30 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with: fetch-depth: 1 - - name: Setup .NET 8 SDK - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 with: - dotnet-version: 8.0.424 - env: - DOTNET_INSTALL_DIR: ${{ runner.temp }}\dotnet - + dotnet-version: 8.0.x - name: Cache NuGet packages - id: nuget-cache - uses: actions/cache@v3 - continue-on-error: true + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 with: - path: ${{ runner.temp }}/.nuget/packages - key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '.config/dotnet-tools.json') }} + path: ${{ runner.temp }}\.nuget\packages + key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', 'global.json', '.config/dotnet-tools.json') }} restore-keys: | nuget-${{ runner.os }}- - - - name: Cache dotnet tools - id: tools-cache - uses: actions/cache@v3 - continue-on-error: true - with: - path: ${{ runner.temp }}/.dotnet/tools - key: tools-${{ runner.os }}-${{ hashFiles('.config/dotnet-tools.json') }} - restore-keys: | - tools-${{ runner.os }}- - - - name: Cache status - if: always() - shell: powershell - run: | - Write-Host "NuGet cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}" - Write-Host "Tools cache hit: ${{ steps.tools-cache.outputs.cache-hit }}" - - name: Restore tools shell: powershell run: dotnet tool restore - + - name: Assert tag matches csproj version + shell: powershell + run: | + $ErrorActionPreference = "Stop" + $ref = "${{ gitea.ref_name }}" + $projXml = [xml](Get-Content src/RgbLedStripController/RgbLedStripController.csproj) + $version = $projXml.Project.PropertyGroup | Where-Object { $_.Version } | Select-Object -First 1 -ExpandProperty Version + if ("v$version" -ne $ref) { throw "Tag $ref does not match csproj version $version" } - name: Package with Velopack (Setup.exe + Portable.zip) shell: powershell run: | $ErrorActionPreference = "Stop" & powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/release/package-velopack.ps1 - - name: Create Gitea Release with assets - uses: akkuman/gitea-release-action@v1 + uses: akkuman/gitea-release-action@5a83c90484ef4355121df5eb60558c8ce66e81ac with: token: ${{ secrets.API_TOKEN }} tag_name: ${{ gitea.ref_name }} @@ -203,8 +109,8 @@ jobs: name: ${{ gitea.ref_name }} body: | Release ${{ gitea.ref_name }} - + - RGBLedStripController-Setup-${{ gitea.ref_name }}-x64.exe (Windows Installer) - RGBLedStripController-Portable-${{ gitea.ref_name }}-x64.zip (Portable) draft: false - prerelease: false \ No newline at end of file + prerelease: false diff --git a/global.json b/global.json new file mode 100644 index 0000000..391ba3c --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "8.0.100", + "rollForward": "latestFeature" + } +}