From ef2c11d54804fc81526766ed0b1085fc34b63365 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:30:47 +0000 Subject: [PATCH] Cache NuGet on .csproj files (#372) * Cache NuGet on .csproj files * Fix restore keys * Formatting Markdown * Fix * Update PipelineWriterTests.cs --------- Co-authored-by: Tom Longhurst --- .github/workflows/dotnet-mac.yml | 4 ++-- .github/workflows/dotnet-windows.yml | 4 ++-- .github/workflows/dotnet.yml | 4 ++-- src/ModularPipelines.Build/ReleaseNotes.md | 2 +- .../PipelineWriters/GitHubPipelineFileWriter.cs | 4 ++-- src/ModularPipelines/Engine/PipelineFileWriter.cs | 4 ++-- test/ModularPipelines.UnitTests/PipelineWriterTests.cs | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dotnet-mac.yml b/.github/workflows/dotnet-mac.yml index 354e327604..7abc002bb3 100644 --- a/.github/workflows/dotnet-mac.yml +++ b/.github/workflows/dotnet-mac.yml @@ -31,9 +31,9 @@ jobs: uses: actions/cache@v3 with: path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} restore-keys: | - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - name: Build ModularPipelines.Analyzers.sln run: dotnet build ModularPipelines.Analyzers.sln -c Release - name: Build diff --git a/.github/workflows/dotnet-windows.yml b/.github/workflows/dotnet-windows.yml index 7bda5c3965..e26776cee5 100644 --- a/.github/workflows/dotnet-windows.yml +++ b/.github/workflows/dotnet-windows.yml @@ -33,9 +33,9 @@ jobs: uses: actions/cache@v3 with: path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} restore-keys: | - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - name: Build ModularPipelines.Analyzers.sln run: dotnet build ModularPipelines.Analyzers.sln -c Release - name: Build diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8ec37b08d7..b6ce3d2787 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -49,9 +49,9 @@ jobs: uses: actions/cache@v3 with: path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} restore-keys: | - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - name: Build ModularPipelines.Analyzers.sln run: dotnet build ModularPipelines.Analyzers.sln -c Release - name: Build diff --git a/src/ModularPipelines.Build/ReleaseNotes.md b/src/ModularPipelines.Build/ReleaseNotes.md index 7951defec1..19765bd501 100644 --- a/src/ModularPipelines.Build/ReleaseNotes.md +++ b/src/ModularPipelines.Build/ReleaseNotes.md @@ -1 +1 @@ -NULL +null diff --git a/src/ModularPipelines.GitHub/PipelineWriters/GitHubPipelineFileWriter.cs b/src/ModularPipelines.GitHub/PipelineWriters/GitHubPipelineFileWriter.cs index 3b5d56b793..9a0c80919f 100644 --- a/src/ModularPipelines.GitHub/PipelineWriters/GitHubPipelineFileWriter.cs +++ b/src/ModularPipelines.GitHub/PipelineWriters/GitHubPipelineFileWriter.cs @@ -54,8 +54,8 @@ public async Task Write(IPipelineHookContext pipelineHookContext) With = new { path= "~/.nuget/packages", - key= "${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}", - RestoreKeys = "${{ runner.os }}-nuget-", + key= "${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}", + RestoreKeys = "${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}", }, }, new diff --git a/src/ModularPipelines/Engine/PipelineFileWriter.cs b/src/ModularPipelines/Engine/PipelineFileWriter.cs index 43af9149cc..cc3d8d230c 100644 --- a/src/ModularPipelines/Engine/PipelineFileWriter.cs +++ b/src/ModularPipelines/Engine/PipelineFileWriter.cs @@ -18,11 +18,11 @@ IEnumerable writers _serviceProvider = serviceProvider; _writers = writers; } - + public async Task WritePipelineFiles() { await _writers - .ForEachAsync(x => + .ForEachAsync(x => x.Write(_serviceProvider.GetRequiredService()) ) .ProcessInParallel(); diff --git a/test/ModularPipelines.UnitTests/PipelineWriterTests.cs b/test/ModularPipelines.UnitTests/PipelineWriterTests.cs index f81aca605c..414ee9755a 100644 --- a/test/ModularPipelines.UnitTests/PipelineWriterTests.cs +++ b/test/ModularPipelines.UnitTests/PipelineWriterTests.cs @@ -132,8 +132,8 @@ await TestPipelineHostBuilder.Create() uses: actions/cache@v3 with: path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: ${{ runner.os }}-nuget- + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - name: Run Pipeline run: dotnet run -c Release --framework net7.0 {{{RandomFilePath}}} env: @@ -154,4 +154,4 @@ await TestPipelineHostBuilder.Create() EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }} """.Trim())); } -} \ No newline at end of file +}