diff --git a/.github/workflows/screenshot-test.yml b/.github/workflows/screenshot-test.yml index b49adbdf639..e5a91228a14 100644 --- a/.github/workflows/screenshot-test.yml +++ b/.github/workflows/screenshot-test.yml @@ -11,7 +11,7 @@ on: permissions: contents: read pull-requests: write - statuses: write + checks: write concurrency: group: screenshots-${{ github.event.pull_request.number || github.sha }} @@ -65,24 +65,28 @@ jobs: test/componentFixtures/.screenshots/report.json test/componentFixtures/.screenshots/report.md - - name: Set status - id: status + - name: Set check title env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | REPORT="test/componentFixtures/.screenshots/report.json" if [ -f "$REPORT" ]; then CHANGED=$(node -e "const r = require('./$REPORT'); console.log(r.summary.added + r.summary.removed + r.summary.changed)") - STATUS_TEXT="${CHANGED} screenshots changed" + TITLE="${CHANGED} screenshots changed" else - STATUS_TEXT="Screenshots match" + TITLE="Screenshots match" fi SHA="${{ github.event.pull_request.head.sha || github.sha }}" - gh api "repos/${{ github.repository }}/statuses/$SHA" \ - -f state=success \ - -f description="$STATUS_TEXT" \ - -f context="screenshots" + CHECK_RUN_ID=$(gh api "repos/${{ github.repository }}/commits/$SHA/check-runs" \ + --jq '.check_runs[] | select(.name == "screenshots") | .id') + + if [ -n "$CHECK_RUN_ID" ]; then + gh api "repos/${{ github.repository }}/check-runs/$CHECK_RUN_ID" \ + -X PATCH --input - <> $GITHUB_STEP_SUMMARY fi - - name: Post PR comment - if: github.event_name == 'pull_request' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - COMMENT_MARKER="" - BODY="$COMMENT_MARKER"$'\n' - - if [ -f test/componentFixtures/.screenshots/report.md ]; then - BODY+=$(cat test/componentFixtures/.screenshots/report.md) - BODY+=$'\n\n' - BODY+="📦 [Download the \`screenshot-diff\` artifact](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) to review images." - else - BODY+="## Screenshots ✅"$'\n\n' - BODY+="No visual changes detected." - fi - - # Find existing comment - EXISTING=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ - --paginate --jq ".[] | select(.body | startswith(\"$COMMENT_MARKER\")) | .id" | head -1) - - if [ -n "$EXISTING" ]; then - gh api "repos/${{ github.repository }}/issues/comments/$EXISTING" -X PATCH -f body="$BODY" - else - gh pr comment "${{ github.event.pull_request.number }}" --body "$BODY" - fi + # - name: Post PR comment + # if: github.event_name == 'pull_request' + # env: + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # COMMENT_MARKER="" + # BODY="$COMMENT_MARKER"$'\n' + # + # if [ -f test/componentFixtures/.screenshots/report.md ]; then + # BODY+=$(cat test/componentFixtures/.screenshots/report.md) + # BODY+=$'\n\n' + # BODY+="📦 [Download the \`screenshot-diff\` artifact](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) to review images." + # else + # BODY+="## Screenshots ✅"$'\n\n' + # BODY+="No visual changes detected." + # fi + # + # # Find existing comment + # EXISTING=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ + # --paginate --jq ".[] | select(.body | startswith(\"$COMMENT_MARKER\")) | .id" | head -1) + # + # if [ -n "$EXISTING" ]; then + # gh api "repos/${{ github.repository }}/issues/comments/$EXISTING" -X PATCH -f body="$BODY" + # else + # gh pr comment "${{ github.event.pull_request.number }}" --body "$BODY" + # fi