forked from bugsink/bugsink
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (143 loc) · 5.51 KB
/
Copy pathvisualshots-run.yml
File metadata and controls
164 lines (143 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Visualshots Run
on:
workflow_call:
inputs:
scenario:
required: true
type: string
ref:
required: true
type: string
base_branch:
required: true
type: string
artifact_prefix:
required: false
type: string
default: visualshots
playwright_version:
required: false
type: string
default: "1.61.0"
env:
DJANGO_SETTINGS_MODULE: "bugsink.settings.development"
HOME: "/root"
jobs:
visualshots:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright/python:v${{ inputs.playwright_version }}-noble
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Check out visualshots
uses: actions/checkout@v6
with:
repository: "bugsink/visualshots"
path: visualshots
- name: Check out event-samples
uses: actions/checkout@v6
with:
repository: "bugsink/event-samples"
path: event-samples
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements.development.txt
pip install "playwright==${{ inputs.playwright_version }}"
- name: Trust Bugsink checkout
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Fetch base branch
run: |
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
- name: Capture screenshots
env:
SAMPLES_DIR: ${{ github.workspace }}/event-samples
run: |
python visualshots/visualshots.py run \
--repo "$GITHUB_WORKSPACE" \
--scenario "${{ inputs.scenario }}" \
--after HEAD \
--base-branch "${{ inputs.base_branch }}" \
--out visualshots/results
- name: Prepare visual artifacts
id: visual_artifacts
shell: bash
run: |
set -euo pipefail
scenario_count=$(find visualshots/results -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')
echo "scenario_count=${scenario_count}" >> "$GITHUB_OUTPUT"
if [ "$scenario_count" = "1" ]; then
scenario_dir=$(find visualshots/results -mindepth 1 -maxdepth 1 -type d | head -n 1)
mkdir -p visualshots/artifacts
if [ -f "${scenario_dir}/before.png" ]; then
cp "${scenario_dir}/before.png" visualshots/artifacts/before.png
echo "has_before=true" >> "$GITHUB_OUTPUT"
else
echo "has_before=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "${scenario_dir}/before-dark.png" ]; then
cp "${scenario_dir}/before-dark.png" visualshots/artifacts/before-dark.png
echo "has_before_dark=true" >> "$GITHUB_OUTPUT"
else
echo "has_before_dark=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "${scenario_dir}/after.png" ]; then
cp "${scenario_dir}/after.png" visualshots/artifacts/after.png
echo "has_after=true" >> "$GITHUB_OUTPUT"
else
echo "has_after=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "${scenario_dir}/after-dark.png" ]; then
cp "${scenario_dir}/after-dark.png" visualshots/artifacts/after-dark.png
echo "has_after_dark=true" >> "$GITHUB_OUTPUT"
else
echo "has_after_dark=false" >> "$GITHUB_OUTPUT"
fi
else
echo "has_before=false" >> "$GITHUB_OUTPUT"
echo "has_before_dark=false" >> "$GITHUB_OUTPUT"
echo "has_after=false" >> "$GITHUB_OUTPUT"
echo "has_after_dark=false" >> "$GITHUB_OUTPUT"
fi
- name: Upload before screenshot
if: steps.visual_artifacts.outputs.scenario_count == '1' && steps.visual_artifacts.outputs.has_before == 'true'
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_prefix }}-before
path: visualshots/artifacts/before.png
archive: false
- name: Upload after screenshot
if: steps.visual_artifacts.outputs.scenario_count == '1' && steps.visual_artifacts.outputs.has_after == 'true'
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_prefix }}-after
path: visualshots/artifacts/after.png
archive: false
- name: Upload before dark screenshot
if: steps.visual_artifacts.outputs.scenario_count == '1' && steps.visual_artifacts.outputs.has_before_dark == 'true'
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_prefix }}-before-dark
path: visualshots/artifacts/before-dark.png
archive: false
- name: Upload after dark screenshot
if: steps.visual_artifacts.outputs.scenario_count == '1' && steps.visual_artifacts.outputs.has_after_dark == 'true'
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_prefix }}-after-dark
path: visualshots/artifacts/after-dark.png
archive: false
- name: Upload visual review bundle
if: steps.visual_artifacts.outputs.scenario_count != '1'
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_prefix }}
path: visualshots/results/
if-no-files-found: error