mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
This pull request updates the `.github/workflows/pr-update-playwright-expectations.yaml` workflow to improve how changed Playwright snapshot files are detected and handled, ensuring that both tracked and untracked (new) files are included throughout the process. The changes also add robustness to file operations and improve the accuracy of change summaries. **Improvements to snapshot detection and staging:** * The workflow now detects both tracked and untracked (new) snapshot files in `browser_tests/` when preparing changed files for staging, ensuring that new snapshots are not missed. * When copying changed files to the staging directory, the script now skips files that no longer exist (e.g., deleted files), preventing errors and unnecessary operations. **Enhancements to change summary and commit logic:** * The summary of changes now includes both tracked and untracked files in `browser_tests/`, and the output is expanded to show up to 50 files for better visibility. * The logic for determining whether there are changes to commit now checks for both tracked and untracked changes, ensuring commits are only made when necessary. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7423-Fix-snapshot-updates-commit-stage-2c76d73d36508195914ec92f37937e67) by [Unito](https://www.unito.io)
327 lines
12 KiB
YAML
327 lines
12 KiB
YAML
# Setting test expectation screenshots for Playwright
|
|
name: "PR: Update Playwright Expectations"
|
|
|
|
on:
|
|
pull_request:
|
|
types: [labeled]
|
|
issue_comment:
|
|
types: [created]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
setup:
|
|
runs-on: ubuntu-latest
|
|
if: >
|
|
( github.event_name == 'pull_request' && github.event.label.name == 'New Browser Test Expectations' ) ||
|
|
( github.event.issue.pull_request &&
|
|
github.event_name == 'issue_comment' &&
|
|
(
|
|
github.event.comment.author_association == 'OWNER' ||
|
|
github.event.comment.author_association == 'MEMBER' ||
|
|
github.event.comment.author_association == 'COLLABORATOR'
|
|
) &&
|
|
startsWith(github.event.comment.body, '/update-playwright') )
|
|
outputs:
|
|
cache-key: ${{ steps.cache-key.outputs.key }}
|
|
pr-number: ${{ steps.pr-info.outputs.pr-number }}
|
|
branch: ${{ steps.pr-info.outputs.branch }}
|
|
comment-id: ${{ steps.find-update-comment.outputs.comment-id }}
|
|
steps:
|
|
- name: Get PR info
|
|
id: pr-info
|
|
run: |
|
|
echo "pr-number=${{ github.event.number || github.event.issue.number }}" >> $GITHUB_OUTPUT
|
|
echo "branch=$(gh pr view ${{ github.event.number || github.event.issue.number }} --repo ${{ github.repository }} --json headRefName --jq '.headRefName')" >> $GITHUB_OUTPUT
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Find Update Comment
|
|
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad
|
|
id: "find-update-comment"
|
|
with:
|
|
issue-number: ${{ steps.pr-info.outputs.pr-number }}
|
|
comment-author: "github-actions[bot]"
|
|
body-includes: "Updating Playwright Expectations"
|
|
|
|
- name: Add Starting Reaction
|
|
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
|
|
with:
|
|
comment-id: ${{ steps.find-update-comment.outputs.comment-id }}
|
|
issue-number: ${{ steps.pr-info.outputs.pr-number }}
|
|
body: |
|
|
Updating Playwright Expectations
|
|
edit-mode: replace
|
|
reactions: eyes
|
|
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
ref: ${{ steps.pr-info.outputs.branch }}
|
|
- name: Setup frontend
|
|
uses: ./.github/actions/setup-frontend
|
|
with:
|
|
include_build_step: true
|
|
# Save expensive build artifacts (Python env, built frontend, node_modules)
|
|
# Source code will be checked out fresh in sharded jobs
|
|
- name: Generate cache key
|
|
id: cache-key
|
|
run: echo "key=$(date +%s)" >> $GITHUB_OUTPUT
|
|
- name: Save cache
|
|
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684
|
|
with:
|
|
path: |
|
|
ComfyUI
|
|
dist
|
|
key: comfyui-setup-${{ steps.cache-key.outputs.key }}
|
|
|
|
# Sharded snapshot updates
|
|
update-snapshots-sharded:
|
|
needs: setup
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
shardIndex: [1, 2, 3, 4]
|
|
shardTotal: [4]
|
|
steps:
|
|
# Checkout source code fresh (not cached)
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
ref: ${{ needs.setup.outputs.branch }}
|
|
|
|
# Restore expensive build artifacts from setup job
|
|
- name: Restore cached artifacts
|
|
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684
|
|
with:
|
|
fail-on-cache-miss: true
|
|
path: |
|
|
ComfyUI
|
|
dist
|
|
key: comfyui-setup-${{ needs.setup.outputs.cache-key }}
|
|
|
|
- name: Setup ComfyUI server (from cache)
|
|
uses: ./.github/actions/setup-comfyui-server
|
|
with:
|
|
launch_server: true
|
|
|
|
- name: Setup nodejs, pnpm, reuse built frontend
|
|
uses: ./.github/actions/setup-frontend
|
|
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
|
|
# Run sharded tests with snapshot updates
|
|
- name: Update snapshots (Shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }})
|
|
id: playwright-tests
|
|
run: pnpm exec playwright test --update-snapshots --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
|
continue-on-error: true
|
|
|
|
# Identify and stage only changed snapshot files
|
|
- name: Stage changed snapshot files
|
|
id: changed-snapshots
|
|
run: |
|
|
set -euo pipefail
|
|
echo "=========================================="
|
|
echo "STAGING CHANGED SNAPSHOTS (Shard ${{ matrix.shardIndex }})"
|
|
echo "=========================================="
|
|
|
|
# Get list of changed snapshot files (including untracked/new files)
|
|
changed_files=$( (
|
|
git diff --name-only browser_tests/ 2>/dev/null || true
|
|
git ls-files --others --exclude-standard browser_tests/ 2>/dev/null || true
|
|
) | sort -u | grep -E '\-snapshots/' || true )
|
|
|
|
if [ -z "$changed_files" ]; then
|
|
echo "No snapshot changes in this shard"
|
|
echo "has-changes=false" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
|
|
echo "✓ Found changed files:"
|
|
echo "$changed_files"
|
|
file_count=$(echo "$changed_files" | wc -l)
|
|
echo "Count: $file_count"
|
|
echo "has-changes=true" >> $GITHUB_OUTPUT
|
|
echo ""
|
|
|
|
# Create staging directory
|
|
mkdir -p /tmp/changed_snapshots_shard
|
|
|
|
# Copy only changed files, preserving directory structure
|
|
# Strip 'browser_tests/' prefix to avoid double nesting
|
|
echo "Copying changed files to staging directory..."
|
|
while IFS= read -r file; do
|
|
# Skip paths that no longer exist (e.g. deletions)
|
|
if [ ! -f "$file" ]; then
|
|
echo " → (skipped; not a file) $file"
|
|
continue
|
|
fi
|
|
# Remove 'browser_tests/' prefix
|
|
file_without_prefix="${file#browser_tests/}"
|
|
# Create parent directories
|
|
mkdir -p "/tmp/changed_snapshots_shard/$(dirname "$file_without_prefix")"
|
|
# Copy file
|
|
cp "$file" "/tmp/changed_snapshots_shard/$file_without_prefix"
|
|
echo " → $file_without_prefix"
|
|
done <<< "$changed_files"
|
|
|
|
echo ""
|
|
echo "Staged files for upload:"
|
|
find /tmp/changed_snapshots_shard -type f
|
|
|
|
# Upload ONLY the changed files from this shard
|
|
- name: Upload changed snapshots
|
|
uses: actions/upload-artifact@v4
|
|
if: steps.changed-snapshots.outputs.has-changes == 'true'
|
|
with:
|
|
name: snapshots-shard-${{ matrix.shardIndex }}
|
|
path: /tmp/changed_snapshots_shard/
|
|
retention-days: 1
|
|
|
|
- name: Upload test report
|
|
uses: actions/upload-artifact@v4
|
|
if: always()
|
|
with:
|
|
name: playwright-report-shard-${{ matrix.shardIndex }}
|
|
path: ./playwright-report/
|
|
retention-days: 30
|
|
|
|
# Merge snapshots and commit
|
|
merge-and-commit:
|
|
needs: [setup, update-snapshots-sharded]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
ref: ${{ needs.setup.outputs.branch }}
|
|
|
|
# Download all changed snapshot files from shards
|
|
- name: Download snapshot artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: snapshots-shard-*
|
|
path: ./downloaded-snapshots
|
|
merge-multiple: false
|
|
|
|
- name: List downloaded files
|
|
run: |
|
|
echo "=========================================="
|
|
echo "DOWNLOADED SNAPSHOT FILES"
|
|
echo "=========================================="
|
|
find ./downloaded-snapshots -type f
|
|
echo ""
|
|
echo "Total files: $(find ./downloaded-snapshots -type f | wc -l)"
|
|
|
|
# Merge only the changed files into browser_tests
|
|
- name: Merge changed snapshots
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "=========================================="
|
|
echo "MERGING CHANGED SNAPSHOTS"
|
|
echo "=========================================="
|
|
|
|
# Verify target directory exists
|
|
if [ ! -d "browser_tests" ]; then
|
|
echo "::error::Target directory 'browser_tests' does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
merged_count=0
|
|
|
|
# For each shard's changed files, copy them directly
|
|
for shard_dir in ./downloaded-snapshots/snapshots-shard-*/; do
|
|
if [ ! -d "$shard_dir" ]; then
|
|
continue
|
|
fi
|
|
|
|
shard_name=$(basename "$shard_dir")
|
|
file_count=$(find "$shard_dir" -type f | wc -l)
|
|
|
|
if [ "$file_count" -eq 0 ]; then
|
|
echo " $shard_name: no files"
|
|
continue
|
|
fi
|
|
|
|
echo "Processing $shard_name ($file_count file(s))..."
|
|
|
|
# Copy files directly, preserving directory structure
|
|
# Since files are already in correct structure (no browser_tests/ prefix), just copy them all
|
|
cp -v -r "$shard_dir"* browser_tests/ 2>&1 | sed 's/^/ /'
|
|
|
|
merged_count=$((merged_count + 1))
|
|
echo " ✓ Merged"
|
|
echo ""
|
|
done
|
|
|
|
echo "=========================================="
|
|
echo "MERGE COMPLETE"
|
|
echo "=========================================="
|
|
echo "Shards merged: $merged_count"
|
|
|
|
- name: Show changes
|
|
run: |
|
|
echo "=========================================="
|
|
echo "CHANGES SUMMARY"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Changed files in browser_tests (including untracked):"
|
|
CHANGES=$(git status --porcelain=v1 --untracked-files=all -- browser_tests/)
|
|
if [ -z "$CHANGES" ]; then
|
|
echo "No changes"
|
|
echo ""
|
|
echo "Total changes:"
|
|
echo "0"
|
|
else
|
|
echo "$CHANGES" | head -50
|
|
echo ""
|
|
echo "Total changes:"
|
|
echo "$CHANGES" | wc -l
|
|
fi
|
|
|
|
- name: Commit updated expectations
|
|
id: commit
|
|
run: |
|
|
git config --global user.name 'github-actions'
|
|
git config --global user.email 'github-actions@github.com'
|
|
|
|
if [ -z "$(git status --porcelain=v1 --untracked-files=all -- browser_tests/)" ]; then
|
|
echo "No changes to commit"
|
|
echo "has-changes=false" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
|
|
echo "=========================================="
|
|
echo "COMMITTING CHANGES"
|
|
echo "=========================================="
|
|
|
|
echo "has-changes=true" >> $GITHUB_OUTPUT
|
|
|
|
git add browser_tests/
|
|
git commit -m "[automated] Update test expectations"
|
|
|
|
echo "Pushing to ${{ needs.setup.outputs.branch }}..."
|
|
git push origin ${{ needs.setup.outputs.branch }}
|
|
|
|
echo "✓ Commit and push successful"
|
|
|
|
- name: Add Done Reaction
|
|
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
|
|
if: github.event_name == 'issue_comment' && steps.commit.outputs.has-changes == 'true'
|
|
with:
|
|
comment-id: ${{ needs.setup.outputs.comment-id }}
|
|
issue-number: ${{ needs.setup.outputs.pr-number }}
|
|
reactions: +1
|
|
reactions-edit-mode: replace
|
|
|
|
- name: Remove New Browser Test Expectations label
|
|
if: always() && github.event_name == 'pull_request'
|
|
run: gh pr edit ${{ needs.setup.outputs.pr-number }} --remove-label "New Browser Test Expectations"
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|