Skip to content

fix: onlyBuiltDependenciesを修正 (#3027) #369

fix: onlyBuiltDependenciesを修正 (#3027)

fix: onlyBuiltDependenciesを修正 (#3027) #369

Workflow file for this run

name: Test
on:
push:
branches:
- main
pull_request:
branches:
- "**"
workflow_dispatch:
inputs:
update_snapshots:
description: "スナップショットを更新する"
required: false
type: boolean
default: false
env:
VOICEVOX_ENGINE_REPO: "VOICEVOX/voicevox_nemo_engine" # 軽いのでNemoを使う
VOICEVOX_ENGINE_VERSION: "0.24.0"
defaults:
run:
shell: bash
jobs:
config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる.
runs-on: ubuntu-latest
outputs:
shouldUpdateSnapshots: ${{ steps.check-whether-to-update-snapshots.outputs.shouldUpdateSnapshots }}
steps:
- name: Check whether to update snapshots
id: check-whether-to-update-snapshots
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "shouldUpdateSnapshots=${{ inputs.update_snapshots }}" >> $GITHUB_OUTPUT
else
echo "shouldUpdateSnapshots=false" >> $GITHUB_OUTPUT
fi
# ビルドのテスト
build-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup environment
uses: ./.github/actions/setup-environment
- run: pnpm run electron:build
# unit テスト
unit-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup environment
uses: ./.github/actions/setup-environment
- name: Run test
run: |
pnpm run test:unit
# e2e テスト
e2e-test:
runs-on: ${{ matrix.os }}
needs: [config]
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
voicevox_engine_asset_name: linux-cpu-x64
- os: macos-latest
voicevox_engine_asset_name: macos-arm64
- os: windows-latest
voicevox_engine_asset_name: windows-cpu
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup environment
uses: ./.github/actions/setup-environment
- name: Install xvfb and x11-xserver-utils
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y xvfb x11-xserver-utils # for electron
- name: Download VOICEVOX ENGINE
id: download-engine
uses: ./.github/actions/download-engine
with:
repo: ${{ env.VOICEVOX_ENGINE_REPO }}
version: ${{ env.VOICEVOX_ENGINE_VERSION }}
dest: ${{ github.workspace }}/voicevox_engine
target: ${{ matrix.voicevox_engine_asset_name }}
- name: Run pnpm run test:browser-e2e
run: |
if [ -n "${{ runner.debug }}" ]; then
export DEBUG="pw:browser*"
fi
ARGS=""
if [[ ${{ needs.config.outputs.shouldUpdateSnapshots }} == 'true' ]]; then
ARGS="--update-snapshots"
fi
pnpm run test:browser-e2e $ARGS
- name: Run pnpm run test:electron-e2e
run: |
# .env
cp tests/env/.env.test-electron .env
sed -i -e 's|"path/to/engine"|"${{ steps.download-engine.outputs.run_path }}"|' .env
# GitHub Actions 環境だとたまに50021が封じられていることがあるので、ランダムなポートを使うようにする
PORT=$(node -r net -e "server=net.createServer();server.listen(0,()=>{console.log(server.address().port);server.close()})")
sed -i -e 's|random_port|'$PORT'|' .env
cat .env # ログ用
if [ -n "${{ runner.debug }}" ]; then
export DEBUG="pw:browser*"
fi
if [[ ${{ matrix.os }} == ubuntu-* ]]; then
xvfb-run --auto-servernum pnpm run test:electron-e2e
else
pnpm run test:electron-e2e
fi
rm .env
- name: Run pnpm run test:storybook-vrt
run: |
if [ -n "${{ runner.debug }}" ]; then
export DEBUG="pw:browser*"
fi
ARGS=""
if [[ ${{ needs.config.outputs.shouldUpdateSnapshots }} == 'true' ]]; then
ARGS="--update-snapshots"
fi
pnpm run test:storybook-vrt $ARGS
- name: Upload playwright report to artifact
if: failure()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: playwright-report-${{ matrix.os }}
path: playwright-report
- name: Collect patch for snapshots
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
run: |
# ログ用
git status
# git diff に表示されるようにする
git add --intent-to-add --all tests/
git diff --binary HEAD tests/ > patch-${{ matrix.os }}.diff
- name: Upload patch to artifact
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: updated-snapshots-${{ matrix.os }}
path: patch-${{ matrix.os }}.diff
commit-snapshots:
runs-on: ubuntu-latest
permissions:
contents: write
needs: [config, e2e-test]
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
# NOTE: デフォルトの設定だとgithub-push-actionが動いてくれないので設定を変えている。
# ref: https://github.com/ad-m/github-push-action/issues/44#issuecomment-581706892
persist-credentials: false
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
pattern: updated-snapshots-*
path: ${{ runner.temp }}/patches
merge-multiple: true
- name: Commit updated snapshots
id: commit-updated-snapshots
run: |
# パッチを適用
for patch in ${{ runner.temp }}/patches/*.diff; do
git apply --allow-empty $patch
rm $patch
done
# 変更があるかチェック
if [ -n "$(git status --porcelain)" ]; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add tests/
git commit -m "(スナップショットを更新)"
echo "changes_exist=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit"
echo "changes_exist=false" >> $GITHUB_OUTPUT
fi
- name: Push changes
if: steps.commit-updated-snapshots.outputs.changes_exist == 'true'
uses: ad-m/github-push-action@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa
with:
github_token: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Show warning if token is not set
if: steps.commit-updated-snapshots.outputs.changes_exist == 'true'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const pushTokenProvided = `${{ secrets.PUSH_TOKEN }}` !== "";
if (!pushTokenProvided) {
core.warning(
"スクリーンショットを更新したので、空コミットをプッシュしてテストを再実行してください。\n" +
"PUSH_TOKENをSecretsに追加すると次からこの操作を省けます。\n" +
"Secretsの設定方法はREADME.mdを参照してください。"
);
}
console.log(`pushTokenProvided: ${pushTokenProvided}`);
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup environment
uses: ./.github/actions/setup-environment
- name: Disallowed licenses check
run: pnpm run license:generate -o voicevox_licenses.json
- run: pnpm run typecheck
- run: pnpm run lint
- run: pnpm run markdownlint
- run: pnpm run typos
- name: Check pinact
uses: suzuki-shunsuke/pinact-action@28aeb220eb3252ad0d4422dd5d9368e925acbd8d # v1.3.0
with:
skip_push: "true"
min_age: "7"