Skip to content

Commit

Permalink
VERSION.txtを消去し、releaseビルド時に自動的にバージョン名が入るようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Jan 15, 2022
1 parent d7c5d56 commit 50228ff
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
60 changes: 37 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
VOICEVOX_RESOURCE_VERSION: '0.10.preview.2'
VOICEVOX_CORE_VERSION: '0.10.preview.3'
VOICEVOX_CORE_SOURCE_VERSION: '0.10.preview.3'
VOICEVOX_ENGINE_VERSION: |- # releaseのときはタグが、それ以外はlatestがバージョン名に
${{ github.event.release.tag_name != '' && github.event.release.tag_name || 'latest' }}
jobs:
# Build Mac binary (x64 arch only)
Expand All @@ -37,6 +39,13 @@ jobs:
shell: bash
run: brew install ccache

# NOTE: The default sed of macOS is BSD sed.
# There is a difference in specification between BSD sed and GNU sed,
# so you need to install GNU sed.
- name: Install GNU sed on macOS
shell: bash
run: brew install gnu-sed

- name: Create download and build directory
run: mkdir download build

Expand Down Expand Up @@ -199,6 +208,8 @@ jobs:
run: |
set -eux
gsed -i "s/__version__ = \"latest\"/__version__ = \"${{ env.VOICEVOX_ENGINE_VERSION }}\"/" ../voicevox_engine/__init__.py
# Nuitka does not copy grandchild dependencies. Explicitly copy libonnxruntime
python -m nuitka \
--output-dir=./ \
Expand All @@ -211,7 +222,6 @@ jobs:
--include-package=anyio \
--include-package-data=pyopenjtalk \
--include-package-data=scipy \
--include-data-file=../VERSION.txt=./ \
--include-data-file=../licenses.json=./ \
--include-data-file=../presets.yaml=./ \
--include-data-file=../user.dic=./ \
Expand Down Expand Up @@ -339,6 +349,7 @@ jobs:
BASE_IMAGE=${{ matrix.base_image }}
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
VOICEVOX_ENGINE_VERSION=${{ env.VOICEVOX_ENGINE_VERSION }}
VOICEVOX_CORE_VERSION=${{ env.VOICEVOX_CORE_VERSION }}
VOICEVOX_CORE_SOURCE_VERSION=${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
VOICEVOX_CORE_LIBRARY_NAME=${{ matrix.voicevox_core_library_name }}
Expand Down Expand Up @@ -703,28 +714,31 @@ jobs:
shell: bash
env:
NUITKA_CACHE_DIR: ${{ matrix.nuitka_cache_path }}
run:
python -m nuitka
--standalone
--assume-yes-for-downloads
--plugin-enable=numpy
--plugin-enable=multiprocessing
--follow-import-to=numpy
--follow-import-to=aiofiles
--include-package=uvicorn
--include-package=anyio
--include-package-data=pyopenjtalk
--include-package-data=scipy
--include-data-file="VERSION.txt=./"
--include-data-file="licenses.json=./"
--include-data-file="user.dic=./"
--include-data-file="presets.yaml=./"
--include-data-file=download/core/*.bin=./
--include-data-file="download/core/metas.json=./"
--include-data-dir="speaker_info=./speaker_info"
--msvc=14.2
--follow-imports
--no-prefer-source-code
run: |
set -eux
sed -i "s/__version__ = \"latest\"/__version__ = \"${{ env.VOICEVOX_ENGINE_VERSION }}\"/" voicevox_engine/__init__.py
python -m nuitka \
--standalone \
--assume-yes-for-downloads \
--plugin-enable=numpy \
--plugin-enable=multiprocessing \
--follow-import-to=numpy \
--follow-import-to=aiofiles \
--include-package=uvicorn \
--include-package=anyio \
--include-package-data=pyopenjtalk \
--include-package-data=scipy \
--include-data-file="licenses.json=./" \
--include-data-file="user.dic=./" \
--include-data-file="presets.yaml=./" \
--include-data-file=download/core/*.bin=./ \
--include-data-file="download/core/metas.json=./" \
--include-data-dir="speaker_info=./speaker_info" \
--msvc=14.2 \
--follow-imports \
--no-prefer-source-code \
run.py
- name: Show disk space (debug info)
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ EOF
# Add local files
ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine
ADD ./docs /opt/voicevox_engine/docs
ADD ./run.py ./generate_licenses.py ./check_tts.py ./presets.yaml ./VERSION.txt ./user.dic /opt/voicevox_engine/
ADD ./run.py ./generate_licenses.py ./check_tts.py ./presets.yaml ./user.dic /opt/voicevox_engine/
ADD ./speaker_info /opt/voicevox_engine/speaker_info

# Replace version
ARG VOICEVOX_ENGINE_VERSION=latest
RUN sed -i "s/__version__ = \"latest\"/__version__ = \"${VOICEVOX_ENGINE_VERSION}\"/" /opt/voicevox_engine/voicevox_engine/__init__.py

# Generate licenses.json
RUN <<EOF
set -eux
Expand Down Expand Up @@ -360,7 +364,6 @@ RUN <<EOF
--include-package=anyio \
--include-package-data=pyopenjtalk \
--include-package-data=scipy \
--include-data-file=/opt/voicevox_engine/VERSION.txt=./ \
--include-data-file=/opt/voicevox_engine/licenses.json=./ \
--include-data-file=/opt/voicevox_engine/presets.yaml=./ \
--include-data-file=/opt/voicevox_engine/user.dic=./ \
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ python -m nuitka \
--include-package=anyio \
--include-package-data=pyopenjtalk \
--include-package-data=scipy \
--include-data-file=VERSION.txt=./ \
--include-data-file=licenses.json=./ \
--include-data-file=presets.yaml=./ \
--include-data-file=user.dic=./ \
Expand Down
1 change: 0 additions & 1 deletion VERSION.txt

This file was deleted.

5 changes: 3 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from fastapi.params import Query
from starlette.responses import FileResponse

from voicevox_engine import __version__
from voicevox_engine.cancellable_engine import CancellableEngine
from voicevox_engine.kana_parser import create_kana, parse_kana
from voicevox_engine.model import (
Expand Down Expand Up @@ -51,7 +52,7 @@ def generate_app(engine: SynthesisEngineBase) -> FastAPI:
app = FastAPI(
title="VOICEVOX ENGINE",
description="VOICEVOXの音声合成エンジンです。",
version=(root_dir / "VERSION.txt").read_text().strip(),
version=__version__,
)

app.add_middleware(
Expand Down Expand Up @@ -422,7 +423,7 @@ def get_presets():

@app.get("/version", tags=["その他"])
def version() -> str:
return (root_dir / "VERSION.txt").read_text()
return __version__

@app.get("/speakers", response_model=List[Speaker], tags=["その他"])
def speakers():
Expand Down
1 change: 1 addition & 0 deletions voicevox_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "latest"
16 changes: 6 additions & 10 deletions voicevox_engine/dev/core/mock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from logging import getLogger
from pathlib import Path
from typing import Any, Dict, List

import numpy as np
Expand Down Expand Up @@ -68,9 +68,7 @@ def decode_forward(length: int, **kwargs: Dict[str, Any]) -> np.ndarray:


def metas() -> str:
mock_dir = Path(__file__).parent
version = (mock_dir / ".." / ".." / ".." / "VERSION.txt").read_text().strip()
return str(
return json.dumps(
[
{
"name": "dummy1",
Expand All @@ -81,7 +79,7 @@ def metas() -> str:
{"name": "style3", "id": 6},
],
"speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
"version": version,
"version": "mock",
},
{
"name": "dummy2",
Expand All @@ -92,25 +90,23 @@ def metas() -> str:
{"name": "style3", "id": 7},
],
"speaker_uuid": "388f246b-8c41-4ac1-8e2d-5d79f3ff56d9",
"version": version,
"version": "mock",
},
{
"name": "dummy3",
"styles": [
{"name": "style0", "id": 8},
],
"speaker_uuid": "35b2c544-660e-401e-b503-0e14c635303a",
"version": version,
"version": "mock",
},
{
"name": "dummy4",
"styles": [
{"name": "style0", "id": 9},
],
"speaker_uuid": "b1a81618-b27b-40d2-b0ea-27a9ad408c4b",
"version": version,
"version": "mock",
},
]
).replace(
"'", '"' # ちゃんとJSONとして認識してもらうためにシングルクォーテーションを置き換える
)

0 comments on commit 50228ff

Please sign in to comment.