Add go-api-examples (#219)

This commit is contained in:
Fangjun Kuang
2023-07-21 17:56:09 +08:00
committed by GitHub
parent 6125d9e063
commit e63d205b3d
28 changed files with 1624 additions and 14 deletions

239
.github/workflows/go.yaml vendored Normal file
View File

@@ -0,0 +1,239 @@
name: test-go
on:
push:
branches:
- master
tags:
- '*'
pull_request:
branches:
- master
workflow_dispatch:
concurrency:
group: go-${{ github.ref }}
cancel-in-progress: true
jobs:
go:
name: go ${{ matrix.os }} ${{matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: amd64
- os: macos-latest
arch: amd64
- os: windows-latest
arch: x64
- os: windows-latest
arch: x86 # use 386 for GOARCH
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '>=1.20'
- name: Display go version
shell: bash
run: |
go version
go env GOPATH
go env GOARCH
- name: Set up MinGW
if: matrix.os == 'windows-latest'
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ matrix.arch }}
- name: Show gcc
if: matrix.os == 'windows-latest'
run: |
gcc --version
- name: Test non-streaming decoding files (Linux/macOS)
if: matrix.os != 'windows-latest'
shell: bash
run: |
cd go-api-examples/non-streaming-decode-files
ls -lh
go mod tidy
cat go.mod
go build -x
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-zipformer-en-2023-06-26
./run-transducer.sh
rm -rf sherpa-onnx-zipformer-en-2023-06-26
echo "Test paraformer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28
./run-paraformer.sh
rm -rf sherpa-onnx-paraformer-zh-2023-03-28
echo "Test NeMo CTC"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-nemo-ctc-en-conformer-medium
./run-nemo-ctc.sh
rm -rf sherpa-onnx-nemo-ctc-en-conformer-medium
- name: Test non-streaming decoding files (Win64)
if: matrix.os == 'windows-latest' && matrix.arch == 'x64'
shell: bash
run: |
cd go-api-examples/non-streaming-decode-files
ls -lh
go mod tidy
cat go.mod
go build
ls -lh
echo $PWD
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/*
cp -v /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/sherpa-onnx-go-windows*/lib/x86_64-pc-windows-gnu/*.dll .
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-zipformer-en-2023-06-26
./run-transducer.sh
rm -rf sherpa-onnx-zipformer-en-2023-06-26
echo "Test paraformer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28
./run-paraformer.sh
rm -rf sherpa-onnx-paraformer-zh-2023-03-28
echo "Test NeMo CTC"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-nemo-ctc-en-conformer-medium
./run-nemo-ctc.sh
rm -rf sherpa-onnx-nemo-ctc-en-conformer-medium
- name: Test non-streaming decoding files (Win32)
if: matrix.os == 'windows-latest' && matrix.arch == 'x86'
shell: bash
run: |
cd go-api-examples/non-streaming-decode-files
ls -lh
go mod tidy
cat go.mod
ls -lh
go env GOARCH
go env
echo "------------------------------"
go env -w GOARCH=386
go env -w CGO_ENABLED=1
go env
go clean
go build -x
echo $PWD
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/
cp -v /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/sherpa-onnx-go-windows*/lib/i686-pc-windows-gnu/*.dll .
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-zipformer-en-2023-06-26
./run-transducer.sh
rm -rf sherpa-onnx-zipformer-en-2023-06-26
echo "Test paraformer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28
./run-paraformer.sh
rm -rf sherpa-onnx-paraformer-zh-2023-03-28
echo "Test NeMo CTC"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-nemo-ctc-en-conformer-medium
./run-nemo-ctc.sh
rm -rf sherpa-onnx-nemo-ctc-en-conformer-medium
- name: Test streaming decoding files (Linux/macOS)
if: matrix.os != 'windows-latest'
shell: bash
run: |
cd go-api-examples/streaming-decode-files
ls -lh
go mod tidy
cat go.mod
go build -x
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
./run.sh
rm -rf sherpa-onnx-streaming-zipformer-en-2023-06-26
- name: Test streaming decoding files (Win64)
if: matrix.os == 'windows-latest' && matrix.arch == 'x64'
shell: bash
run: |
cd go-api-examples/streaming-decode-files
ls -lh
go mod tidy
cat go.mod
go build
ls -lh
echo $PWD
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/*
cp -v /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/sherpa-onnx-go-windows*/lib/x86_64-pc-windows-gnu/*.dll .
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
./run.sh
rm -rf sherpa-onnx-streaming-zipformer-en-2023-06-26
- name: Test streaming decoding files (Win32)
if: matrix.os == 'windows-latest' && matrix.arch == 'x86'
shell: bash
run: |
cd go-api-examples/streaming-decode-files
ls -lh
go mod tidy
cat go.mod
ls -lh
go env GOARCH
go env
echo "------------------------------"
go env -w GOARCH=386
go env -w CGO_ENABLED=1
go env
go clean
go build -x
echo $PWD
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/
ls -lh /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/*
cp -v /C/Users/runneradmin/go/pkg/mod/github.com/k2-fsa/sherpa-onnx-go-windows*/lib/i686-pc-windows-gnu/*.dll .
ls -lh
git lfs install
echo "Test transducer"
git clone https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
./run.sh
rm -rf sherpa-onnx-streaming-zipformer-en-2023-06-26

198
.github/workflows/release-go.yaml vendored Normal file
View File

@@ -0,0 +1,198 @@
name: release-go
on:
push:
branches:
- master
tags:
- '*'
workflow_dispatch:
inputs:
version:
description: "Version informatione.g., 1.5.3) or auto"
required: true
env:
VERSION:
|- # Enter release tag name or version name in workflow_dispatch. Appropriate version if not specified
${{ github.event.release.tag_name || github.event.inputs.version }}
concurrency:
group: release-go-${{ github.ref }}
cancel-in-progress: true
jobs:
linux-x86_64_wheel:
if: github.repository_owner == 'k2-fsa' || github.repository_owner == 'csukuangfj'
name: Linux x86_64
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: SSH to GitHub
run: |
mkdir -p ~/.ssh/
cp scripts/go/ssh_config ~/.ssh/config
echo "${{ secrets.MY_GITHUB_SSH_KEY }}" > ~/.ssh/github && chmod 600 ~/.ssh/github
ssh github.com || true
rm ~/.ssh/github
# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
- name: Build wheels
uses: pypa/cibuildwheel@v2.11.4
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'
- name: Display wheels
shell: bash
run: |
ls -lh ./wheelhouse/*.whl
unzip -l ./wheelhouse/*.whl
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-wheels-for-go
path: ./wheelhouse/*.whl
macOS:
name: macOS ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest]
arch: [x86_64, arm64]
steps:
- uses: actions/checkout@v2
- name: Configure CMake
shell: bash
run: |
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=ON -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for macOS ${{ matrix.arch }}
shell: bash
run: |
cd build
make -j2
make install
ls -lh lib
ls -lh bin
file install/lib/lib*
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-for-${{ matrix.arch }}
path: ./build/install/lib/
windows:
name: Windows ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
arch: [x64, Win32]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Configure CMake
shell: bash
run: |
mkdir build
cd build
cmake -A ${{ matrix.arch }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash
run: |
cd build
cmake --build . --config Release -- -m:2
cmake --build . --config Release --target install -- -m:2
ls -lh install/*
ls -lh install/lib
ls -lh install/bin
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: sherpa-onnx-go-windows-${{ matrix.arch }}
path: ./build/install/lib/
Release:
name: Release
runs-on: ubuntu-latest
needs: [linux-x86_64_wheel, macOS, windows]
steps:
- uses: actions/checkout@v2
- name: Add SSH key
run: |
mkdir -p ~/.ssh/
cp scripts/go/ssh_config ~/.ssh/config
echo "${{ secrets.MY_GITHUB_SSH_KEY }}" > ~/.ssh/github && chmod 600 ~/.ssh/github
ssh github.com || true
- name: Retrieve artifact from ubuntu-latest
uses: actions/download-artifact@v2
with:
name: ubuntu-latest-wheels-for-go
path: ./linux
- name: Retrieve artifact from macos-latest (x86_64)
uses: actions/download-artifact@v2
with:
name: macos-latest-for-x86_64
path: ./macos-x86_64
- name: Retrieve artifact from macos-latest (arm64)
uses: actions/download-artifact@v2
with:
name: macos-latest-for-arm64
path: ./macos-arm64
- name: Retrieve artifact from windows-latest (x64)
uses: actions/download-artifact@v2
with:
name: sherpa-onnx-go-windows-x64
path: ./windows-x64
- name: Retrieve artifact from windows-latest (Win32)
uses: actions/download-artifact@v2
with:
name: sherpa-onnx-go-windows-Win32
path: ./windows-win32
- name: Unzip Ubuntu wheels
shell: bash
run: |
cd linux
ls -lh
unzip ./*.whl
tree .
- name: Release go
if: env.VERSION != ''
shell: bash
run: |
./scripts/go/release.sh

View File

@@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v2