From 1b9316400f752aaae6156267bd0861b3d1a2ca84 Mon Sep 17 00:00:00 2001 From: TekuSP Date: Wed, 29 Apr 2026 02:48:35 +0200 Subject: [PATCH 1/2] Optimize CI workflows with improved caching and artifact cleanup - Streamline Rust toolchain setup by using a combined setup and cache action. - Introduce a dedicated action for more efficient Linux apt dependency installation. - Implement explicit NuGet package caching to speed up restore operations. - Enforce `--locked-mode` for `dotnet restore` for consistent dependency resolution. - Add a new `clean-up` job to remove generated artifacts after each run, reducing storage. --- .github/workflows/build-sample.yml | 69 ++++++++++++++++---- .github/workflows/build.yml | 68 +++++++++++++++---- .github/workflows/publish.yml | 101 +++++++++++++++++++++-------- 3 files changed, 189 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build-sample.yml b/.github/workflows/build-sample.yml index 3906fc0..2962dab 100644 --- a/.github/workflows/build-sample.yml +++ b/.github/workflows/build-sample.yml @@ -50,20 +50,17 @@ jobs: with: submodules: recursive - - name: Setup Rust toolchain - run: rustup show - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 + - name: Setup Rust with Cache + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: | + cache-workspaces: | framework-system -> target - - name: Install Linux Framework dependencies + - name: Install with Cache Linux Framework dependencies (libudev-dev) + uses: daaku/gh-action-apt-install@v4 if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y libudev-dev + with: + packages: libudev-dev - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release @@ -154,8 +151,16 @@ jobs: name: framework-dotnet-native-linux-arm64 path: artifacts/linux-arm64 + - name: Cache and restore nugets + uses: actions/cache@v5 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-${{ runner.arch }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-nuget- + - name: Restore dependencies for library - run: dotnet restore -v normal -p:Version=${{ env.VERSION_PREFIX }}.${{ github.run_number }} -p:InformationalVersion=${{ env.VERSION_PREFIX }}.${{ github.run_number }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable + run: dotnet restore -v normal --locked-mode -p:Version=${{ env.VERSION_PREFIX }}.${{ github.run_number }} -p:InformationalVersion=${{ env.VERSION_PREFIX }}.${{ github.run_number }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable - name: Restore dependencies for sample app run: dotnet restore framework-dotnet-cli-test/framework-dotnet-cli-test.csproj -v normal -p:Version=${{ env.VERSION_PREFIX }}.${{ github.run_number }} -p:InformationalVersion=${{ env.VERSION_PREFIX }}.${{ github.run_number }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable @@ -213,3 +218,45 @@ jobs: if-no-files-found: error retention-days: 90 + clean-up: + name: Cleans up artifacts + needs: build + runs-on: ubuntu-latest + if: ${{ always() }} + + steps: + - name: Deletes generated bindings artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-bindings + failOnError: false + + - name: Deletes win-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-x64 + failOnError: false + + - name: Deletes win-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-arm64 + failOnError: false + + - name: Deletes linux-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-x64 + failOnError: false + + - name: Deletes linux-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-arm64 + failOnError: false + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d14989c..572a439 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,20 +51,17 @@ jobs: with: submodules: recursive - - name: Setup Rust toolchain - run: rustup show - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 + - name: Setup Rust with Cache + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: | + cache-workspaces: | framework-system -> target - - name: Install Linux Framework dependencies + - name: Install with Cache Linux Framework dependencies (libudev-dev) + uses: daaku/gh-action-apt-install@v4 if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y libudev-dev + with: + packages: libudev-dev - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release @@ -138,8 +135,16 @@ jobs: name: framework-dotnet-native-linux-arm64 path: artifacts/linux-arm64 + - name: Cache and restore nugets + uses: actions/cache@v5 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-${{ runner.arch }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-nuget- + - name: Restore dependencies - run: dotnet restore -v normal -p:Version=${{ env.VERSION_PREFIX }}.${{ github.run_number }} -p:InformationalVersion=${{ env.VERSION_PREFIX }}.${{ github.run_number }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable + run: dotnet restore -v normal --locked-mode -p:Version=${{ env.VERSION_PREFIX }}.${{ github.run_number }} -p:InformationalVersion=${{ env.VERSION_PREFIX }}.${{ github.run_number }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable - name: Build run: >- @@ -188,3 +193,44 @@ jobs: nuget sources Add -Name "GitHub" -Source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json -Username "${{ github.actor }}" -Password "${{ secrets.GITHUB_TOKEN }}" nuget push "${{ env.ARTIFACT_OUTPUT }}/**/*.nupkg" -Source "GitHub" + clean-up: + name: Cleans up artifacts + needs: pack + runs-on: ubuntu-latest + if: ${{ always() }} + + steps: + - name: Deletes generated bindings artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-bindings + failOnError: false + + - name: Deletes win-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-x64 + failOnError: false + + - name: Deletes win-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-arm64 + failOnError: false + + - name: Deletes linux-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-x64 + failOnError: false + + - name: Deletes linux-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-arm64 + failOnError: false diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c602e15..8159615 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -44,20 +44,17 @@ jobs: with: submodules: recursive - - name: Setup Rust toolchain - run: rustup show - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 + - name: Setup Rust with Cache + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: | + cache-workspaces: | framework-system -> target - - name: Install Linux Framework dependencies + - name: Install with Cache Linux Framework dependencies (libudev-dev) + uses: daaku/gh-action-apt-install@v4 if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y libudev-dev + with: + packages: libudev-dev - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release @@ -95,6 +92,23 @@ jobs: - uses: actions/checkout@v6 with: submodules: recursive + + - name: Set version environment variable + run: | + $tagName = "${{ github.event.release.tag_name }}" + # Check if the tag starts with 'v' and remove it + if ($tagName.StartsWith("v")) { + $version = $tagName.Substring(1) + } else { + $version = $tagName + } + + Write-Host "The original tag name was: $tagName" + Write-Host "The processed version is: $version" + + # Set the environment variable for subsequent steps in the same job + echo "version=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: pwsh # Explicitly use PowerShell Core (default on windows-latest for 'run') - name: Setup .NET uses: actions/setup-dotnet@v5 @@ -131,25 +145,16 @@ jobs: name: framework-dotnet-native-linux-arm64 path: artifacts/linux-arm64 - - name: Set version environment variable - run: | - $tagName = "${{ github.event.release.tag_name }}" - # Check if the tag starts with 'v' and remove it - if ($tagName.StartsWith("v")) { - $version = $tagName.Substring(1) - } else { - $version = $tagName - } - - Write-Host "The original tag name was: $tagName" - Write-Host "The processed version is: $version" - - # Set the environment variable for subsequent steps in the same job - echo "version=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - shell: pwsh # Explicitly use PowerShell Core (default on windows-latest for 'run') + - name: Cache and restore nugets + uses: actions/cache@v5 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-${{ runner.arch }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-nuget- - name: Restore dependencies - run: dotnet restore -v normal -p:Version=${{ env.version }} -p:InformationalVersion=${{ env.version }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable + run: dotnet restore -v normal --locked-mode -p:Version=${{ env.version }} -p:InformationalVersion=${{ env.version }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable - name: Build run: >- @@ -193,9 +198,51 @@ jobs: name: framework-dotnet-nuget path: ${{ env.ARTIFACT_OUTPUT }} if-no-files-found: error + - name: Push nugets to Github run: | nuget sources Add -Name "GitHub" -Source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json -Username "${{ github.actor }}" -Password "${{ secrets.GITHUB_TOKEN }}" nuget push "${{ env.ARTIFACT_OUTPUT }}/**/*.nupkg" -Source "GitHub" nuget push "${{ env.ARTIFACT_OUTPUT }}/**/*.nupkg" -Source https://api.nuget.org/v3/index.json -NoSymbols -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} + + clean-up: + name: Cleans up artifacts + needs: pack + runs-on: ubuntu-latest + if: ${{ always() }} + + steps: + - name: Deletes generated bindings artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-bindings + failOnError: false + + - name: Deletes win-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-x64 + failOnError: false + + - name: Deletes win-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-win-arm64 + failOnError: false + + - name: Deletes linux-x64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-x64 + failOnError: false + - name: Deletes linux-arm64 native artifact + uses: geekyeggo/delete-artifact@v6 + if: ${{ always() }} + with: + name: framework-dotnet-native-linux-arm64 + failOnError: false From 438223dbe0e8a36b5f128f3e9dd9869152f7ef93 Mon Sep 17 00:00:00 2001 From: TekuSP Date: Wed, 29 Apr 2026 02:55:03 +0200 Subject: [PATCH 2/2] Improve Linux apt package caching in CI workflows Replaces `daaku/gh-action-apt-install` with `awalsh128/cache-apt-pkgs-action` for more robust apt dependency caching. The added `version` input ensures architecture-specific cache keys, preventing collisions and improving cache hit rates across different runner environments. --- .github/workflows/build-sample.yml | 3 ++- .github/workflows/build.yml | 3 ++- .github/workflows/publish.yml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-sample.yml b/.github/workflows/build-sample.yml index 2962dab..4222183 100644 --- a/.github/workflows/build-sample.yml +++ b/.github/workflows/build-sample.yml @@ -57,10 +57,11 @@ jobs: framework-system -> target - name: Install with Cache Linux Framework dependencies (libudev-dev) - uses: daaku/gh-action-apt-install@v4 + uses: awalsh128/cache-apt-pkgs-action@v1 if: runner.os == 'Linux' with: packages: libudev-dev + version: ${{ runner.os }}-${{ runner.arch }} - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 572a439..178db59 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,10 +58,11 @@ jobs: framework-system -> target - name: Install with Cache Linux Framework dependencies (libudev-dev) - uses: daaku/gh-action-apt-install@v4 + uses: awalsh128/cache-apt-pkgs-action@v1 if: runner.os == 'Linux' with: packages: libudev-dev + version: ${{ runner.os }}-${{ runner.arch }} - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8159615..e15573b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -51,10 +51,11 @@ jobs: framework-system -> target - name: Install with Cache Linux Framework dependencies (libudev-dev) - uses: daaku/gh-action-apt-install@v4 + uses: awalsh128/cache-apt-pkgs-action@v1 if: runner.os == 'Linux' with: packages: libudev-dev + version: ${{ runner.os }}-${{ runner.arch }} - name: Build native library run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release