Skip to content

Commit 49acef2

Browse files
Enhance .NET setup action with build/restore and update all workflows to use it
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent b098362 commit 49acef2

4 files changed

Lines changed: 21 additions & 54 deletions

File tree

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
name: 'Setup .NET Environment'
2-
description: 'Set up .NET SDK and configure dependency caching for faster builds'
2+
description: 'Set up .NET SDK, configure dependency caching, restore, and optionally build'
33
inputs:
4-
dotnet-version:
5-
description: 'Specific .NET version(s) to install'
4+
build:
5+
description: 'Whether to run dotnet build after restore'
66
required: false
7-
default: ''
8-
use-global-json:
9-
description: 'Use global.json file for .NET version'
10-
required: false
11-
default: 'true'
7+
default: 'false'
128
runs:
139
using: 'composite'
1410
steps:
1511
- name: Setup dotnet SDK
1612
uses: actions/setup-dotnet@v5
1713
with:
18-
dotnet-version: ${{ inputs.dotnet-version || '' }}
19-
global-json-file: ${{ inputs.use-global-json == 'true' && 'global.json' || '' }}
14+
global-json-file: global.json
2015

2116
- name: Set up dependency caching for faster builds
2217
uses: actions/cache@v4
@@ -28,4 +23,13 @@ runs:
2823
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
2924
restore-keys: |
3025
${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
31-
${{ runner.os }}-nuget-
26+
${{ runner.os }}-nuget-
27+
28+
- name: Restore dependencies
29+
shell: bash
30+
run: dotnet restore
31+
32+
- name: Build
33+
if: ${{ inputs.build == 'true' }}
34+
shell: bash
35+
run: dotnet build --no-restore

.github/workflows/Code-Analysis.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,8 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v5
17-
- name: Setup dotnet SDK
18-
uses: actions/setup-dotnet@v5
19-
with:
20-
global-json-file: global.json
21-
- name: Set up dependency caching for faster builds
22-
uses: actions/cache@v4
23-
id: nuget-cache
24-
with:
25-
path: |
26-
~/.nuget/packages
27-
${{ github.workspace }}/**/obj/project.assets.json
28-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
29-
restore-keys: |
30-
${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
31-
${{ runner.os }}-nuget-
32-
# Run NuGet restore for the solution at repo root
33-
- name: Run NuGet restore
34-
run: dotnet restore
17+
- name: Setup .NET environment
18+
uses: ./.github/actions/setup-dotnet
3519

3620
# Run code analysis for the solution at repo root
3721
- name: Run .NET Code Analysis

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,10 @@ jobs:
3030
os: [ubuntu-latest, windows-latest, macOS-latest]
3131
steps:
3232
- uses: actions/checkout@v5
33-
- name: Setup dotnet SDK
34-
uses: actions/setup-dotnet@v5
33+
- name: Setup .NET environment
34+
uses: ./.github/actions/setup-dotnet
3535
with:
36-
dotnet-version: |
37-
6.0.x
38-
7.0.x
39-
8.0.x
40-
- name: Set up dependency caching for faster builds
41-
uses: actions/cache@v4
42-
id: nuget-cache
43-
with:
44-
path: |
45-
~/.nuget/packages
46-
${{ github.workspace }}/**/obj/project.assets.json
47-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
48-
restore-keys: |
49-
${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
50-
${{ runner.os }}-nuget-
51-
- name: Restore dependencies
52-
run: dotnet restore
53-
- name: Build
54-
run: dotnet build --no-restore
36+
build: 'true'
5537
- name: Test
5638
run: dotnet test --no-build --no-restore --verbosity normal --logger trx --results-directory ${{ runner.temp }}
5739

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ jobs:
2222
uses: actions/checkout@v5
2323

2424
- name: Setup .NET environment
25-
uses: ./.github/actions/setup-dotnet
26-
27-
- name: Restore dependencies
28-
run: dotnet restore
25+
uses: ./.github/actions/setup-dotnet

0 commit comments

Comments
 (0)