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

Auto-update snapshot tests if changing strings #20

Merged
Changes from all commits
Commits
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
75 changes: 69 additions & 6 deletions .github/workflows/build-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:

env:
node-version: 18
english-strings: client/src/intl/en.json

jobs:
build:
Expand All @@ -31,6 +32,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
cache: npm
cache-dependency-path: client/package-lock.json

- name: Install
run: npm ci
Expand All @@ -55,22 +58,73 @@ jobs:

test:
runs-on: ubuntu-latest
needs:
- translations
defaults:
run:
working-directory: client
permissions:
contents: write # For commiting changes back to the current PR.
pull-requests: write # For commenting on the PR.
steps:
- uses: actions/checkout@v4
with:
# The translation job may have committed some changes; use them!
ref: ${{ needs.translations.outputs.commit_hash }}

- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
cache: npm
cache-dependency-path: client/package-lock.json

- name: Install
run: npm ci

# We want to know if this branch has changed the english strings, not
# just if the `translations` job had to update it, so we need this check.
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
english:
- ${{ env.english-strings }}

- name: Unit tests
run: npm test
env:
update_snapshots: ${{ github.event_name == 'pull_request' && steps.changes.outputs.english == 'true' }}
run: |
if [ "${update_snapshots}" == 'true' ]; then
echo '⚠️ Updating snapshots as part of the test!'
echo '-----------------------------------------'
npm run test:update
else
npm test
fi

- name: Commit changes to Snapshots
uses: stefanzweifel/git-auto-commit-action@v5
id: commit
if: github.event_name == 'pull_request'
with:
commit_message: 'Auto-update snapshot tests'
file_pattern: '*.snap'

- name: Comment on the PR about changes
uses: thollander/actions-comment-pull-request@v3
if: steps.commit.outputs.changes_detected == 'true'
env:
commit_url: 'https://github.com/${{ github.repository }}/commit/${{ steps.commit.outputs.commit_hash }}'
with:
message: >
🚨 The "snapshot" tests in your PR have been automatically updated
because you changed some text in the app! **Make sure [the changes
to `.snap` files](${{ env.commit_url }}) are correct** and don’t
include other things that should *not* have changed.

You can also update snapshot tests yourself when working locally by
running `npm run test:update` on the command line.

lint:
runs-on: ubuntu-latest
Expand All @@ -84,6 +138,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
cache: npm
cache-dependency-path: client/package-lock.json

- name: Install
run: npm ci
Expand All @@ -109,13 +165,18 @@ jobs:
permissions:
contents: write # For commiting changes back to the current PR.
pull-requests: write # For commenting on the PR.
outputs:
changed: ${{ steps.commit-strings.outputs.changes_detected == 'true' }}
commit_hash: ${{ steps.commit-strings.outputs.commit_hash }}
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
cache: npm
cache-dependency-path: client/package-lock.json

- name: Install
run: npm ci
Expand All @@ -124,20 +185,22 @@ jobs:
if: github.event_name == 'pull_request'
run: npm run intl:extract

- uses: stefanzweifel/git-auto-commit-action@v5
- name: Commit changes to English strings
uses: stefanzweifel/git-auto-commit-action@v5
id: commit-strings
if: github.event_name == 'pull_request'
with:
commit_message: 'Auto-update en.json from component source code'
file_pattern: 'client/src/intl/en.json'
file_pattern: '${{ env.english-strings }}'

- uses: thollander/actions-comment-pull-request@v3
- name: Comment on the PR about changes
uses: thollander/actions-comment-pull-request@v3
if: steps.commit-strings.outputs.changes_detected == 'true'
with:
message: >
:wave: FYI, your PR has been automatically updated with changes to
`client/src/intl/en.json`, which contains all the translatable text
from the application (probably because you made changes to
`${{ env.english-strings }}`, which contains all the translatable
text from the application (probably because you made changes to
the text of a component without updating this file).

- name: Check Spanish translations
Expand Down
Loading