Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish npm package for nodejs #284

Closed
wants to merge 18 commits into from
1 change: 1 addition & 0 deletions .github/workflows/aarch64-linux-gnu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
- 'cmake/**'
- 'sherpa-ncnn/csrc/*'
- 'toolchains/aarch64-linux-gnu.toolchain.cmake'
workflow_dispatch:

concurrency:
group: aarch64-linux-gnu-${{ github.ref }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/arm-linux-gnueabihf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
- 'cmake/**'
- 'sherpa-ncnn/csrc/*'
- 'toolchains/arm-linux-gnueabihf.toolchain.cmake'
workflow_dispatch:

concurrency:
group: arm-linux-gnueabihf-${{ github.ref }}
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/build-wheels-macos-arm64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: build-wheels-macos-arm64

on:
push:
branches:
- wheel
tags:
- '*'
workflow_dispatch:

env:
SHERPA_NCNN_IS_IN_GITHUB_ACTIONS: 1

concurrency:
group: build-wheels-macos-arm64-${{ github.ref }}
cancel-in-progress: true

jobs:
build_wheels_arm64:
name: ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest]
python-version: ["cp38", "cp39", "cp310", "cp311", "cp312"]

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_BUILD: "${{ matrix.python-version}}-* "
CIBW_ENVIRONMENT: SHERPA_NCNN_CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES='arm64'"
CIBW_ARCHS: "arm64"
CIBW_BUILD_VERBOSITY: 3

# Don't repair macOS wheels
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

- name: Display wheels
shell: bash
run: |
ls -lh ./wheelhouse/

ls -lh ./wheelhouse/*.whl

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

- name: Publish to huggingface
if: matrix.python-version == 'cp38'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v2
with:
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
git config --global user.email "[email protected]"
git config --global user.name "Fangjun Kuang"

rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1

git clone https://huggingface.co/csukuangfj/sherpa-ncnn-wheels huggingface
cd huggingface
git fetch
git pull
git merge -m "merge remote" --ff origin main

cp -v ../wheelhouse/*.whl .

git status
git add .
git commit -m "add more wheels"
git push https://csukuangfj:[email protected]/csukuangfj/sherpa-ncnn-wheels main

- name: Publish wheels to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m pip install --upgrade pip
python3 -m pip install wheel twine setuptools

twine upload ./wheelhouse/*.whl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-wheels-macos
name: build-wheels-macos-x64

on:
push:
Expand All @@ -12,11 +12,11 @@ env:
SHERPA_NCNN_IS_IN_GITHUB_ACTIONS: 1

concurrency:
group: build-wheels-macos-${{ github.ref }}
group: build-wheels-macos-x64-${{ github.ref }}
cancel-in-progress: true

jobs:
build_wheels:
build_wheels_x64:
name: ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -34,8 +34,8 @@ jobs:
uses: pypa/[email protected]
env:
CIBW_BUILD: "${{ matrix.python-version}}-* "
CIBW_ENVIRONMENT: SHERPA_NCNN_CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'"
CIBW_ARCHS: "universal2"
CIBW_ENVIRONMENT: SHERPA_NCNN_CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES='x86_64'"
CIBW_ARCHS: "x86_64"
CIBW_BUILD_VERBOSITY: 3

# Don't repair macOS wheels
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/jni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ on:
- 'sherpa-ncnn/jni/*'
- '.github/scripts/test-jni.sh'

workflow_dispatch:

concurrency:
group: jni-${{ github.ref }}
cancel-in-progress: true
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ on:
- 'sherpa-ncnn/csrc/*'
- 'sherpa-ncnn/csrc/*'

workflow_dispatch:

concurrency:
group: linux-${{ github.ref }}
cancel-in-progress: true
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ on:
- 'cmake/**'
- 'sherpa-ncnn/csrc/*'

workflow_dispatch:

concurrency:
group: macos-${{ github.ref }}
cancel-in-progress: true
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/mfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,8 @@ on:
- 'mfc-examples/**'
- 'sherpa-ncnn/csrc/*'
- 'sherpa-ncnn/c-api/*'
release:
types:
- published

workflow_dispatch:
inputs:
release:
description: "Whether to release"
type: boolean

env:
RELEASE:
|- # Release if there is a release tag name or a release flag in workflow_dispatch
${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }}

concurrency:
group: mfc-${{ github.ref }}
Expand Down Expand Up @@ -130,7 +118,6 @@ jobs:
path: ./sherpa-ncnn*.exe

- name: Release pre-compiled binaries for Windows ${{ matrix.arch }}
if: env.RELEASE == 'true'
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
Expand Down
37 changes: 7 additions & 30 deletions .github/workflows/nodejs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ on:
push:
branches:
- master
paths:
- '.github/workflows/nodejs.yaml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'nodejs-examples/**'
- 'sherpa-ncnn/csrc/*'
- nodejs

pull_request:
branches:
- master
paths:
- '.github/workflows/nodejs.yaml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'nodejs-examples/**'
- 'sherpa-ncnn/csrc/*'

workflow_dispatch:

concurrency:
group: nodejs-${{ github.ref }}
Expand Down Expand Up @@ -49,6 +41,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 13
registry-url: 'https://registry.npmjs.org'

- name: Display node version
shell: bash
Expand All @@ -61,18 +54,6 @@ jobs:
npm install [email protected]
npm --version

- name: Install npm packages
shell: bash
run: |
cd nodejs-examples
npm install ffi-napi ref-struct-napi wav
npm list

- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.os }}-shared

- name: Download model
shell: bash
run: |
Expand All @@ -85,11 +66,7 @@ jobs:
- name: Test
shell: bash
run: |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version

cd nodejs-examples
ls -lh

./run.sh
npm install sherpa-ncnn4 wav
node ./test.js
60 changes: 60 additions & 0 deletions .github/workflows/npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: npm

on:
push:
branches:
- master

workflow_dispatch:

concurrency:
group: npm-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
nodejs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8"]

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

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: actions/setup-node@v3
with:
node-version: 13
registry-url: 'https://registry.npmjs.org'

- name: Display node version
shell: bash
run: |
node --version
npm --version
cd nodejs-examples

npm install [email protected] -g
npm install [email protected]
npm --version

- name: Build nodejs package
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd scripts/nodejs
./run.sh
npm ci
npm publish --provenance --access public
1 change: 1 addition & 0 deletions .github/workflows/swift-api-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
- 'sherpa-ncnn/csrc/*'
- 'sherpa-ncnn/swift-api-examples/*'
- 'build-swift-macos.sh'
workflow_dispatch:

concurrency:
group: swift-api-test-${{ github.ref }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-dot-net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ on:
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"

workflow_dispatch:

concurrency:
group: test-dot-net
cancel-in-progress: true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-pip-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
# day of the week (0-6)
# nightly test at 22:50 UTC time every day
- cron: "50 22 * * *"
workflow_dispatch:

concurrency:
group: test_pip_install-${{ github.ref }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows-x64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- 'CMakeLists.txt'
- 'cmake/**'
- 'sherpa-ncnn/csrc/*'
workflow_dispatch:

concurrency:
group: windows-x64-${{ github.ref }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows-x86.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- 'CMakeLists.txt'
- 'cmake/**'
- 'sherpa-ncnn/csrc/*'
workflow_dispatch:

concurrency:
group: windows-x86-${{ github.ref }}
Expand Down
13 changes: 13 additions & 0 deletions nodejs-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Introduction

## Usage
```
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13
cd sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13
git lfs pull --include "*.bin"
ls -lh
cd ..

npm install sherpa-ncnn wav
node ./test.js
```
Loading
Loading