Skip to content

Commit 5cb2fa9

Browse files
committed
Add GitHub Actions CI/CD pipeline (build-and-release)
Single workflow with 4 jobs: test (matrix: windows + ubuntu + macos, .NET 8 + 10 preview): - Builds and runs all tests on 3 OSes x 2 TFMs - Excludes 49 known-failing tests via TEST_FILTER env var: OpenBugs (38), NpAnyTest (8), np_all_axis_Test (4), Issue448 (2), 13 specific IndexingTest methods (fancy indexing/mask bugs) - Excludes BitmapWithAlphaTests on non-Windows (System.Drawing.Common is Windows-only on .NET 6+) - New test failures will correctly fail the pipeline and block merges - Filter is documented: remove exclusions as bugs are fixed build-nuget (on v* tags, after test): - Packs NumSharp and NumSharp.Bitmap into .nupkg with version from tag - Version extraction: v1.2.3-beta -> Version=1.2.3-beta, AssemblyVersion=1.2.3 - Embeds commit SHA via SourceRevisionId create-release (on v* tags, after build-nuget): - Creates GitHub Release with .nupkg + SHA256 checksum assets - Detects prerelease from version suffix (any hyphen) - Auto-generates changelog + structured install instructions body publish-nuget (on v* tags, after build-nuget, parallel to create-release): - Pushes all .nupkg to nuget.org via NUGETAPIKEY secret - Uses --skip-duplicate for idempotency Triggers: push/PR to master/main, v* tags, workflow_dispatch (manual) Tested on Nucs/NumSharp-dev — all 3 OS test jobs pass green.
1 parent 3b49398 commit 5cb2fa9

1 file changed

Lines changed: 242 additions & 0 deletions

File tree

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ "master", "main" ]
6+
tags: [ "v*" ]
7+
pull_request:
8+
branches: [ "master", "main" ]
9+
workflow_dispatch:
10+
11+
permissions: write-all
12+
13+
env:
14+
# Exclude known-failing test classes and specific test methods from CI.
15+
# These are pre-existing bugs tracked in OpenBugs.cs and related test files.
16+
# When a bug is fixed, remove its exclusion here so CI catches regressions.
17+
TEST_FILTER: >-
18+
FullyQualifiedName!~OpenBugs
19+
& FullyQualifiedName!~NpAnyTest
20+
& FullyQualifiedName!~np_all_axis_Test
21+
& FullyQualifiedName!~Issue448
22+
& Name!=Combining_IndexArrays_with_Slices
23+
& Name!=Combining_MaskArrays_with_Slices
24+
& Name!=IndexNDArray_Get_Case7
25+
& Name!=IndexNDArray_Get_Case7_Broadcasted
26+
& Name!=IndexNDArray_Get_Case8_Broadcasted
27+
& Name!=IndexNDArray_Set_Case2
28+
& Name!=IndexNDArray_Set_Case3
29+
& Name!=IndexNDArray_Set_Case4
30+
& Name!=IndexNDArray_Set_Case8_Broadcasted
31+
& Name!=IndexNDArray_sliced3dreshaped_indexed_by_1d_1d
32+
& Name!=Masking_2D_over_3D
33+
& Name!=MaskSetter
34+
& Name!=Compare
35+
36+
jobs:
37+
test:
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
include:
42+
- os: windows-latest
43+
extra_filter: ''
44+
- os: ubuntu-latest
45+
extra_filter: '& FullyQualifiedName!~BitmapWithAlphaTests'
46+
- os: macos-latest
47+
extra_filter: '& FullyQualifiedName!~BitmapWithAlphaTests'
48+
49+
runs-on: ${{ matrix.os }}
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Setup .NET
55+
uses: actions/setup-dotnet@v4
56+
with:
57+
dotnet-version: |
58+
8.0.x
59+
10.0.x
60+
dotnet-quality: 'preview'
61+
62+
- name: Build
63+
run: dotnet build test/NumSharp.UnitTest/NumSharp.UnitTest.csproj --configuration Release
64+
65+
- name: Test
66+
run: dotnet test test/NumSharp.UnitTest/NumSharp.UnitTest.csproj --configuration Release --no-build --verbosity normal --logger trx --filter "${{ env.TEST_FILTER }} ${{ matrix.extra_filter }}"
67+
68+
- name: Upload Test Results
69+
uses: actions/upload-artifact@v4
70+
if: always()
71+
with:
72+
name: test-results-${{ matrix.os }}
73+
path: ${{ github.workspace }}/**/TestResults/**/*.trx
74+
retention-days: 5
75+
76+
build-nuget:
77+
needs: test
78+
if: startsWith(github.ref, 'refs/tags/v')
79+
runs-on: ubuntu-latest
80+
81+
steps:
82+
- uses: actions/checkout@v4
83+
84+
- name: Setup .NET
85+
uses: actions/setup-dotnet@v4
86+
with:
87+
dotnet-version: |
88+
8.0.x
89+
10.0.x
90+
dotnet-quality: 'preview'
91+
92+
- name: Get version info
93+
id: version
94+
shell: bash
95+
run: |
96+
VERSION="${GITHUB_REF#refs/tags/v}"
97+
ASSEMBLY_VERSION="${VERSION%%-*}"
98+
COMMIT_SHA="${GITHUB_SHA:0:7}"
99+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
100+
echo "ASSEMBLY_VERSION=$ASSEMBLY_VERSION" >> $GITHUB_OUTPUT
101+
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_OUTPUT
102+
echo "Building version $VERSION (assembly: $ASSEMBLY_VERSION) +$COMMIT_SHA"
103+
104+
- name: Build
105+
run: |
106+
dotnet build src/NumSharp.Core/NumSharp.Core.csproj \
107+
--configuration Release \
108+
-p:Version=${{ steps.version.outputs.VERSION }} \
109+
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
110+
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
111+
-p:PackageVersion=${{ steps.version.outputs.VERSION }} \
112+
-p:SourceRevisionId=${{ steps.version.outputs.COMMIT_SHA }}
113+
114+
dotnet build src/NumSharp.Bitmap/NumSharp.Bitmap.csproj \
115+
--configuration Release \
116+
-p:Version=${{ steps.version.outputs.VERSION }} \
117+
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
118+
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
119+
-p:PackageVersion=${{ steps.version.outputs.VERSION }} \
120+
-p:SourceRevisionId=${{ steps.version.outputs.COMMIT_SHA }}
121+
122+
- name: Pack
123+
run: |
124+
mkdir -p artifacts/nuget
125+
126+
dotnet pack src/NumSharp.Core/NumSharp.Core.csproj \
127+
--configuration Release \
128+
--no-build \
129+
--output artifacts/nuget \
130+
-p:Version=${{ steps.version.outputs.VERSION }} \
131+
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
132+
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
133+
-p:PackageVersion=${{ steps.version.outputs.VERSION }}
134+
135+
dotnet pack src/NumSharp.Bitmap/NumSharp.Bitmap.csproj \
136+
--configuration Release \
137+
--no-build \
138+
--output artifacts/nuget \
139+
-p:Version=${{ steps.version.outputs.VERSION }} \
140+
-p:AssemblyVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
141+
-p:FileVersion=${{ steps.version.outputs.ASSEMBLY_VERSION }} \
142+
-p:PackageVersion=${{ steps.version.outputs.VERSION }}
143+
144+
echo "Packages built:"
145+
ls -la artifacts/nuget/
146+
147+
- name: Upload NuGet Packages
148+
uses: actions/upload-artifact@v4
149+
with:
150+
name: nuget-packages
151+
path: artifacts/nuget/*.nupkg
152+
retention-days: 5
153+
154+
create-release:
155+
needs: build-nuget
156+
if: startsWith(github.ref, 'refs/tags/v')
157+
runs-on: ubuntu-latest
158+
159+
steps:
160+
- uses: actions/checkout@v4
161+
with:
162+
fetch-depth: 0
163+
164+
- name: Extract version
165+
id: version
166+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
167+
168+
- name: Download NuGet Packages
169+
uses: actions/download-artifact@v4
170+
with:
171+
name: nuget-packages
172+
path: artifacts
173+
174+
- name: Generate checksums
175+
run: |
176+
cd artifacts
177+
for f in *.nupkg; do
178+
sha256sum "$f" | cut -d' ' -f1 > "${f}.sha256"
179+
echo "${f}: $(cat ${f}.sha256)"
180+
done
181+
182+
- name: Check if prerelease
183+
id: prerelease
184+
run: |
185+
if [[ "${{ steps.version.outputs.VERSION }}" == *"-"* ]]; then
186+
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
187+
else
188+
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
189+
fi
190+
191+
- name: Create Release
192+
uses: softprops/action-gh-release@v2
193+
with:
194+
files: |
195+
artifacts/*.nupkg
196+
artifacts/*.sha256
197+
draft: false
198+
prerelease: ${{ steps.prerelease.outputs.IS_PRERELEASE }}
199+
generate_release_notes: true
200+
body: |
201+
## NumSharp v${{ steps.version.outputs.VERSION }}
202+
203+
### Install via NuGet
204+
205+
```
206+
dotnet add package NumSharp --version ${{ steps.version.outputs.VERSION }}
207+
dotnet add package NumSharp.Bitmap --version ${{ steps.version.outputs.VERSION }}
208+
```
209+
210+
### Packages
211+
212+
| Package | NuGet |
213+
|---------|-------|
214+
| NumSharp | [![NuGet](https://img.shields.io/nuget/v/NumSharp.svg)](https://www.nuget.org/packages/NumSharp/${{ steps.version.outputs.VERSION }}) |
215+
| NumSharp.Bitmap | [![NuGet](https://img.shields.io/nuget/v/NumSharp.Bitmap.svg)](https://www.nuget.org/packages/NumSharp.Bitmap/${{ steps.version.outputs.VERSION }}) |
216+
217+
publish-nuget:
218+
needs: build-nuget
219+
if: startsWith(github.ref, 'refs/tags/v')
220+
runs-on: ubuntu-latest
221+
222+
steps:
223+
- name: Download NuGet Packages
224+
uses: actions/download-artifact@v4
225+
with:
226+
name: nuget-packages
227+
path: artifacts
228+
229+
- name: Setup .NET
230+
uses: actions/setup-dotnet@v4
231+
with:
232+
dotnet-version: '8.0.x'
233+
234+
- name: Push to NuGet
235+
run: |
236+
for package in artifacts/*.nupkg; do
237+
echo "Pushing $package..."
238+
dotnet nuget push "$package" \
239+
--api-key ${{ secrets.NUGETAPIKEY }} \
240+
--source https://api.nuget.org/v3/index.json \
241+
--skip-duplicate
242+
done

0 commit comments

Comments
 (0)