-
Notifications
You must be signed in to change notification settings - Fork 4
222 lines (190 loc) · 7.97 KB
/
screenshots.yml
File metadata and controls
222 lines (190 loc) · 7.97 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Generate Screenshots
on:
workflow_dispatch:
inputs:
upload_artifacts:
description: 'Upload screenshots as artifacts'
required: false
type: boolean
default: true
push:
branches:
- main
paths:
- 'src/openadapt_viewer/**'
- 'scripts/generate_readme_screenshots.py'
- '.github/workflows/screenshots.yml'
pull_request:
paths:
- 'src/openadapt_viewer/**'
- 'scripts/generate_readme_screenshots.py'
jobs:
generate-screenshots:
name: Generate README Screenshots
runs-on: macos-latest
steps:
- name: Checkout openadapt-viewer
uses: actions/checkout@v4
with:
path: openadapt-viewer
- name: Checkout openadapt-capture
uses: actions/checkout@v4
with:
repository: OpenAdaptAI/openadapt-capture
path: openadapt-capture
# Use default branch or specific ref if needed
# ref: main
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python 3.11
run: uv python install 3.11
- name: Create shared virtual environment
run: uv venv --python 3.11 .venv
- name: Install openadapt-capture
working-directory: openadapt-capture
run: |
source ../.venv/bin/activate
uv pip install -e .
- name: Install openadapt-viewer with screenshots extra
working-directory: openadapt-viewer
run: |
source ../.venv/bin/activate
uv pip install -e ".[screenshots]"
- name: Install Playwright browsers
run: |
source .venv/bin/activate
playwright install chromium
- name: Check if captures exist
id: check-captures
working-directory: openadapt-capture
run: |
if [ -d "turn-off-nightshift" ] && [ -f "turn-off-nightshift/capture.db" ]; then
echo "nightshift_exists=true" >> $GITHUB_OUTPUT
else
echo "nightshift_exists=false" >> $GITHUB_OUTPUT
echo "⚠️ Warning: turn-off-nightshift capture not found"
fi
if [ -d "demo_new" ] && [ -f "demo_new/capture.db" ]; then
echo "demo_exists=true" >> $GITHUB_OUTPUT
else
echo "demo_exists=false" >> $GITHUB_OUTPUT
echo "⚠️ Warning: demo_new capture not found"
fi
- name: Generate screenshots
if: steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'
working-directory: openadapt-viewer
run: |
source ../.venv/bin/activate
python scripts/generate_readme_screenshots.py \
--capture-dir ../openadapt-capture \
--output-dir docs/images \
--max-events 50
continue-on-error: false
- name: Check generated screenshots
if: steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'
working-directory: openadapt-viewer
run: |
echo "📸 Generated screenshots:"
ls -lh docs/images/*.png || echo "No PNG files found"
echo ""
echo "📊 Screenshot details:"
for img in docs/images/*.png; do
if [ -f "$img" ]; then
size=$(du -h "$img" | cut -f1)
echo " - $(basename "$img"): $size"
fi
done
- name: Upload screenshots as artifacts
if: |
(github.event_name == 'workflow_dispatch' && github.event.inputs.upload_artifacts == 'true') ||
(github.event_name != 'workflow_dispatch' && (steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true'))
uses: actions/upload-artifact@v4
with:
name: readme-screenshots
path: openadapt-viewer/docs/images/*.png
if-no-files-found: warn
retention-days: 30
- name: Create pull request with screenshots (on main push)
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
(steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true')
uses: peter-evans/create-pull-request@v6
with:
path: openadapt-viewer
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "docs: update README screenshots"
title: "Update README screenshots"
body: |
## Automated Screenshot Update
This PR updates the README screenshots using the latest viewer code.
### Generated Screenshots
- Turn off Night Shift workflow
- Demo workflow examples
### Changes
- Updated screenshot images in `docs/images/`
Screenshots were automatically generated by the [Screenshots workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
branch: update-screenshots-${{ github.run_id }}
delete-branch: true
labels: documentation,automated
- name: Comment on PR with screenshot preview (on pull request)
if: |
github.event_name == 'pull_request' &&
(steps.check-captures.outputs.nightshift_exists == 'true' || steps.check-captures.outputs.demo_exists == 'true')
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const imagesDir = path.join(process.env.GITHUB_WORKSPACE, 'openadapt-viewer', 'docs', 'images');
let comment = '## 📸 Generated Screenshots Preview\n\n';
comment += 'Screenshots have been generated. Download the artifacts to preview them.\n\n';
if (fs.existsSync(imagesDir)) {
const files = fs.readdirSync(imagesDir).filter(f => f.endsWith('.png'));
if (files.length > 0) {
comment += '### Generated Files:\n';
files.forEach(file => {
const stats = fs.statSync(path.join(imagesDir, file));
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
comment += `- \`${file}\` (${sizeMB} MB)\n`;
});
}
}
comment += '\n---\n';
comment += `🔗 [Download screenshots artifact](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
- name: Summary
if: always()
run: |
echo "## Screenshot Generation Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check-captures.outputs.nightshift_exists }}" == "true" ]; then
echo "✅ turn-off-nightshift capture found" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ turn-off-nightshift capture not found" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.check-captures.outputs.demo_exists }}" == "true" ]; then
echo "✅ demo_new capture found" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ demo_new capture not found" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ -d "openadapt-viewer/docs/images" ]; then
echo "### Generated Screenshots" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for img in openadapt-viewer/docs/images/*.png; do
if [ -f "$img" ]; then
size=$(du -h "$img" | cut -f1)
echo "- $(basename "$img"): $size" >> $GITHUB_STEP_SUMMARY
fi
done
else
echo "⚠️ No screenshots generated" >> $GITHUB_STEP_SUMMARY
fi