Skip to content

Commit

Permalink
Merge branch 'main' into エンジンのmockを作る
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Nov 9, 2024
2 parents 57337a3 + 301f792 commit b5fdcad
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/build_preview_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ jobs:

- name: Build
run: |
# 追加のバージョン情報
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
LOCATION="PR#${{ github.event.pull_request.number }}"
SHORT_SHA=$(cut -c 1-7 <<< "${{ github.event.pull_request.head.sha }}")
else
LOCATION="${{ github.ref_name }}"
SHORT_SHA=$(cut -c 1-7 <<< "${{ github.sha }}")
fi
# Storybookのビルド
npm run storybook:build -- --output-dir $(pwd)/dist_preview/storybook
npm run browser:build -- --base ./ --outDir $(pwd)/dist_preview/editor
# ブラウザ版エディタのビルド
VITE_EXTRA_VERSION_INFO="${LOCATION} @ ${SHORT_SHA}" \
npm run browser:build -- --base ./ --outDir $(pwd)/dist_preview/editor
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
4 changes: 4 additions & 0 deletions src/components/Menu/MenuBar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const store = useStore();
const { registerHotkeyWithCleanup } = useHotkeyManager();
const currentVersion = ref("");
/** 追加のバージョン情報。コミットハッシュなどを書ける。 */
const extraVersionInfo = import.meta.env.VITE_EXTRA_VERSION_INFO;
const audioKeys = computed(() => store.state.audioKeys);
// デフォルトエンジンの代替先ポート
Expand Down Expand Up @@ -93,6 +96,7 @@ const titleText = computed(
(projectName.value != undefined ? projectName.value + " - " : "") +
"VOICEVOX" +
(currentVersion.value ? " - Ver. " + currentVersion.value : "") +
(extraVersionInfo ? ` (${extraVersionInfo})` : "") +
(isMultiEngineOffMode.value ? " - マルチエンジンオフ" : "") +
(defaultEngineAltPortTo.value != null
? ` - Port: ${defaultEngineAltPortTo.value}`
Expand Down
43 changes: 21 additions & 22 deletions src/domain/defaultEngine/latetDefaultEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,46 @@

import { z } from "zod";

/** パッケージ(vvppやvvppp1ファイル)ごとのスキーマ */
const defaultEnginePackageSchema = z.object({
url: z.string(),
name: z.string(),
size: z.number(),
hash: z.string().optional(),
});

/** デバイスごとのスキーマ */
const defaultEngineDeviceSchema = z.object({
/** パッケージ情報のスキーマ */
const engineVariantSchema = z.object({
version: z.string(),
packages: z.array(defaultEnginePackageSchema),
packages: z
.object({
url: z.string(),
name: z.string(),
size: z.number(),
hash: z.string().optional(),
})
.array(),
});

/** デフォルトエンジンの更新情報のスキーマ */
const defaultEngineInfosSchema = z.object({
/** デフォルトエンジンの最新情報のスキーマ */
const latestDefaultEngineInfoSchema = z.object({
formatVersion: z.number(),
windows: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
"GPU/CPU": defaultEngineDeviceSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
macos: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
CPU: engineVariantSchema,
}),
arm64: z.object({
CPU: defaultEngineDeviceSchema,
CPU: engineVariantSchema,
}),
}),
linux: z.object({
x64: z.object({
CPU: defaultEngineDeviceSchema,
"GPU/CPU": defaultEngineDeviceSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
});

/** デフォルトエンジンの更新情報を取得する */
export const fetchDefaultEngineInfos = async (url: string) => {
/** デフォルトエンジンの最新情報を取得する */
export const fetchLatestDefaultEngineInfo = async (url: string) => {
const response = await fetch(url);
return defaultEngineInfosSchema.parse(await response.json());
return latestDefaultEngineInfoSchema.parse(await response.json());
};
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ImportMetaEnv {
readonly VITE_LATEST_UPDATE_INFOS_URL: string;
readonly VITE_GTM_CONTAINER_ID: string;
readonly VITE_TARGET: "electron" | "browser";
readonly VITE_EXTRA_VERSION_INFO: string | undefined;
}

interface ImportMeta {
Expand Down
21 changes: 0 additions & 21 deletions tests/unit/domain/defaultEngine/defaultEngine.node.spec.ts

This file was deleted.

16 changes: 16 additions & 0 deletions tests/unit/domain/defaultEngine/latetDefaultEngine.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import latestDefaultEngineInfos from "./latestDefaultEngineInfos.json";
import { fetchLatestDefaultEngineInfo } from "@/domain/defaultEngine/latetDefaultEngine";

test("fetchLatestDefaultEngineInfo", async () => {
// テスト用のjsonファイルでfetchをモックする
// 元ファイルは https://raw.githubusercontent.com/VOICEVOX/voicevox_blog/master/src/generateLatestDefaultEngineInfos.ts
const spy = vi
.spyOn(global, "fetch")
.mockResolvedValue(new Response(JSON.stringify(latestDefaultEngineInfos)));

// 読み込めることを確認
const infos = await fetchLatestDefaultEngineInfo("https://example.com/");
expect(infos.formatVersion).toBe(1);

spy.mockRestore();
});

0 comments on commit b5fdcad

Please sign in to comment.