Skip to content

Commit

Permalink
Merge: main -> add/java-build-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 19, 2023
2 parents 502d06e + bbb35b4 commit f958e5d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 29 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ defaults:
shell: bash

jobs:
build_and_deploy_strategy_matrix: # 実行対象の条件をフィルタリングする
config: # 全 jobs で利用する定数の定義。実行対象の条件をフィルタリングする
runs-on: ubuntu-latest
outputs:
includes: ${{ steps.strategy_matrix.outputs.includes }}
deploy: ${{ env.VERSION != '0.0.0' }}
steps:
- name: declare strategy matrix
id: strategy_matrix
Expand Down Expand Up @@ -181,11 +182,11 @@ jobs:
echo "includes=${includes}" >> "$GITHUB_OUTPUT"
build_and_deploy:
needs: build_and_deploy_strategy_matrix
needs: config
environment: ${{ github.event.inputs.is_production == 'true' && 'production' || '' }} # 製品版のenvironment
strategy:
matrix:
include: ${{ fromJson(needs.build_and_deploy_strategy_matrix.outputs.includes) }}
include: ${{ fromJson(needs.config.outputs.includes) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3 # 製品版ではない場合
Expand Down Expand Up @@ -345,7 +346,7 @@ jobs:
cd artifact
7z a "../${{ env.ASSET_NAME }}.zip" "${{ env.ASSET_NAME }}"
- name: Upload to Release
if: env.VERSION != '0.0.0' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' && !contains(matrix.target, 'ios')
if: needs.config.outputs.deploy == 'true' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' && !contains(matrix.target, 'ios')
uses: softprops/action-gh-release@v1
with:
prerelease: true
Expand All @@ -354,7 +355,7 @@ jobs:
${{ env.ASSET_NAME }}.zip
target_commitish: ${{ github.sha }}
- name: Upload Python whl to Release
if: env.VERSION != '0.0.0' && matrix.whl_local_version
if: needs.config.outputs.deploy == 'true' && matrix.whl_local_version
uses: softprops/action-gh-release@v1
with:
prerelease: true
Expand All @@ -371,7 +372,7 @@ jobs:

build_xcframework:
if: ${{ !(github.event_name != 'release' && github.event_name != 'workflow_dispatch') }} # !env.IS_SIMPLE_TEST と同じ
needs: build_and_deploy
needs: [config, build_and_deploy]
runs-on: macos-12
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -414,7 +415,7 @@ jobs:
cd artifact/${{ env.ASSET_NAME }}
7z a "../../${{ env.ASSET_NAME }}.zip" "voicevox_core.xcframework"
- name: Upload to Release
if: env.VERSION != '0.0.0' && env.SKIP_UPLOADING_RELEASE_ASSET == '0'
if: needs.config.outputs.deploy == 'true' && env.SKIP_UPLOADING_RELEASE_ASSET == '0'
uses: softprops/action-gh-release@v1
with:
prerelease: true
Expand Down Expand Up @@ -589,3 +590,9 @@ jobs:
files: |-
/tmp/java_packages.zip
target_commitish: ${{ github.sha }}
download_test:
needs: [config, build_and_deploy]
if: needs.config.outputs.deploy == 'true'
uses: ./.github/workflows/download_test.yml
with:
version: ${{ inputs.version }}
25 changes: 16 additions & 9 deletions .github/workflows/download_test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: Download test workflow

on:
workflow_call:
inputs:
version:
description: "テスト対象のコアのバージョン。無指定時はprerelease込みの最新release。"
type: string
required: false
push:
branches:
- main
Expand All @@ -10,7 +17,7 @@ on:
- ".github/workflows/download_test.yml"

env:
VERSION: "prerelease-latest"
VERSION: ${{ inputs.version || 'prerelease-latest' }}

defaults:
run:
Expand All @@ -28,7 +35,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
open_jtalk_dic_utf_8-1.11
README.txt
# https://github.com/VOICEVOX/voicevox_core/pull/411#issuecomment-1412457592
Expand All @@ -46,7 +53,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
open_jtalk_dic_utf_8-1.11
README.txt
check_not_exists_items: |
Expand All @@ -63,7 +70,7 @@ jobs:
download_dir: other_output
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
open_jtalk_dic_utf_8-1.11
README.txt
check_not_exists_items: |
Expand All @@ -80,7 +87,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
README.txt
check_not_exists_items: |
*directml*
Expand All @@ -97,7 +104,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
open_jtalk_dic_utf_8-1.11
README.txt
DirectML.dll
Expand All @@ -116,7 +123,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
README.txt
check_not_exists_items: |
*cuda*
Expand All @@ -134,7 +141,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
open_jtalk_dic_utf_8-1.11
README.txt
EULA.txt
Expand All @@ -156,7 +163,7 @@ jobs:
download_dir: voicevox_core
check_items: |
voicevox_core.dll
model/metas.json
model/README.*
README.txt
check_not_exists_items: |
*directml*
Expand Down
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ name = "e2e"
directml = ["voicevox_core/directml"]

[dependencies]
anstream = { version = "0.5.0", default-features = false, features = ["auto"] }
anstyle-query = "1.0.0"
colorchoice = "1.0.0"
cstr = "0.2.11"
derive-getters.workspace = true
itertools.workspace = true
Expand Down
35 changes: 22 additions & 13 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use self::drop_check::C_STRING_DROP_CHECKER;
use self::helpers::*;
use self::result_code::VoicevoxResultCode;
use self::slice_owner::U8_SLICE_OWNER;
use anstream::{AutoStream, RawStream};
use chrono::SecondsFormat;
use colorchoice::ColorChoice;
use derive_getters::Getters;
use once_cell::sync::Lazy;
use std::env;
use std::ffi::{CStr, CString};
use std::fmt;
use std::io::{self, IsTerminal, Write};
use std::io;
use std::os::raw::c_char;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex, MutexGuard};
Expand All @@ -37,14 +39,31 @@ static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
let _ = init_logger();

fn init_logger() -> std::result::Result<(), impl Sized> {
let ansi = {
// anstyle系のクレートを利用して次の2つを行う。
//
// * ANSI escape codeを出してよいかの判定(環境変数のチェックとisatty)
// * 必要であれば`ENABLE_VIRTUAL_TERMINAL_PROCESSING`の有効化

assert_eq!(
ColorChoice::Auto,
ColorChoice::global(),
"`ColorChoice::write_global` should not have been called",
);

AutoStream::choice(&out()) != ColorChoice::Never
&& anstyle_query::term_supports_ansi_color()
&& anstyle_query::windows::enable_ansi_colors().unwrap_or(true)
};

tracing_subscriber::fmt()
.with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() {
EnvFilter::from_default_env()
} else {
"error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into()
})
.with_timer(local_time as fn(&mut Writer<'_>) -> _)
.with_ansi(out().is_terminal() && env_allows_ansi())
.with_ansi(ansi)
.with_writer(out)
.try_init()
}
Expand All @@ -55,20 +74,10 @@ static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
wtr.write_str(&chrono::Local::now().to_rfc3339_opts(SecondsFormat::Micros, false))
}

fn out() -> impl IsTerminal + Write {
fn out() -> impl RawStream {
io::stderr()
}

fn env_allows_ansi() -> bool {
// https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291
// ただしWindowsではPowerShellっぽかったらそのまま許可する。
// ちゃんとやるなら`ENABLE_VIRTUAL_TERMINAL_PROCESSING`をチェックするなり、そもそも
// fwdansiとかでWin32の色に変換するべきだが、面倒。
env::var_os("TERM").map_or(
cfg!(windows) && env::var_os("PSModulePath").is_some(),
|term| term != "dumb",
) && env::var_os("NO_COLOR").is_none()
}
Runtime::new().unwrap()
});

Expand Down

0 comments on commit f958e5d

Please sign in to comment.