screenshot-test-comment.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. name: Screenshot Test PR Comment
  2. # This workflow is designed to safely comment on PRs from forks
  3. # It uses pull_request_target which has higher permissions than pull_request
  4. # Security note: This workflow does NOT check out or execute code from the PR
  5. # It only monitors the status of the ScreenshotTests job and posts comments
  6. # (If this commenting was done in the main worflow it would not have the permissions
  7. # to create a comment)
  8. on:
  9. pull_request_target:
  10. types: [opened, synchronize, reopened]
  11. jobs:
  12. monitor-screenshot-tests:
  13. name: Monitor Screenshot Tests and Comment
  14. runs-on: ubuntu-latest
  15. timeout-minutes: 60
  16. permissions:
  17. pull-requests: write
  18. contents: read
  19. steps:
  20. - name: Wait for GitHub to register the workflow run
  21. run: sleep 15
  22. - name: Wait for Screenshot Tests to complete
  23. uses: lewagon/[email protected]
  24. with:
  25. ref: ${{ github.event.pull_request.head.sha }}
  26. check-name: 'Run Screenshot Tests'
  27. repo-token: ${{ secrets.GITHUB_TOKEN }}
  28. wait-interval: 10
  29. allowed-conclusions: success,skipped,failure
  30. - name: Check Screenshot Tests status
  31. id: check-status
  32. uses: actions/github-script@v6
  33. with:
  34. github-token: ${{ secrets.GITHUB_TOKEN }}
  35. script: |
  36. const { owner, repo } = context.repo;
  37. const ref = '${{ github.event.pull_request.head.sha }}';
  38. // Get workflow runs for the PR
  39. const runs = await github.rest.actions.listWorkflowRunsForRepo({
  40. owner,
  41. repo,
  42. head_sha: ref
  43. });
  44. // Find the ScreenshotTests job
  45. let screenshotTestRun = null;
  46. for (const run of runs.data.workflow_runs) {
  47. if (run.name === 'Build jMonkeyEngine') {
  48. const jobs = await github.rest.actions.listJobsForWorkflowRun({
  49. owner,
  50. repo,
  51. run_id: run.id
  52. });
  53. for (const job of jobs.data.jobs) {
  54. if (job.name === 'Run Screenshot Tests') {
  55. screenshotTestRun = job;
  56. break;
  57. }
  58. }
  59. if (screenshotTestRun) break;
  60. }
  61. }
  62. if (!screenshotTestRun) {
  63. console.log('Screenshot test job not found');
  64. return;
  65. }
  66. // Check if the job failed
  67. if (screenshotTestRun.conclusion === 'failure') {
  68. core.setOutput('failed', 'true');
  69. } else {
  70. core.setOutput('failed', 'false');
  71. }
  72. - name: Find Existing Comment
  73. uses: peter-evans/find-comment@v3
  74. id: existingCommentId
  75. with:
  76. issue-number: ${{ github.event.pull_request.number }}
  77. comment-author: 'github-actions[bot]'
  78. body-includes: Screenshot tests have failed.
  79. - name: Comment on PR if tests fail
  80. if: steps.check-status.outputs.failed == 'true'
  81. uses: peter-evans/create-or-update-comment@v4
  82. with:
  83. issue-number: ${{ github.event.pull_request.number }}
  84. body: |
  85. 🖼️ **Screenshot tests have failed.**
  86. The purpose of these tests is to ensure that changes introduced in this PR don't break visual features. They are visual unit tests.
  87. 📄 **Where to find the report:**
  88. - Go to the (failed run) > Summary > Artifacts > screenshot-test-report
  89. - Download the zip and open jme3-screenshot-tests/build/reports/ScreenshotDiffReport.html
  90. ⚠️ **If you didn't expect to change anything visual:**
  91. Fix your changes so the screenshot tests pass.
  92. ✅ **If you did mean to change things:**
  93. Review the replacement images in jme3-screenshot-tests/build/changed-images to make sure they really are improvements and then replace and commit the replacement images at jme3-screenshot-tests/src/test/resources.
  94. ✨ **If you are creating entirely new tests:**
  95. Find the new images in jme3-screenshot-tests/build/changed-images and commit the new images at jme3-screenshot-tests/src/test/resources.
  96. **Note;** it is very important that the committed reference images are created on the build pipeline, locally created images are not reliable. Similarly tests will fail locally but you can look at the report to check they are "visually similar".
  97. See https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-screenshot-tests/README.md for more information
  98. Contact @richardTingle (aka richtea) for guidance if required
  99. edit-mode: replace
  100. comment-id: ${{ steps.existingCommentId.outputs.comment-id }}