Skip to content

Commit 5e09f26

Browse files
Stop Update SDKs failing when there is nothing to update
setup-dotnet registers a post-job step that saves the NuGet cache, and that step fails the run if ~/.nuget/packages was never created. On the no-updates path every Restore/Build/Test step is skipped, nothing ever restores, and the cache save errors out - turning a perfectly healthy repo red every week. Move the setup step below the update check and gate it on has_updates, so it only runs when there is actually something to build. Caching is kept for the path that benefits from it, and the cache key is now computed after global.json has been rewritten, which is what the existing note there already wanted. [patch]
1 parent 139d5e6 commit 5e09f26

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

.github/workflows/update-sdks.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ jobs:
4242
submodules: recursive
4343
persist-credentials: true
4444

45-
- name: Setup .NET SDK ${{ env.DOTNET_VERSION }}
46-
uses: actions/setup-dotnet@v6
47-
with:
48-
dotnet-version: ${{ env.DOTNET_VERSION }}.x
49-
# Keyed on the files that actually pin versions. See the same note in dotnet.yml. This
50-
# workflow rewrites the SDK versions in global.json, so including it here also means the
51-
# verification build after an update does not restore against a stale key.
52-
cache: true
53-
cache-dependency-path: |
54-
**/*.csproj
55-
**/Directory.Packages.props
56-
**/global.json
57-
5845
- name: Configure Git
5946
run: |
6047
git config --global user.name "github-actions[bot]"
@@ -255,6 +242,27 @@ jobs:
255242
env:
256243
FORCE_UPDATE: ${{ inputs.force_update }}
257244

245+
# Deliberately placed after the update check rather than next to Checkout. setup-dotnet
246+
# registers a post-job step that saves the NuGet cache, and that step fails the run if
247+
# ~/.nuget/packages was never created. On the far more common no-updates path every step
248+
# below is skipped, nothing ever restores, and the cache save errors out on a green repo.
249+
# Gating the whole action on has_updates keeps the cache for the path that benefits from
250+
# it while leaving the no-op path clean. It also means the cache key is computed after
251+
# global.json has been rewritten, which is what the note below actually wants.
252+
- name: Setup .NET SDK ${{ env.DOTNET_VERSION }}
253+
if: steps.update_sdks.outputs.has_updates == 'true'
254+
uses: actions/setup-dotnet@v6
255+
with:
256+
dotnet-version: ${{ env.DOTNET_VERSION }}.x
257+
# Keyed on the files that actually pin versions. See the same note in dotnet.yml. This
258+
# workflow rewrites the SDK versions in global.json, so including it here also means the
259+
# verification build after an update does not restore against a stale key.
260+
cache: true
261+
cache-dependency-path: |
262+
**/*.csproj
263+
**/Directory.Packages.props
264+
**/global.json
265+
258266
- name: Restore Dependencies
259267
if: steps.update_sdks.outputs.has_updates == 'true'
260268
run: dotnet restore

0 commit comments

Comments
 (0)