Skip to content

Commit

Permalink
Fix building for .Net (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Dec 4, 2023
1 parent 73afa02 commit 3b90e85
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 150 deletions.
123 changes: 15 additions & 108 deletions .github/workflows/dot-net.yaml
Original file line number Diff line number Diff line change
@@ -1,130 +1,45 @@
name: dot-net
name: release-nuget-package

on:
push:
branches:
- dot-net
- fix-dot-net
tags:
- '*'

workflow_dispatch:

concurrency:
group: dot-net-${{ github.ref }}
group: release-nuget-package
cancel-in-progress: true

permissions:
contents: read

jobs:
build-libs:
name: dot-net for ${{ matrix.os }}
release-nuget-package:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v4
# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BEFORE_BUILD: "pip install -U cmake numpy"
CIBW_BUILD: "cp38-*64"
CIBW_SKIP: "cp27-* cp35-* cp36-* *-win32 pp* *-musllinux* *-manylinux_i686"
CIBW_BUILD_VERBOSITY: 3
CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH='/project/build/bdist.linux-x86_64/wheel/sherpa_onnx/lib'
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

- name: Display wheels
shell: bash
run: |
ls -lh ./wheelhouse/*.whl
unzip -l ./wheelhouse/*.whl
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-wheels
path: ./wheelhouse/*.whl

build-nuget-packages:
name: build-nuget-packages
runs-on: ubuntu-latest
needs: build-libs
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4

- name: Retrieve artifact from ubuntu-latest
uses: actions/download-artifact@v2
with:
name: ubuntu-latest-wheels
path: ./linux

- name: Retrieve artifact from macos-latest
uses: actions/download-artifact@v2
with:
name: macos-latest-wheels
path: ./macos

- name: Retrieve artifact from windows-latest
uses: actions/download-artifact@v2
with:
name: windows-latest-wheels
path: ./windows

- name: Display wheels
shell: bash
run: |
tree .
- name: Unzip Ubuntu wheels
shell: bash
run: |
cd linux
unzip ./*.whl
tree .
- name: Unzip macOS wheels
shell: bash
run: |
cd macos
unzip ./*.whl
tree .
- name: Unzip Windows wheels
shell: bash
run: |
cd windows
unzip ./*.whl
tree .
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
fetch-depth: 0

- name: Setup .NET 7.0
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: |
6.0.x
7.0.x
- name: Check dotnet
run: dotnet --info

- name: build nuget packages
- name: Build
shell: bash
run: |
cd scripts/dotnet
./run.sh
ls -lh packages
- uses: actions/upload-artifact@v3
name: upload nuget packages
with:
name: nuget-packages
path: scripts/dotnet/packages/*.nupkg
ls -lh /tmp/packages
- name: publish .Net packages to nuget.org
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
Expand All @@ -133,13 +48,5 @@ jobs:
API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
# API_KEY is valid until 2024.05.02
cd scripts/dotnet/packages
cd /tmp/packages
dotnet nuget push ./org.k2fsa.sherpa.onnx.*.nupkg --skip-duplicate --api-key $API_KEY --source https://api.nuget.org/v3/index.json
- name: Release nuget packages
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: scripts/dotnet/packages/*.nupkg
57 changes: 57 additions & 0 deletions .github/workflows/test-dot-net-nuget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: test-dot-net-nuget

on:
workflow_dispatch:

schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"

concurrency:
group: test-dot-net-nuget
cancel-in-progress: true

permissions:
contents: read

jobs:
test-dot-net-nuget:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Check dotnet
run: dotnet --info

- name: Decode a file
shell: bash
run: |
cd dotnet-examples/
cd online-decode-files
./run-transducer.sh
./run-paraformer.sh
cd ../offline-decode-files
./run-nemo-ctc.sh
./run-paraformer.sh
./run-zipformer.sh
./run-whisper.sh
./run-tdnn-yesno.sh
122 changes: 100 additions & 22 deletions .github/workflows/test-dot-net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,13 @@ on:
push:
branches:
- master
paths:
- '.github/workflows/test-dot-net'
- 'dotnet-examples/**'

pull_request:
branches:
- master
paths:
- '.github/workflows/test-dot-net'
- 'dotnet-examples/**'

workflow_dispatch:

schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"

concurrency:
group: test-dot-net
cancel-in-progress: true
Expand All @@ -34,31 +19,124 @@ permissions:
contents: read

jobs:
test-dot-net:
build-libs:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8"]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.os }}-release-shared

- name: Build sherpa-onnx
shell: bash
run: |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target install --config Release
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: ./build/install/lib/

test-dot-net:
runs-on: ${{ matrix.os }}
needs: [build-libs]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.8"]

steps:
- uses: actions/checkout@v4
with:
dotnet-version: 3.1.x
fetch-depth: 0

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
dotnet-version: 6.0.x
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip Jinja2
- name: Retrieve artifact from ubuntu-latest
uses: actions/download-artifact@v2
with:
name: ubuntu-latest
path: /tmp/linux

- name: Retrieve artifact from macos-latest
uses: actions/download-artifact@v2
with:
name: macos-latest
path: /tmp/macos

- name: Retrieve artifact from windows-latest
uses: actions/download-artifact@v2
with:
name: windows-latest
path: /tmp/windows

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Check dotnet
run: dotnet --info

- name: Display files
shell: bash
run: |
echo "----------/tmp/----------"
ls -lh /tmp/
echo "----------/tmp/linux----------"
ls -lh /tmp/linux
echo "----------/tmp/macos----------"
ls -lh /tmp/macos
echo "----------/tmp/windows----------"
ls -lh /tmp/windows
- name: Build
shell: bash
run: |
cd scripts/dotnet
./run.sh
- name: Copy files
shell: bash
run: |
cp -v scripts/dotnet/examples/offline-decode-files.csproj dotnet-examples/offline-decode-files/
cp -v scripts/dotnet/examples/online-decode-files.csproj dotnet-examples/online-decode-files/
cp -v scripts/dotnet/examples/speech-recognition-from-microphone.csproj dotnet-examples/speech-recognition-from-microphone/
ls -lh /tmp
- name: Decode a file
shell: bash
run: |
Expand Down
3 changes: 3 additions & 0 deletions scripts/dotnet/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Introduction

Files in this directory are used exclusively by CI.
Loading

0 comments on commit 3b90e85

Please sign in to comment.