Skip to content

Commit 535a368

Browse files
authored
Merge pull request #534 from SciSharp/gh-actions
Add GitHub Actions CI/CD pipeline
2 parents 3b49398 + 665e868 commit 535a368

File tree

1 file changed

+253
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)