C APIのセーフティネットのメッセージを改善する #2059
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: test workflow | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
env: | |
CARGO_TERM_COLOR: always | |
# 簡易テストとするかどうか。workflow_dispatch以外は簡易テストとする | |
IS_SIMPLE_TEST: ${{ github.event_name != 'workflow_dispatch' }} | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
shellcheck: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Update ShellCheck | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y shellcheck | |
- name: ShellCheck | |
run: git ls-files | grep -E '\.(ba)?sh' | xargs shellcheck | |
actionlint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
# ShellCheckとPyflakesをインストールしておくと、shell: bashとshell: pythonのコードを検査してくれるようになる | |
# | |
# 参考: | |
# - https://github.com/rhysd/actionlint/blob/main/docs/checks.md#shellcheck-integration-for-run | |
# - https://github.com/rhysd/actionlint/blob/main/docs/checks.md#pyflakes-integration-for-run | |
- name: Update ShellCheck | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y shellcheck | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- name: Install Pyflakes | |
run: pip install 'pyflakes>3,<4' | |
- name: actionlint | |
run: | | |
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) | |
./actionlint -color | |
validate-cargo-lock: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: Validate Cargo.lock | |
run: cargo metadata --locked --format-version 1 > /dev/null | |
rust-lint: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
with: | |
components: clippy,rustfmt | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- uses: Swatinem/rust-cache@v2 | |
- run: cargo clippy -vv --all-features --features onnxruntime/disable-sys-build-script --tests -- -D clippy::all -D warnings --no-deps | |
- run: cargo clippy -vv --all-features --features onnxruntime/disable-sys-build-script -- -D clippy::all -D warnings --no-deps | |
- run: cargo fmt -- --check | |
rust-unit-test: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
key: "cargo-unit-test-cache" | |
- name: Run cargo unit test | |
run: RUST_BACKTRACE=full cargo test --lib --bins -vv --features , -- --include-ignored | |
- name: Run cargo documentation test | |
run: RUST_BACKTRACE=full cargo test --doc -vv | |
rust-integration-test-strategy-matrix: # 実行対象の条件をフィルタリングする | |
runs-on: ubuntu-latest | |
outputs: | |
includes: ${{ steps.strategy-matrix.outputs.includes }} | |
steps: | |
- name: declare strategy matrix | |
id: strategy-matrix | |
run: | | |
includes='[ | |
{ "os": "windows-2019", "features": "", "can_skip_in_simple_test": true }, | |
{ "os": "windows-2022", "features": "", "can_skip_in_simple_test": true }, | |
{ "os": "windows-2019", "features": "directml", "can_skip_in_simple_test": false }, | |
{ "os": "windows-2022", "features": "directml", "can_skip_in_simple_test": true }, | |
{ "os": "macos-11", "features": "", "can_skip_in_simple_test": false }, | |
{ "os": "macos-12", "features": "", "can_skip_in_simple_test": true }, | |
{ "os": "ubuntu-20.04", "features": "", "can_skip_in_simple_test": false }, | |
{ "os": "ubuntu-22.04", "features": "", "can_skip_in_simple_test": true } | |
]' | |
# FIXME: composite action に切り出す | |
if ${{ env.IS_SIMPLE_TEST }}; then | |
includes=$(echo "$includes" | jq -c '[.[] | select(.can_skip_in_simple_test == false)]') | |
fi | |
includes=$(echo "$includes" | jq -c '[.[] | del(.can_skip_in_simple_test)]') | |
echo "includes=${includes}" >> "$GITHUB_OUTPUT" | |
rust-integration-test: | |
needs: rust-integration-test-strategy-matrix | |
strategy: | |
fail-fast: false | |
matrix: | |
include: ${{ fromJson(needs.rust-integration-test-strategy-matrix.outputs.includes) }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
key: "cargo-integration-test-cache-${{ matrix.features }}-${{ matrix.os }}" | |
- name: Run cargo integration test | |
run: RUST_BACKTRACE=full cargo test --test "*" -vv --features ,${{ matrix.features }} -- --include-ignored | |
c-header: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: Install cargo-binstall | |
uses: taiki-e/install-action@cargo-binstall | |
- name: Extract the version of cbindgen that xtask depends on | |
id: cbindgen-version | |
run: | | |
metadata=$(cargo metadata --format-version 1) | |
version=$( | |
jq -r ' | |
(.workspace_members[] | select(startswith("xtask "))) as $xtask | |
| (.resolve.nodes[] | select(.id == $xtask).deps[] | select(.name == "cbindgen").pkg) as $cbindgen | |
| .packages[] | select(.id == $cbindgen).version | |
' <<< "$metadata" | |
) | |
echo "version=$version" >> "$GITHUB_OUTPUT" | |
- name: Install cbindgen v${{ steps.cbindgen-version.outputs.version }} | |
run: | | |
cargo binstall \ | |
cbindgen@${{ steps.cbindgen-version.outputs.version }} \ | |
--pkg-url 'https://github.com/alsuren/cargo-quickinstall/releases/download/{ name }-{ version }-{ target }/{ name }-{ version }-{ target }.tar.gz' \ | |
--pkg-fmt tgz \ | |
--bin-dir '{ bin }{ binary-ext }' \ | |
--no-confirm \ | |
--log-level debug | |
- name: Assert voicevox_core.h is up to date | |
run: | | |
cbindgen --crate voicevox_core_c_api -o /tmp/voicevox_core.h | |
diff -u --color=always {/tmp,./crates/voicevox_core_c_api/include}/voicevox_core.h | |
- name: Assert `cargo xtask update-c-header --verify` succeeds | |
run: | | |
cargo xtask update-c-header --verify | |
git diff | |
build-unix-cpp-example: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: macos-latest | |
artifact_name: osx-x64-cpu-cpp-shared | |
- os: ubuntu-latest | |
artifact_name: linux-x64-cpu-cpp-shared | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: Install cargo-binstall | |
uses: taiki-e/install-action@cargo-binstall | |
- name: build voicevox_core_c_api | |
run: cargo build -p voicevox_core_c_api -vv | |
- name: 必要なfileをunix用exampleのディレクトリに移動させる | |
run: | | |
mkdir -p example/cpp/unix/voicevox_core/ | |
cp -v crates/voicevox_core_c_api/include/voicevox_core.h example/cpp/unix/voicevox_core/ | |
cp -v target/debug/libvoicevox_core.{so,dylib} example/cpp/unix/voicevox_core/ || true | |
cp -v target/debug/build/onnxruntime-sys-*/out/onnxruntime_*/onnxruntime-*/lib/libonnxruntime.so.* example/cpp/unix/voicevox_core/ || true | |
cp -v target/debug/build/onnxruntime-sys-*/out/onnxruntime_*/onnxruntime-*/lib/libonnxruntime.*.dylib example/cpp/unix/voicevox_core/ || true | |
- if: startsWith(matrix.os, 'mac') | |
uses: jwlawson/[email protected] | |
- name: Install build dependencies | |
if: startsWith(matrix.os, 'ubuntu') | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y cmake | |
- name: Build | |
run: | | |
cd example/cpp/unix | |
cmake -S . -B build | |
cmake --build build | |
build-windows-cpp-example: | |
strategy: | |
fail-fast: false | |
runs-on: windows-latest | |
env: | |
# Path to the solution file relative to the root of the project. | |
SOLUTION_FILE_PATH: example\cpp\windows\windows_example.sln | |
# Configuration type to build. | |
BUILD_CONFIGURATION: Debug | |
defaults: | |
run: | |
shell: pwsh | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: Install cargo-binstall | |
uses: taiki-e/install-action@cargo-binstall | |
- name: build voicevox_core_c_api | |
run: cargo build -p voicevox_core_c_api -vv | |
- name: 必要なfileをexampleのディレクトリに移動させる | |
run: | | |
mkdir -p example/cpp/windows/simple_tts/lib/x64 | |
cp -v crates/voicevox_core_c_api/include/voicevox_core.h example/cpp/windows/simple_tts/ | |
cp target/debug/voicevox_core.dll.lib example/cpp/windows/simple_tts/lib/x64/voicevox_core.lib | |
- name: Add MSBuild to PATH | |
uses: microsoft/[email protected] | |
- name: Restore NuGet packages | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
run: nuget restore ${{env.SOLUTION_FILE_PATH}} | |
- name: Build | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} | |
build-and-test-python-api: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: windows-latest | |
- os: macos-latest | |
- os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: venv作成 | |
uses: ./.github/actions/create-venv | |
- run: pip install -r ./crates/voicevox_core_python_api/requirements.txt | |
- run: cargo build -p voicevox_core_c_api -vv | |
- run: maturin build --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --locked | |
- run: maturin develop --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --locked | |
- name: 必要なDLLをコピーしてpytestを実行 | |
working-directory: crates/voicevox_core_python_api | |
run: | | |
cp -v ../../target/debug/build/onnxruntime-sys-*/out/onnxruntime_*/onnxruntime-*/lib/onnxruntime.dll . || true | |
cp -v ../../target/debug/build/onnxruntime-sys-*/out/onnxruntime_*/onnxruntime-*/lib/libonnxruntime.so.* . || true | |
cp -v ../../target/debug/build/onnxruntime-sys-*/out/onnxruntime_*/onnxruntime-*/lib/libonnxruntime.*.dylib . || true | |
pip install -r requirements-test.txt | |
pytest | |
build-and-test-java-api: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: windows-latest | |
- os: macos-latest | |
- os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Rust | |
uses: ./.github/actions/rust-toolchain-from-file | |
- name: Set up Java | |
uses: actions/setup-java@v2 | |
with: | |
java-version: "11" | |
distribution: "adopt" | |
- name: Build | |
run: | | |
cargo build -p voicevox_core_java_api -vv | |
cargo build -p test_util -vv | |
- name: 必要なDLLをコピーしてテストを実行 | |
working-directory: crates/voicevox_core_java_api | |
run: | | |
OS=$(tr '[:upper:]' '[:lower:]' <<<"$RUNNER_OS") | |
ARCH=$(tr '[:upper:]' '[:lower:]' <<<"$RUNNER_ARCH") | |
case "$RUNNER_OS" in | |
Windows) | |
DLL_NAME="voicevox_core_java_api.dll" | |
;; | |
macOS) | |
DLL_NAME="libvoicevox_core_java_api.dylib" | |
;; | |
Linux) | |
DLL_NAME="libvoicevox_core_java_api.so" | |
;; | |
*) | |
echo "Unsupported OS: $RUNNER_OS" | |
exit 1 | |
;; | |
esac | |
TARGET_NAME="$OS-$ARCH" | |
mkdir -p "./lib/src/main/resources/dll/$TARGET_NAME" | |
cp -v "../../target/debug/$DLL_NAME" "./lib/src/main/resources/dll/$TARGET_NAME/$DLL_NAME" | |
echo "target = $TARGET_NAME, dll = $DLL_NAME" | |
./gradlew test --info |