Skip to content

Commit

Permalink
Fix: e2eテストが動かないのを修正 (#1276)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
  • Loading branch information
sevenc-nanashi and Hiroshiba authored Apr 11, 2023
1 parent 8f670e2 commit 9e8fdc7
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 179 deletions.
12 changes: 12 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DEFAULT_ENGINE_INFOS=`[
{
"uuid": "074fc39e-678b-4c13-8916-ffca8d505d1d",
"name": "VOICEVOX Engine",
"executionEnabled": true,
"executionFilePath": "../voicevox_engine/run.exe",
"executionArgs": [],
"host": "http://127.0.0.1:50021"
}
]`
VITE_GTM_CONTAINER_ID=GTM-DUMMY
VV_OUTPUT_LOG_UTF8=1
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = {
"./src/background.ts",
"./src/background/*.ts",
"./src/electron/*.ts",
"./tests/**/*.ts",
],
rules: {
"no-console": "off",
Expand Down
96 changes: 96 additions & 0 deletions .github/actions/download-engine/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: "Download VOICEVOX ENGINE"
description: |
VOICEVOX ENGINEをダウンロードし、指定したディレクトリに展開する。
inputs:
version:
description: "VOICEVOX ENGINEのバージョン。latest(デフォルト)、prerelease-latest、バージョン番号(例:0.14.4)で指定できる。"
required: false
default: "latest"
dest:
description: "VOICEVOX ENGINEを展開するディレクトリ。"
required: true
target:
description: "ダウンロードする対象。デフォルトは各OSのCPU版。"
required: false
default: ""

outputs:
run_path:
description: "run.exe、またはrunのパス。"
value: ${{ steps.result.outputs.run_path }}
version:
description: "VOICEVOX ENGINEのバージョン。"
value: ${{ steps.result.outputs.version }}
runs:
using: "composite"
steps:
- name: Setup tempdir
shell: bash
run: |
TEMPDIR=$(echo '${{ runner.temp }}' | sed -e 's_\\_/_g')
echo TEMPDIR=$TEMPDIR >> $GITHUB_ENV
mkdir -p $TEMPDIR
DEST=$(echo '${{ inputs.dest }}' | sed -e 's_\\_/_g')
echo DEST=$DEST >> $GITHUB_ENV
- name: Get version
shell: bash
run: |
curl -s https://api.github.com/repos/voicevox/voicevox_engine/releases \
-H 'authorization: Bearer ${{ github.token }}' \
-H 'content-type: application/json' > $TEMPDIR/releases.json
if [ "${{ inputs.version }}" = "latest" ]; then
cat $TEMPDIR/releases.json | jq -er '[.[] | select(.prerelease == false)][0]' > $TEMPDIR/target.json
elif [ "${{ inputs.version }}" = "prerelease-latest" ]; then
cat $TEMPDIR/releases.json | jq -er '[.[] | select(.prerelease == true)][0]' > $TEMPDIR/target.json
else
cat $TEMPDIR/releases.json | jq -er '[.[] | select(.tag_name == "${{ inputs.version }}")][0]' > $TEMPDIR/target.json
fi
- name: Download and Extract
shell: bash
run: |
if [ "${{ inputs.target }}" = "" ]; then
OS="${{ runner.os }}"
TARGET="${OS,,}-cpu" # 小文字にする
else
TARGET="${{ inputs.target }}"
fi
# リリース情報からファイル一覧のtxtを取得
cat $TEMPDIR/target.json | jq -er '[.assets[] | select(.name | contains("'$TARGET'") and endswith(".7z.txt"))][0]' > $TEMPDIR/assets_txt.json
LIST_URL=$(cat $TEMPDIR/assets_txt.json | jq -er '.browser_download_url')
echo "7z.txt url: $LIST_URL"
echo $LIST_URL | xargs curl -sSL > $TEMPDIR/download_name.txt
echo "Files to download:"
cat $TEMPDIR/download_name.txt | sed -e 's|^|- |'
# ファイル一覧のtxtにあるファイルをダウンロード
for i in $(cat $TEMPDIR/download_name.txt); do
URL=$(cat $TEMPDIR/target.json | jq -er "[.assets[] | select(.name == \"$i\")][0].browser_download_url")
echo "Download url: $URL, dest: $TEMPDIR/$i"
curl -sSL $URL -o $TEMPDIR/$i &
done
for job in `jobs -p`; do
wait $job
done
# 一時ディレクトリに展開してから、本体(windows-cpuなどの中)を取り出す
7z x -y -o$TEMPDIR/tmp-extract $TEMPDIR/$(head -1 $TEMPDIR/download_name.txt)
mkdir -p $DEST
mv $TEMPDIR/tmp-extract/$TARGET/* $DEST
echo "::group::ll $DEST"
ls -al $DEST
echo "::endgroup::"
- name: Set output
id: result
shell: bash
run: |
if [ "${{ runner.os }}" = "Windows" ]; then
echo "run_path=$DEST/run.exe" >> $GITHUB_OUTPUT
else
echo "run_path=$DEST/run" >> $GITHUB_OUTPUT
fi
cat $TEMPDIR/target.json | jq -r '.tag_name' | sed -e 's_^_version=_' >> $GITHUB_OUTPUT
53 changes: 9 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,48 +263,13 @@ jobs:
mv ${{ matrix.artifact_path }} ./prepackage
# Download VOICEVOX ENGINE
- name: Create directory voicevox_engine/download
shell: bash
run: |
mkdir -p voicevox_engine/download
# NOTE: VOICEVOX ENGINE should not be cached since it has a size of several GB
# and actions/cache has a limit of 5GB per repository.
# https://github.com/actions/cache#cache-limits
# - name: Dump VOICEVOX ENGINE repo URL to calc hash
# shell: bash
# run: |
# echo "${{ env.VOICEVOX_ENGINE_REPO_URL }}" > voicevox_engine/repo_url.txt
# - name: Cache VOICEVOX ENGINE
# uses: actions/cache@v3
# id: voicevox-engine-cache
# with:
# path: voicevox_engine/download
# key: ${{ env.cache-version }}-voicevox-engine-${{ hashFiles('voicevox_engine/repo_url.txt') }}-${{ env.VOICEVOX_ENGINE_VERSION }}

- name: Download VOICEVOX ENGINE
# if: steps.voicevox-engine-cache.outputs.cache-hit != 'true'
shell: bash
env:
VOICEVOX_ENGINE_RELEASE_URL: ${{ env.VOICEVOX_ENGINE_REPO_URL }}/releases/download/${{ env.VOICEVOX_ENGINE_VERSION }}
run: |
curl -L -o "voicevox_engine/download/list.txt" "${{ env.VOICEVOX_ENGINE_RELEASE_URL }}/voicevox_engine-${{ matrix.voicevox_engine_asset_name }}-${{ env.VOICEVOX_ENGINE_VERSION }}.7z.txt"
cat "voicevox_engine/download/list.txt" | xargs -I '%' curl -L -o "voicevox_engine/download/%" "${{ env.VOICEVOX_ENGINE_RELEASE_URL }}/%"
- name: Extract VOICEVOX ENGINE
shell: bash
run: |
mkdir -p voicevox_engine/tmp
# Extract first file to extract all parts
# Destination: voicevox_engine/tmp/${{ matrix.voicevox_engine_asset_name }}/
7z x "voicevox_engine/download/$(head -n1 voicevox_engine/download/list.txt)" -ovoicevox_engine/tmp/
mkdir -p voicevox_engine/voicevox_engine
mv "voicevox_engine/tmp/${{ matrix.voicevox_engine_asset_name }}"/* voicevox_engine/voicevox_engine
# remove downloads to free space
rm -rf voicevox_engine/download voicevox_engine/tmp
id: download-engine
uses: ./.github/actions/download-engine
with:
version: ${{ env.VOICEVOX_ENGINE_VERSION }}
dest: ${{ github.workspace }}/voicevox_engine
target: ${{ matrix.voicevox_engine_asset_name }}

# FIXME: asarをextract/packせず、ビルド前にengine_licenses.jsonとlicenses.jsonを結合する
- name: Merge licenses.json (ENGINE, VOICEVOX)
Expand All @@ -314,7 +279,7 @@ jobs:
npx asar extract "${{ matrix.app_asar_dir }}/app.asar" "${{ matrix.app_asar_dir }}/app"
rm "${{ matrix.app_asar_dir }}/app.asar"
mv voicevox_engine/voicevox_engine/licenses.json engine_licenses.json
mv voicevox_engine/licenses.json engine_licenses.json
npm run license:merge -- -o "${{ matrix.app_asar_dir }}/app/dist/licenses.json" -i engine_licenses.json -i "${{ matrix.app_asar_dir }}/app/dist/licenses.json"
# Repack asar
Expand All @@ -325,14 +290,14 @@ jobs:
if: startsWith(matrix.artifact_name, 'windows-') || startsWith(matrix.artifact_name, 'linux-')
shell: bash
run: |
mv voicevox_engine/voicevox_engine/* prepackage/
mv voicevox_engine/* prepackage/
rm -rf voicevox_engine
- name: Merge VOICEVOX ENGINE into prepackage/VOICEVOX.app/Contents/MacOS/
if: startsWith(matrix.artifact_name, 'macos-')
shell: bash
run: |
mv voicevox_engine/voicevox_engine/* prepackage/VOICEVOX.app/Contents/MacOS/
mv voicevox_engine/* prepackage/VOICEVOX.app/Contents/MacOS/
rm -rf voicevox_engine
- name: Show disk space (debug info)
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- "**"
workflow_dispatch:

env:
VOICEVOX_ENGINE_VERSION: 0.14.4

jobs:
build:
runs-on: windows-latest
Expand Down Expand Up @@ -47,4 +50,22 @@ jobs:
- run: npm run lint
- run: npm run markdownlint
- run: npm run test:unit

- name: Download VOICEVOX ENGINE
id: download-engine
uses: ./.github/actions/download-engine
with:
version: ${{ env.VOICEVOX_ENGINE_VERSION }}
dest: ${{ github.workspace }}/voicevox_engine

- name: Run npm run test:e2e
shell: bash
run: |
cp .env.test .env
sed -i -e 's|"../voicevox_engine/run.exe"|"${{ steps.download-engine.outputs.run_path }}"|' .env
if [ -n "${{ runner.debug }}" ]; then
DEBUG=pw:browser* npm run test:e2e
else
npm run test:e2e
fi
- run: npm run electron:build_pnever
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ npm run test:unit
npm run test:e2e
```

### 監視モード

```bash
npm run test-watch:unit
npm run test-watch:e2e
```

## 依存ライブラリのライセンス情報の生成

```bash
Expand Down
Loading

0 comments on commit 9e8fdc7

Please sign in to comment.