-
Notifications
You must be signed in to change notification settings - Fork 9
163 lines (147 loc) · 5.06 KB
/
dotnet.yml
File metadata and controls
163 lines (147 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: .NET CI/CD
on:
push:
branches:
- main
pull_request:
release:
types:
- published
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
NUGET_XMLDOC_MODE: skip
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6.0.2
- name: Setup .NET SDK # detected from global.json
uses: actions/setup-dotnet@v5.1.0
- name: Add Problem Matcher for dotnet-format
run: echo "::add-matcher::.github/dotnet-format.json"
- name: Lint
run: dotnet format --verify-no-changes --verbosity detailed
validate:
name: Validate NuGet Lock Files
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6.0.2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5.1.0
with: &setup-dotnet-with
dotnet-version: ${{ vars.DOTNET_SDK_VERSIONS }}
cache: true
cache-dependency-path: '**/packages.lock.json'
- name: Restore with lock files
run: dotnet restore --locked-mode
test:
name: Debug Build & Test
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, ubuntu-24.04-arm, windows-11-arm, macos-15-intel]
framework: [net10.0, net9.0, net8.0]
include:
- os: windows-latest
framework: net48
steps:
- uses: actions/checkout@v6.0.2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5.1.0
with: *setup-dotnet-with
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --framework ${{ matrix.framework }} --no-build -- --coverage --coverage-output-format cobertura --coverage-output cobertura.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ runner.os }},${{ matrix.framework }}
disable_search: true
files: "./test/Sample.Test/bin/Debug/${{ matrix.framework }}/TestResults/cobertura.xml"
pack:
name: Release Build & Pack
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [lint, validate, test]
permissions:
contents: read
steps:
- uses: actions/checkout@v6.0.2
with:
fetch-depth: ${{ github.event_name == 'push' && 0 || 1 }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5.1.0
with: *setup-dotnet-with
- name: Restore
run: dotnet restore --locked-mode
- name: Set version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "release" ]; then
# Remove 'v' prefix from tag name (e.g., v1.0.0 -> 1.0.0)
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
echo "arg=Version=${VERSION}" >> $GITHUB_OUTPUT
else
# Use first 7 characters of SHA for nightly builds
SHA="${{ github.sha }}"
echo "arg=VersionSuffix=nightly-${SHA:0:7}" >> $GITHUB_OUTPUT
fi
- name: Build & Pack
run: dotnet pack --configuration Release --no-restore --output nupkgs -p:${{ steps.version.outputs.arg }}
- name: Upload Build Assets
uses: actions/upload-artifact@v7.0.0
with:
name: packages
path: nupkgs/
include-hidden-files: true
publish:
name: Publish
needs: [pack]
if: github.event_name != 'pull_request'
environment: ${{ github.event_name == 'release' && 'production' || 'nightly' }}
permissions:
packages: write
id-token: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5.1.0
- name: Download Build Assets
uses: actions/download-artifact@v8.0.0
with:
name: packages
path: nupkgs/
- name: Upload to GitHub Releases
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.release.tag_name }}
files: nupkgs/*.nupkg
- name: NuGet login (OIDC)
if: github.event_name == 'release'
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ vars.NUGET_USER_NAME }}
- name: Publish to ${{ github.event_name == 'release' && 'NuGet' || 'GitHub Packages' }}
run: dotnet nuget push "nupkgs/*.nupkg" --skip-duplicate --source ${SOURCE_URL} --api-key ${NUGET_API_KEY}
env:
SOURCE_URL: ${{ github.event_name == 'release' && 'https://api.nuget.org/v3/index.json' || format('https://nuget.pkg.github.com/{0}/index.json', github.repository_owner) }}
NUGET_API_KEY: ${{ github.event_name == 'release' && steps.nuget-login.outputs.NUGET_API_KEY || github.token }}