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

全OSでGithub Actionsでのスナップショットを更新できるようにする #1761

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
406fc4e
スナップショットを更新できるようにする
Hiroshiba Jan 25, 2024
8c9d36a
パッチする仕組みにしてみる [update snapshots]
Hiroshiba Jan 25, 2024
c130ec4
スナップショット更新してみる [update snapshots]
Hiroshiba Jan 25, 2024
2c9620e
a [update snapshots]
Hiroshiba Jan 25, 2024
2bdab8c
[update snapshots]
Hiroshiba Jan 25, 2024
0ead2bb
(スナップショットを更新)
github-actions[bot] Jan 25, 2024
d8ebe2b
add [update snapshots]
Hiroshiba Jan 25, 2024
67fffe9
Merge branch 'スナップショットを更新できるようにする' of github.com:Hiroshiba/voicevox i…
Hiroshiba Jan 25, 2024
b8fdf04
a [update snapshots]
Hiroshiba Jan 25, 2024
faa50ac
空コミット [update snapshots]
Hiroshiba Jan 25, 2024
9ccf516
空コミット [update snapshots]
Hiroshiba Jan 25, 2024
c23ad13
(スナップショットを更新)
github-actions[bot] Jan 25, 2024
46190c6
空コミット [update snapshots]
Hiroshiba Jan 25, 2024
d488a6c
空コミット [update snapshots]
Hiroshiba Jan 25, 2024
86c958e
からコミット3 [update snapshots]
Hiroshiba Jan 25, 2024
e5accbe
if [ -n "$(git status --porcelain)" ]; then [update snapshots]
Hiroshiba Jan 25, 2024
e26b6d0
からコミット
Hiroshiba Jan 25, 2024
0aad395
[update snapshots]
Hiroshiba Jan 25, 2024
789657c
config jobに [update snapshots]
Hiroshiba Jan 25, 2024
3cfbe75
空コミット
Hiroshiba Jan 25, 2024
125c5a0
やっぱりwinだけにしよう! [update snapshots]
Hiroshiba Jan 25, 2024
e965bd8
ローカルでの更新方法を追記
Hiroshiba Jan 25, 2024
4b92d41
[update snapshots]
Hiroshiba Jan 25, 2024
d961b4a
Apply suggestions from code review
Hiroshiba Jan 25, 2024
19af669
[update snapshots]
Hiroshiba Jan 25, 2024
0cede2b
主導削除
Hiroshiba Jan 25, 2024
6e3c811
別に不具合ではないという理解
Hiroshiba Jan 25, 2024
6e32d15
Merge remote-tracking branch 'upstream/main' into スナップショットを更新できるようにする
Hiroshiba Jan 28, 2024
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
76 changes: 48 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ defaults:
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:
github-token: ${{ secrets.GITHUB_TOKEN }}
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
Expand All @@ -38,6 +61,7 @@ jobs:
# e2e テスト
e2e-test:
runs-on: ${{ matrix.os }}
needs: [config]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -87,31 +111,13 @@ jobs:
sed -i -e 's|"executionArgs": \[\],|"executionArgs": ["--port='$PORT'"],|' .env.test
cp .env.test .env

- name: Check if commit message includes [update snapshots]
id: check-whether-to-update-snapshots
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
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}`);

- name: Run npm run test:browser-e2e
run: |
if [ -n "${{ runner.debug }}" ]; then
export DEBUG="pw:browser*"
fi
ARGS=""
if [[ ${{ steps.check-whether-to-update-snapshots.outputs.shouldUpdateSnapshots }} == 'true' ]]; then
if [[ ${{ needs.config.outputs.shouldUpdateSnapshots }} == 'true' ]]; then
ARGS="--update-snapshots"
fi
npm run test:browser-e2e -- $ARGS
Expand All @@ -134,35 +140,49 @@ jobs:
name: playwright-report-${{ matrix.os }}
path: playwright-report

- name: Upload updated snapshots to artifact
if: steps.check-whether-to-update-snapshots.outputs.shouldUpdateSnapshots == 'true'
- 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: tests/e2e/browser/*-snapshots/*
path: patch-${{ matrix.os }}.diff

commit-snapshots:
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- e2e-test
needs: [config, e2e-test]
if: needs.config.outputs.shouldUpdateSnapshots == 'true'
steps:
- uses: actions/checkout@v3

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: updated-snapshots-*
path: tests/e2e/browser
path: patches
merge-multiple: true

- name: Commit updated snapshots
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# パッチを適用
for patch in patches/*.diff; do
git apply --allow-empty $patch
rm $patch
done

# 変更があるかチェック
if [ -n "$(git status --porcelain)" ]; then
git add tests/e2e/browser
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 "(スナップショットを更新)"
git push
else
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ npx playwright codegen http://localhost:5173/#/talk --viewport-size=800,600
#### スクリーンショットの更新

ブラウザ End to End テストでは Visual Regression Testing を行っています。
現在 VRT テストは Windows のみで行っています。
以下の手順でスクリーンショットを更新できます:

##### Github Actions で更新する場合

1. フォークしたリポジトリの設定で GitHub Actions を有効にします。
2. リポジトリの設定の Actions > General > Workflow permissions で Read and write permissions を選択します。
3. `[update snapshots]` という文字列をコミットメッセージに含めてコミットします。
Expand All @@ -128,6 +131,14 @@ npx playwright codegen http://localhost:5173/#/talk --viewport-size=800,600

4. Github Workflow が完了すると、更新されたスクリーンショットがコミットされます。

##### ローカルで更新する場合

ローカル PC の OS に対応したもののみが更新されます。

```bash
npm run test:browser-e2e -- --update-snapshots
```

### Electron End to End テスト

Electron の機能が必要な、エンジン起動・終了などを含めた End to End テストを実行します。
Expand Down
Loading