Fix Python 3.10/3.11 compatibility #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: Install openadapt-capture | |
| working-directory: openadapt-capture | |
| run: | | |
| uv pip install -e . | |
| - name: Install openadapt-viewer with screenshots extra | |
| working-directory: openadapt-viewer | |
| run: | | |
| uv pip install -e ".[screenshots]" | |
| - name: Install Playwright browsers | |
| working-directory: openadapt-viewer | |
| run: | | |
| uv run 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: | | |
| uv run 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 |