From 9bc58d00ffb24138b3b56b9a1bf7ef7bdf3b549c Mon Sep 17 00:00:00 2001 From: MoritzWeber Date: Wed, 4 Sep 2024 10:44:30 +0200 Subject: [PATCH] ci: Add Storybook visual testing results to PR comment --- .github/workflows/storybook.yml | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index 7c63c636e8..65b80ed731 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -56,7 +56,7 @@ jobs: with: projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} workingDir: ./frontend - - name: Create or update Storybook comment on PR + - name: Create Storybook comment (no changes) if: github.event_name == 'pull_request' uses: peter-evans/create-or-update-comment@v4 with: @@ -64,6 +64,43 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | A Storybook preview is available for commit ${{ github.sha }}. - [View Storybook](${{ steps.chromatic.outputs.storybookUrl }}) - [View Chromatic build](${{ steps.chromatic.outputs.buildUrl }}) + ➡️ [View Storybook](${{ steps.chromatic.outputs.storybookUrl }}) + ➡️ [View Chromatic build](${{ steps.chromatic.outputs.buildUrl }}) + edit-mode: replace + - name: Create Storybook comment (with changes) + if: + github.event_name == 'pull_request' && + steps.chromatic.outputs.changeCount == 0 + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.cc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ✅ Captured ${{ steps.chromatic.outputs.actualCaptureCount }} snapshots. No changes detected. + edit-mode: append + - name: Create Storybook comment (with changes) + if: + github.event_name == 'pull_request' && + steps.chromatic.outputs.changeCount > 0 + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.cc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + # prettier-ignore + body: > + 🔍 ${{ steps.chromatic.outputs.changeCount }} out of + ${{ steps.chromatic.outputs.componentCount }} snapshots have changed. + Please review the changes before merging. + edit-mode: append + - name: Create Storybook comment (failure) + # prettier-ignore + if: + github.event_name == 'pull_request' && steps.chromatic.outcome != 'success' + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.cc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + The Storybook preview generation failed for commit ${{ github.sha }}. + Check the log output of the GitHub action for more information. edit-mode: replace