Skip to content

Commit d4be25f

Browse files
committed
try add make-nuget
1 parent 23f678b commit d4be25f

File tree

2 files changed

+178
-1
lines changed

2 files changed

+178
-1
lines changed

.github/workflows/make-nuget.yml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Make-NuGet
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths: [ '.github/workflows/make-nuget.yml' ]
7+
workflow_dispatch:
8+
9+
env:
10+
# NuGet 版本号只在这里改一次即可
11+
NUGET_VERSION: 4.11.0.20250507
12+
13+
jobs:
14+
make-nuget:
15+
name: Make NuGet (OpenCvSharp mini-runtime)
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
shell: bash
20+
21+
strategy:
22+
matrix:
23+
include:
24+
- { os: linux, arch: x64 }
25+
- { os: ubuntu.24.04, arch: x64 }
26+
- { os: linux, arch: arm64 }
27+
- { os: ubuntu.24.04, arch: arm64 }
28+
- { os: win, arch: x64 }
29+
- { os: win11, arch: x64 }
30+
- { os: win, arch: arm64 }
31+
- { os: osx, arch: x64 }
32+
- { os: osx, arch: arm64 }
33+
- { os: osx.15, arch: arm64 }
34+
35+
steps:
36+
# ------------------------------------------------------------
37+
# 1. 取上一次 opencvsharp.yml 成功运行的产物
38+
# ------------------------------------------------------------
39+
- name: Download OpenCvSharp Artifacts
40+
env:
41+
GH_TOKEN: ${{ github.token }}
42+
run: |
43+
echo "Fetching latest successful opencvsharp.yml run of branch ${{ github.ref_name }}"
44+
RUN_ID=$(gh run list -R ${{ github.repository }} \
45+
--workflow=opencvsharp.yml \
46+
--branch=${{ github.ref_name }} \
47+
--status=success --limit=1 \
48+
--json databaseId | jq -r '.[0].databaseId')
49+
echo "Run id = $RUN_ID"
50+
51+
ART_NAME="opencvsharp-${{ matrix.os }}-${{ matrix.arch }}"
52+
echo "Download artifact ${ART_NAME}"
53+
gh run download -R ${{ github.repository }} "$RUN_ID" --name "$ART_NAME" --dir opencvsharp
54+
55+
echo "::group::Artifact tree"
56+
ls -lR opencvsharp
57+
echo "::endgroup::"
58+
59+
# ------------------------------------------------------------
60+
# 2. 打包 NuGet
61+
# ------------------------------------------------------------
62+
- name: Build NuGet package
63+
env:
64+
VERSION: ${{ env.NUGET_VERSION }}
65+
run: |
66+
set -euo pipefail
67+
68+
# ---------- 基本元数据 ----------
69+
PKG_ID="Sdcb.OpenCvSharp4.mini.runtime.${{ matrix.os }}-${{ matrix.arch }}"
70+
AUTHOR="sdcb"
71+
LICENSE="Apache-2.0"
72+
GIT_URL="https://github.com/sdcb/opencvsharp-mini-runtime"
73+
TAGS="Sdcb OpenCV OpenCvSharp OpenCvSharp4"
74+
YEAR=$(date +%Y)
75+
76+
# ---------- 动态库名 & rid ----------
77+
case "${{ matrix.os }}" in
78+
win* )
79+
LIB_NAME="OpenCvSharpExtern.dll"
80+
RUNTIME_RID="win-${{ matrix.arch }}"
81+
;;
82+
osx* )
83+
LIB_NAME="libOpenCvSharpExtern.dylib"
84+
RUNTIME_RID="osx-${{ matrix.arch }}"
85+
;;
86+
* )
87+
LIB_NAME="libOpenCvSharpExtern.so"
88+
RUNTIME_RID="linux-${{ matrix.arch }}"
89+
;;
90+
esac
91+
92+
LIB_SRC="${{ github.workspace }}/opencvsharp/lib/${LIB_NAME}"
93+
if [[ ! -f "$LIB_SRC" ]]; then
94+
echo "::error file not found::${LIB_SRC}"
95+
exit 1
96+
fi
97+
98+
# ---------- 准备临时工作目录 ----------
99+
WORK="$RUNNER_TEMP/pkg"
100+
mkdir -p \
101+
"$WORK/runtimes/${RUNTIME_RID}/native" \
102+
"$WORK/lib/netstandard2.0" \
103+
"$WORK/lib/net45" \
104+
"$WORK/build/native"
105+
106+
cp "$LIB_SRC" "$WORK/runtimes/${RUNTIME_RID}/native/"
107+
touch "$WORK/lib/netstandard2.0/_._"
108+
cp "$WORK/lib/netstandard2.0/_._" "$WORK/lib/net45/_._"
109+
110+
# ---------- 生成 .props ----------
111+
NORMALIZED_NAME="$(echo "${PKG_ID}" | tr '.-' '_' )_Dlls"
112+
PROPS_FILE="$WORK/build/native/${PKG_ID}.props"
113+
cat > "$PROPS_FILE" <<EOF
114+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
115+
<PropertyGroup>
116+
<${NORMALIZED_NAME}>\\$(MSBuildThisFileDirectory)..\\..\\runtimes</${NORMALIZED_NAME}>
117+
</PropertyGroup>
118+
<ItemGroup Condition="\\$(TargetFrameworkVersion.StartsWith('v4')) Or \\$(TargetFramework.StartsWith('net4'))">
119+
<Content Include="\\$(${NORMALIZED_NAME})\\${RUNTIME_RID}\\native\\${LIB_NAME}">
120+
<Linkdll\\${RUNTIME_RID}\\${LIB_NAME}</Link>
121+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
122+
</Content>
123+
</ItemGroup>
124+
</Project>
125+
EOF
126+
127+
# ---------- 生成 .nuspec ----------
128+
NUSPEC_FILE="$WORK/${PKG_ID}.nuspec"
129+
cat > "$NUSPEC_FILE" <<EOF
130+
<?xml version="1.0" encoding="utf-8"?>
131+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
132+
<metadata>
133+
<id>${PKG_ID}</id>
134+
<version>${VERSION}</version>
135+
<title>${PKG_ID} native bindings</title>
136+
<authors>${AUTHOR}</authors>
137+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
138+
<description>Native binding for ${AUTHOR}.OpenCvSharp4.mini to work on ${RUNTIME_RID}.</description>
139+
<summary>Native binding for ${AUTHOR}.OpenCvSharp4.mini to work on ${RUNTIME_RID}.</summary>
140+
<copyright>Copyright ${YEAR}</copyright>
141+
<license type="expression">${LICENSE}</license>
142+
<projectUrl>${GIT_URL}</projectUrl>
143+
<repository type="git" url="${GIT_URL}.git" />
144+
<tags>${TAGS}</tags>
145+
<dependencies />
146+
<frameworkAssemblies />
147+
</metadata>
148+
<files>
149+
<!-- 两个 _._ 占位 -->
150+
<file src="lib\\netstandard2.0\\_._" target="lib\\netstandard2.0" />
151+
<file src="lib\\net45\\_._" target="lib\\net45" />
152+
<!-- 动态库 -->
153+
<file src="runtimes\\${RUNTIME_RID}\\native\\${LIB_NAME}" target="runtimes\\${RUNTIME_RID}\\native" />
154+
<!-- props -->
155+
<file src="build\\native\\${PKG_ID}.props" target="build\\native" />
156+
</files>
157+
</package>
158+
EOF
159+
160+
# ---------- 打包 ----------
161+
pushd "$WORK" >/dev/null
162+
dotnet nuget pack "${NUSPEC_FILE}" -OutputDirectory "${{ github.workspace }}/nupkgs"
163+
popd >/dev/null
164+
165+
echo "::group::生成的 nupkg"
166+
ls -l "${{ github.workspace }}/nupkgs"
167+
echo "::endgroup::"
168+
169+
# ------------------------------------------------------------
170+
# 3. 上传结果
171+
# ------------------------------------------------------------
172+
- name: Upload nupkg artifact
173+
uses: actions/upload-artifact@v4
174+
with:
175+
name: nuget-${{ matrix.os }}-${{ matrix.arch }}
176+
path: nupkgs/*.nupkg
177+
if-no-files-found: error

.github/workflows/test-opencvsharp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
ubuntu-test:
10+
test:
1111
name: Test OpenCvSharp
1212
runs-on: ${{ matrix.runs-on }}
1313
defaults:

0 commit comments

Comments
 (0)