mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 17:10:07 +00:00
- Split Playwright tests into 5 shards to reduce CI runtime from 17min to ~3-4min - Each browser now runs tests in 5 parallel jobs (20 total jobs: 4 browsers × 5 shards) - Updated test-ui.yaml workflow to use matrix strategy with sharding - Added merge-reports job to consolidate test results - Updated pr-playwright-deploy.yaml to handle sharded test reports - Merge sharded reports before deploying to Cloudflare Pages This change will significantly improve CI/CD performance by running tests in parallel, matching the runtime of other workflows (~3-4 minutes). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
326 lines
12 KiB
YAML
326 lines
12 KiB
YAML
name: PR Playwright Deploy and Comment
|
||
|
||
on:
|
||
workflow_run:
|
||
workflows: ["Tests CI"]
|
||
types: [requested, completed]
|
||
|
||
env:
|
||
DATE_FORMAT: '+%m/%d/%Y, %I:%M:%S %p'
|
||
|
||
jobs:
|
||
deploy-reports:
|
||
runs-on: ubuntu-latest
|
||
if: github.repository == 'Comfy-Org/ComfyUI_frontend' && github.event.workflow_run.event == 'pull_request' && github.event.action == 'completed'
|
||
permissions:
|
||
actions: read
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
browser: [chromium, chromium-2x, chromium-0.5x, mobile-chrome]
|
||
steps:
|
||
- name: Get PR info
|
||
id: pr-info
|
||
uses: actions/github-script@v7
|
||
with:
|
||
script: |
|
||
const { data: pullRequests } = await github.rest.pulls.list({
|
||
owner: context.repo.owner,
|
||
repo: context.repo.repo,
|
||
state: 'open',
|
||
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`,
|
||
});
|
||
|
||
if (pullRequests.length === 0) {
|
||
console.log('No open PR found for this branch');
|
||
return { number: null, sanitized_branch: null };
|
||
}
|
||
|
||
const pr = pullRequests[0];
|
||
const branchName = context.payload.workflow_run.head_branch;
|
||
const sanitizedBranch = branchName.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/^-|-$/g, '');
|
||
|
||
return {
|
||
number: pr.number,
|
||
sanitized_branch: sanitizedBranch
|
||
};
|
||
|
||
- name: Set project name
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
id: project-name
|
||
run: |
|
||
if [ "${{ matrix.browser }}" = "chromium-0.5x" ]; then
|
||
echo "name=comfyui-playwright-chromium-0-5x" >> $GITHUB_OUTPUT
|
||
else
|
||
echo "name=comfyui-playwright-${{ matrix.browser }}" >> $GITHUB_OUTPUT
|
||
fi
|
||
echo "branch=${{ fromJSON(steps.pr-info.outputs.result).sanitized_branch }}" >> $GITHUB_OUTPUT
|
||
|
||
- name: Install pnpm
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
uses: pnpm/action-setup@v4
|
||
with:
|
||
version: 10
|
||
|
||
- uses: actions/setup-node@v4
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
with:
|
||
node-version: lts/*
|
||
|
||
- name: Download playwright report shards
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||
run-id: ${{ github.event.workflow_run.id }}
|
||
pattern: playwright-report-${{ matrix.browser }}-shard-*
|
||
path: playwright-shards
|
||
|
||
- name: Install Playwright
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
run: npm install @playwright/test
|
||
|
||
- name: Merge reports
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
run: |
|
||
npx playwright merge-reports --reporter html ./playwright-shards
|
||
mv playwright-report merged-report
|
||
|
||
- name: Rename merged report
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
run: mv merged-report playwright-report
|
||
|
||
- name: Install Wrangler
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
run: npm install -g wrangler
|
||
|
||
- name: Deploy to Cloudflare Pages (${{ matrix.browser }})
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
id: cloudflare-deploy
|
||
continue-on-error: true
|
||
run: |
|
||
# Retry logic for wrangler deploy (3 attempts)
|
||
RETRY_COUNT=0
|
||
MAX_RETRIES=3
|
||
SUCCESS=false
|
||
DEPLOYMENT_URL=""
|
||
|
||
while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ $SUCCESS = false ]; do
|
||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||
echo "Deployment attempt $RETRY_COUNT of $MAX_RETRIES..."
|
||
|
||
OUTPUT=$(npx wrangler pages deploy playwright-report --project-name=${{ steps.project-name.outputs.name }} --branch=${{ steps.project-name.outputs.branch }} 2>&1)
|
||
EXIT_CODE=$?
|
||
|
||
if [ $EXIT_CODE -eq 0 ]; then
|
||
SUCCESS=true
|
||
DEPLOYMENT_URL=$(echo "$OUTPUT" | grep -oE 'https://[^ ]+\.pages\.dev' | head -1)
|
||
echo "Deployment successful on attempt $RETRY_COUNT"
|
||
echo "URL: $DEPLOYMENT_URL"
|
||
else
|
||
echo "Deployment failed on attempt $RETRY_COUNT"
|
||
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
|
||
echo "Retrying in 10 seconds..."
|
||
sleep 10
|
||
fi
|
||
fi
|
||
done
|
||
|
||
if [ $SUCCESS = false ]; then
|
||
echo "All deployment attempts failed"
|
||
exit 1
|
||
fi
|
||
|
||
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
|
||
env:
|
||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||
|
||
- name: Save deployment info
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
run: |
|
||
echo "${{ matrix.browser }}|${{ steps.cloudflare-deploy.outcome == 'success' && '0' || '1' }}|${{ steps.cloudflare-deploy.outputs.deployment_url || '#' }}" > deployment-info-${{ matrix.browser }}.txt
|
||
|
||
- name: Upload deployment info
|
||
if: fromJSON(steps.pr-info.outputs.result).number != null
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: deployment-info-${{ matrix.browser }}
|
||
path: deployment-info-${{ matrix.browser }}.txt
|
||
retention-days: 1
|
||
|
||
comment-tests-starting:
|
||
runs-on: ubuntu-latest
|
||
if: github.repository == 'Comfy-Org/ComfyUI_frontend' && github.event.workflow_run.event == 'pull_request' && github.event.action == 'requested'
|
||
permissions:
|
||
pull-requests: write
|
||
actions: read
|
||
steps:
|
||
- name: Get PR number
|
||
id: pr
|
||
uses: actions/github-script@v7
|
||
with:
|
||
script: |
|
||
const { data: pullRequests } = await github.rest.pulls.list({
|
||
owner: context.repo.owner,
|
||
repo: context.repo.repo,
|
||
state: 'open',
|
||
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`,
|
||
});
|
||
|
||
if (pullRequests.length === 0) {
|
||
console.log('No open PR found for this branch');
|
||
return null;
|
||
}
|
||
|
||
return pullRequests[0].number;
|
||
|
||
- name: Get completion time
|
||
id: completion-time
|
||
run: echo "time=$(date -u '${{ env.DATE_FORMAT }}')" >> $GITHUB_OUTPUT
|
||
|
||
- name: Generate comment body for start
|
||
if: steps.pr.outputs.result != 'null'
|
||
id: comment-body-start
|
||
run: |
|
||
echo "<!-- PLAYWRIGHT_TEST_STATUS -->" > comment.md
|
||
echo "## 🎭 Playwright Test Results" >> comment.md
|
||
echo "" >> comment.md
|
||
echo "<img alt='comfy-loading-gif' src='https://github.com/user-attachments/assets/755c86ee-e445-4ea8-bc2c-cca85df48686' width='14px' height='14px' style='vertical-align: middle; margin-right: 4px;' /> **Tests are starting...** " >> comment.md
|
||
echo "" >> comment.md
|
||
echo "⏰ Started at: ${{ steps.completion-time.outputs.time }} UTC" >> comment.md
|
||
echo "" >> comment.md
|
||
echo "### 🚀 Running Tests (5 parallel shards per browser)" >> comment.md
|
||
echo "- 🧪 **chromium**: Running tests in 5 shards..." >> comment.md
|
||
echo "- 🧪 **chromium-0.5x**: Running tests in 5 shards..." >> comment.md
|
||
echo "- 🧪 **chromium-2x**: Running tests in 5 shards..." >> comment.md
|
||
echo "- 🧪 **mobile-chrome**: Running tests in 5 shards..." >> comment.md
|
||
echo "" >> comment.md
|
||
echo "---" >> comment.md
|
||
echo "⏱️ Tests are running in parallel across 20 jobs (4 browsers × 5 shards)..." >> comment.md
|
||
|
||
- name: Comment PR - Tests Started
|
||
if: steps.pr.outputs.result != 'null'
|
||
uses: edumserrano/find-create-or-update-comment@82880b65c8a3a6e4c70aa05a204995b6c9696f53 # v3.0.0
|
||
with:
|
||
issue-number: ${{ steps.pr.outputs.result }}
|
||
body-includes: '<!-- PLAYWRIGHT_TEST_STATUS -->'
|
||
comment-author: 'github-actions[bot]'
|
||
edit-mode: replace
|
||
body-path: comment.md
|
||
|
||
comment-tests-completed:
|
||
runs-on: ubuntu-latest
|
||
needs: deploy-reports
|
||
if: github.repository == 'Comfy-Org/ComfyUI_frontend' && github.event.workflow_run.event == 'pull_request' && github.event.action == 'completed' && always()
|
||
permissions:
|
||
pull-requests: write
|
||
actions: read
|
||
steps:
|
||
- name: Get PR number
|
||
id: pr
|
||
uses: actions/github-script@v7
|
||
with:
|
||
script: |
|
||
const { data: pullRequests } = await github.rest.pulls.list({
|
||
owner: context.repo.owner,
|
||
repo: context.repo.repo,
|
||
state: 'open',
|
||
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`,
|
||
});
|
||
|
||
if (pullRequests.length === 0) {
|
||
console.log('No open PR found for this branch');
|
||
return null;
|
||
}
|
||
|
||
return pullRequests[0].number;
|
||
|
||
- name: Download all deployment info
|
||
if: steps.pr.outputs.result != 'null'
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||
run-id: ${{ github.event.workflow_run.id }}
|
||
pattern: deployment-info-*
|
||
merge-multiple: true
|
||
path: deployment-info
|
||
|
||
- name: Get completion time
|
||
id: completion-time
|
||
run: echo "time=$(date -u '${{ env.DATE_FORMAT }}')" >> $GITHUB_OUTPUT
|
||
|
||
- name: Generate comment body for completion
|
||
if: steps.pr.outputs.result != 'null'
|
||
id: comment-body-completed
|
||
run: |
|
||
echo "<!-- PLAYWRIGHT_TEST_STATUS -->" > comment.md
|
||
echo "## 🎭 Playwright Test Results" >> comment.md
|
||
echo "" >> comment.md
|
||
|
||
# Check if all tests passed
|
||
ALL_PASSED=true
|
||
for file in deployment-info/*.txt; do
|
||
if [ -f "$file" ]; then
|
||
browser=$(basename "$file" .txt)
|
||
info=$(cat "$file")
|
||
exit_code=$(echo "$info" | cut -d'|' -f2)
|
||
if [ "$exit_code" != "0" ]; then
|
||
ALL_PASSED=false
|
||
break
|
||
fi
|
||
fi
|
||
done
|
||
|
||
if [ "$ALL_PASSED" = "true" ]; then
|
||
echo "✅ **All tests passed across all browsers!**" >> comment.md
|
||
else
|
||
echo "❌ **Some tests failed!**" >> comment.md
|
||
fi
|
||
|
||
echo "" >> comment.md
|
||
echo "⏰ Completed at: ${{ steps.completion-time.outputs.time }} UTC" >> comment.md
|
||
echo "" >> comment.md
|
||
echo "### 📊 Test Reports by Browser" >> comment.md
|
||
|
||
for file in deployment-info/*.txt; do
|
||
if [ -f "$file" ]; then
|
||
browser=$(basename "$file" .txt)
|
||
info=$(cat "$file")
|
||
exit_code=$(echo "$info" | cut -d'|' -f2)
|
||
url=$(echo "$info" | cut -d'|' -f3)
|
||
|
||
# Validate URLs before using them in comments
|
||
sanitized_url=$(echo "$url" | grep -E '^https://[a-z0-9.-]+\.pages\.dev(/.*)?$' || echo "INVALID_URL")
|
||
if [ "$sanitized_url" = "INVALID_URL" ]; then
|
||
echo "Invalid deployment URL detected: $url"
|
||
url="#" # Use safe fallback
|
||
fi
|
||
|
||
if [ "$exit_code" = "0" ]; then
|
||
status="✅"
|
||
else
|
||
status="❌"
|
||
fi
|
||
|
||
echo "- $status **$browser**: [View Report]($url)" >> comment.md
|
||
fi
|
||
done
|
||
|
||
echo "" >> comment.md
|
||
echo "---" >> comment.md
|
||
if [ "$ALL_PASSED" = "true" ]; then
|
||
echo "🎉 Your tests are passing across all browsers!" >> comment.md
|
||
else
|
||
echo "⚠️ Please check the test reports for details on failures." >> comment.md
|
||
fi
|
||
|
||
- name: Comment PR - Tests Complete
|
||
if: steps.pr.outputs.result != 'null'
|
||
uses: edumserrano/find-create-or-update-comment@82880b65c8a3a6e4c70aa05a204995b6c9696f53 # v3.0.0
|
||
with:
|
||
issue-number: ${{ steps.pr.outputs.result }}
|
||
body-includes: '<!-- PLAYWRIGHT_TEST_STATUS -->'
|
||
comment-author: 'github-actions[bot]'
|
||
edit-mode: replace
|
||
body-path: comment.md |