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

VERSION.txtを消去し、releaseビルド時に自動的にバージョン名が入るようにした #288

Merged
merged 3 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ env:
PYTHON_VERSION: '3.8.10'
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-docker:
Expand Down Expand Up @@ -108,6 +110,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
62 changes: 39 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,9 @@ jobs:
run: |
set -eux

# Replace version
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 +223,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 +350,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 +715,32 @@ 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

# Replace version
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として認識してもらうためにシングルクォーテーションを置き換える
)