-
Notifications
You must be signed in to change notification settings - Fork 306
248 lines (219 loc) · 8.61 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: Test
on:
push:
pull_request:
branches:
- "**"
workflow_dispatch:
env:
VOICEVOX_ENGINE_REPO: "VOICEVOX/voicevox_nemo_engine" # 軽いのでNemoを使う
VOICEVOX_ENGINE_VERSION: "0.14.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 if commit message includes [update snapshots]
id: check-whether-to-update-snapshots
uses: actions/github-script@v7
with:
script: |
const commits = ${{ toJson(github.event.commits) }};
if (!commits) {
// pull_request などでコミットがない場合はスキップ
core.setOutput("shouldUpdateSnapshots", false);
process.exit(0);
}
const shouldUpdateSnapshots = commits.some((commit) =>
commit.message.toLowerCase().includes("[update snapshots]")
);
core.setOutput("shouldUpdateSnapshots", shouldUpdateSnapshots);
console.log(`shouldUpdateSnapshots: ${shouldUpdateSnapshots}`);
# ビルドのテスト
build-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-environment
- run: npm run electron:build
# unit テスト
unit-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-environment
- name: Run test
run: |
npm run test:unit
# e2e テスト
e2e-test:
runs-on: ${{ matrix.os }}
needs: [config]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
voicevox_engine_asset_name: linux-cpu
- os: macos-latest
voicevox_engine_asset_name: macos-x64
# TODO: voicevox_nemo_negineがarm64に対応したら変更する
# - os: macos-latest
# voicevox_engine_asset_name: macos-arm64
- os: windows-latest
voicevox_engine_asset_name: windows-cpu
steps:
- uses: actions/checkout@v4
- 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
sudo apt-get install -y libsndfile1 # for engine
- 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: Setup
run: |
# run.exe
chmod +x ${{ steps.download-engine.outputs.run_path }}
# .env
sed -i -e 's|"074fc39e-678b-4c13-8916-ffca8d505d1d"|"208cf94d-43d2-4cf5-abc0-9783cac36d29"|' .env.test
sed -i -e 's|"../voicevox_engine/run.exe"|"${{ steps.download-engine.outputs.run_path }}"|' .env.test
# 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|"host": "http://127.0.0.1:50021"|"host": "http://127.0.0.1:'$PORT'"|' .env.test
sed -i -e 's|"executionArgs": \[\],|"executionArgs": ["--port='$PORT'"],|' .env.test
cp .env.test .env
- name: Run npm 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
npm run test:browser-e2e -- $ARGS
- name: Run npm run test:electron-e2e
run: |
if [ -n "${{ runner.debug }}" ]; then
export DEBUG="pw:browser*"
fi
if [[ ${{ matrix.os }} == ubuntu-* ]]; then
xvfb-run --auto-servernum npm run test:electron-e2e
else
npm run test:electron-e2e
fi
- name: Run npm 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
npm run test:storybook-vrt -- $ARGS
- name: Upload playwright report to artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report-${{ matrix.os }}
path: playwright-report
- name: Collect patch for snapshots
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
run: |
git add --intent-to-add tests/ # git diff に表示されるようにする
git diff tests/ # ロギング用
git diff --binary tests/ > patch-${{ matrix.os }}.diff
- name: Upload patch to artifact
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
uses: actions/upload-artifact@v4
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@v4
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@v4
with:
pattern: updated-snapshots-*
path: patches
merge-multiple: true
- name: Commit updated snapshots
id: commit-updated-snapshots
run: |
# パッチを適用
for patch in 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@v7
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@v4
- name: Setup environment
uses: ./.github/actions/setup-environment
- name: Disallowed licenses check
run: npm run license:generate -- -o voicevox_licenses.json
- run: npm run typecheck
- run: npm run lint
- run: npm run markdownlint
- run: npm run typos