-
Notifications
You must be signed in to change notification settings - Fork 203
288 lines (247 loc) · 9.55 KB
/
build-and-release.yml
File metadata and controls
288 lines (247 loc) · 9.55 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
name: Build and Release
on:
push:
branches: [ "master", "main" ]
tags: [ "v*" ]
pull_request:
branches: [ "master", "main" ]
workflow_dispatch:
permissions: write-all
env:
# Suppress noisy build warnings that clutter CI annotations.
# Uses %3B (URL-encoded semicolon) because MSBuild CLI treats raw ; and , as property separators.
# XML doc warnings (CS15xx, CS17xx): ~7,200 of ~8,700 total — malformed/missing doc comments
# CS8981: 'np' only contains lowercase chars — intentional for NumPy API compat
# NU5048: PackageIconUrl deprecated — cosmetic NuGet warning
DOTNET_NOWARN: CS1570%3BCS1571%3BCS1572%3BCS1573%3BCS1574%3BCS1587%3BCS1591%3BCS1711%3BCS1734%3BCS8981%3BNU5048
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
# Ubuntu has intermittent OOM issues - allow failure while investigating
continue-on-error: ${{ matrix.os == 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
dotnet-quality: 'preview'
- name: Build
run: dotnet build test/NumSharp.UnitTest/NumSharp.UnitTest.csproj --configuration Release -p:NoWarn=${{ env.DOTNET_NOWARN }}
# Test filtering:
# - OpenBugs: excluded (known-failing bug reproductions)
# - HighMemory: excluded (requires 8GB+ RAM, too much for CI runners)
# - WindowsOnly: excluded on non-Windows runners
- name: Test (net8.0)
shell: bash
timeout-minutes: 10
run: |
echo "Starting test run (net8.0)..."
echo "dotnet version: $(dotnet --version)"
echo "Available memory: $(free -h 2>/dev/null || echo 'N/A')"
FILTER="TestCategory!=OpenBugs&TestCategory!=HighMemory"
if [[ "$RUNNER_OS" != "Windows" ]]; then
FILTER="$FILTER&TestCategory!=WindowsOnly"
fi
dotnet test test/NumSharp.UnitTest/NumSharp.UnitTest.csproj \
--configuration Release --no-build --framework net8.0 \
--filter "$FILTER" --logger "trx"
- name: Test (net10.0)
shell: bash
timeout-minutes: 10
run: |
echo "Starting test run (net10.0)..."
echo "dotnet version: $(dotnet --version)"
echo "Available memory: $(free -h 2>/dev/null || echo 'N/A')"
FILTER="TestCategory!=OpenBugs&TestCategory!=HighMemory"
if [[ "$RUNNER_OS" != "Windows" ]]; then
FILTER="$FILTER&TestCategory!=WindowsOnly"
fi
dotnet test test/NumSharp.UnitTest/NumSharp.UnitTest.csproj \
--configuration Release --no-build --framework net10.0 \
--filter "$FILTER" --logger "trx"
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}
path: ${{ github.workspace }}/**/TestResults/**/*.trx
retention-days: 5
validate-release:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
outputs:
is_valid: ${{ steps.check.outputs.is_valid }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify tag is on master branch
id: check
run: |
TAG_COMMIT=$(git rev-parse HEAD)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if the tagged commit is reachable from origin/master
if git merge-base --is-ancestor "$TAG_COMMIT" origin/master; then
echo "Tag v$VERSION is on master branch"
echo "is_valid=true" >> $GITHUB_OUTPUT
else
echo "::error::Tag v$VERSION is NOT on master branch. Releases must be tagged from master."
echo "is_valid=false" >> $GITHUB_OUTPUT
exit 1
fi
build-nuget:
needs: validate-release
if: needs.validate-release.outputs.is_valid == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
dotnet-quality: 'preview'
- name: Get version info
id: version
shell: bash
run: |
VERSION="${GITHUB_REF#refs/tags/v}"
ASSEMBLY_VERSION="${VERSION%%-*}"
COMMIT_SHA="${GITHUB_SHA:0:7}"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "ASSEMBLY_VERSION=$ASSEMBLY_VERSION" >> $GITHUB_OUTPUT
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_OUTPUT
echo "Building version $VERSION (assembly: $ASSEMBLY_VERSION) +$COMMIT_SHA"
- name: Build
run: |
dotnet build src/NumSharp.Core/NumSharp.Core.csproj \
--configuration Release \
-p:NoWarn=${{ env.DOTNET_NOWARN }} \
-p:Version=${{ steps.version.outputs.VERSION }} \
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:PackageVersion=${{ steps.version.outputs.VERSION }} \
-p:SourceRevisionId=${{ steps.version.outputs.COMMIT_SHA }}
dotnet build src/NumSharp.Bitmap/NumSharp.Bitmap.csproj \
--configuration Release \
-p:NoWarn=${{ env.DOTNET_NOWARN }} \
-p:Version=${{ steps.version.outputs.VERSION }} \
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:PackageVersion=${{ steps.version.outputs.VERSION }} \
-p:SourceRevisionId=${{ steps.version.outputs.COMMIT_SHA }}
- name: Pack
run: |
mkdir -p artifacts/nuget
dotnet pack src/NumSharp.Core/NumSharp.Core.csproj \
--configuration Release \
--no-build \
--output artifacts/nuget \
-p:NoWarn=${{ env.DOTNET_NOWARN }} \
-p:Version=${{ steps.version.outputs.VERSION }} \
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:PackageVersion=${{ steps.version.outputs.VERSION }}
dotnet pack src/NumSharp.Bitmap/NumSharp.Bitmap.csproj \
--configuration Release \
--no-build \
--output artifacts/nuget \
-p:NoWarn=${{ env.DOTNET_NOWARN }} \
-p:Version=${{ steps.version.outputs.VERSION }} \
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
-p:PackageVersion=${{ steps.version.outputs.VERSION }}
echo "Packages built:"
ls -la artifacts/nuget/
- name: Upload NuGet Packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: artifacts/nuget/*.nupkg
retention-days: 5
create-release:
needs: [validate-release, build-nuget]
if: needs.validate-release.outputs.is_valid == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Download NuGet Packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: artifacts
- name: Generate checksums
run: |
cd artifacts
for f in *.nupkg; do
sha256sum "$f" | cut -d' ' -f1 > "${f}.sha256"
echo "${f}: $(cat ${f}.sha256)"
done
- name: Check if prerelease
id: prerelease
run: |
if [[ "${{ steps.version.outputs.VERSION }}" == *"-"* ]]; then
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/*.nupkg
artifacts/*.sha256
draft: false
prerelease: ${{ steps.prerelease.outputs.IS_PRERELEASE }}
generate_release_notes: true
body: |
## NumSharp v${{ steps.version.outputs.VERSION }}
### Install via NuGet
```
dotnet add package NumSharp --version ${{ steps.version.outputs.VERSION }}
dotnet add package NumSharp.Bitmap --version ${{ steps.version.outputs.VERSION }}
```
### Packages
| Package | NuGet |
|---------|-------|
| NumSharp | [](https://www.nuget.org/packages/NumSharp/${{ steps.version.outputs.VERSION }}) |
| NumSharp.Bitmap | [](https://www.nuget.org/packages/NumSharp.Bitmap/${{ steps.version.outputs.VERSION }}) |
publish-nuget:
needs: [validate-release, build-nuget]
if: needs.validate-release.outputs.is_valid == 'true'
runs-on: ubuntu-latest
steps:
- name: Download NuGet Packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Push to NuGet
run: |
for package in artifacts/*.nupkg; do
echo "Pushing $package..."
dotnet nuget push "$package" \
--api-key ${{ secrets.NUGETAPIKEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done