Skip to content

Helper: comment PR with visual tests report #193

Helper: comment PR with visual tests report

Helper: comment PR with visual tests report #193

# Copyright (C) 2023 Dynamic Solutions
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This workflow adds a comment to the current PR with visual tests report.
# It must be triggered at the completion of CI workflow, because GH Actions artifacts are not available until the workflow is completed.
# And we need an URL of the artifact to add it to the comment.
# Read more here:
# - https://github.com/actions/upload-artifact/issues/50
# - https://github.com/orgs/community/discussions/51403
name: 'Helper: comment PR with visual tests report'
on:
workflow_run:
types:
- completed
workflows:
- 'CI: verify build'
jobs:
comment-on-pr:
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Artifact and Pull request info
env:
GITHUB_TOKEN: ${{ github.token }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: ./.github/scripts/helper-visual-test-get-report-url.sh
- name: Get current date
id: currentDateStep
run: echo "CURRENT_DATE=$(date +'%Y-%m-%dT%H%M%S')" >> "$GITHUB_OUTPUT"
- name: Add a comment
if: "${{ env.ARTIFACT_ID != '' }}"
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}"
HEAD_SHA: "${{ env.HEAD_SHA }}"
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ env.PR_NUMBER }}
body: |
## ⚠️ Visual tests status
Some visual changes require review.
Please download BackstopJS report and check if there is no visual regression.
Please note that the report only stay for 1 day!
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ env.JOB_PATH }} |
| Report | [visual-tests-report_${{ steps.currentDateStep.outputs.CURRENT_DATE }}.zip](${{ env.ARTIFACT_URL }}) |
- name: Add a comment
if: "${{ env.ARTIFACT_ID == '' }}"
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
HEAD_SHA: "${{ env.HEAD_SHA }}"
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ env.PR_NUMBER }}
body: |
## ✅ Visual tests status
No visual changes detected.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ env.JOB_PATH }} |
- name: Add a comment on job failure
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ env.PR_NUMBER }}
body: ❌ Failed to add visual tests status!