mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-24 23:22:38 +08:00
ci: Add comment trigger to re-run E2E tests (#21452)
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
# Manually trigger E2E tests by commenting `/test-e2e` on a PR.
|
||||
# Dispatches the official "PR E2E" workflow to create the required "E2E - Checks" status.
|
||||
|
||||
name: E2E Tests on PR Comment
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
pull-requests: read
|
||||
contents: read
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
validate_and_prepare:
|
||||
name: Validate User and Get PR Details
|
||||
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-e2e')
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
permission_granted: ${{ steps.check_permissions.outputs.permission_granted }}
|
||||
head_sha: ${{ steps.check_permissions.outputs.head_sha }}
|
||||
|
||||
steps:
|
||||
- name: Validate User and Get PR Details
|
||||
id: check_permissions
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const commenter = context.actor;
|
||||
const issueOwner = context.repo.owner;
|
||||
const issueRepo = context.repo.repo;
|
||||
const commentId = context.payload.comment.id;
|
||||
const prNumber = context.issue.number;
|
||||
|
||||
// Function to add a reaction to the comment
|
||||
async function addReaction(content) {
|
||||
try {
|
||||
await github.rest.reactions.createForIssueComment({
|
||||
owner: issueOwner,
|
||||
repo: issueRepo,
|
||||
comment_id: commentId,
|
||||
content: content
|
||||
});
|
||||
} catch (reactionError) {
|
||||
console.log(`Failed to add reaction '${content}': ${reactionError.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize outputs
|
||||
core.setOutput('permission_granted', 'false');
|
||||
core.setOutput('head_sha', '');
|
||||
|
||||
// 1. Check user permissions
|
||||
try {
|
||||
const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
|
||||
owner: issueOwner,
|
||||
repo: issueRepo,
|
||||
username: commenter
|
||||
});
|
||||
|
||||
const allowedPermissions = ['admin', 'write', 'maintain'];
|
||||
if (!allowedPermissions.includes(permissions.permission)) {
|
||||
console.log(`User @${commenter} has '${permissions.permission}' permission. Needs 'admin', 'write', or 'maintain'.`);
|
||||
await addReaction('-1');
|
||||
return;
|
||||
}
|
||||
console.log(`User @${commenter} has '${permissions.permission}' permission.`);
|
||||
} catch (error) {
|
||||
console.log(`Could not verify permissions for @${commenter}: ${error.message}`);
|
||||
await addReaction('confused');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Fetch PR details
|
||||
try {
|
||||
const { data: pr } = await github.rest.pulls.get({
|
||||
owner: issueOwner,
|
||||
repo: issueRepo,
|
||||
pull_number: prNumber,
|
||||
});
|
||||
const headSha = pr.head.sha;
|
||||
console.log(`Fetched PR details: SHA - ${headSha}, PR Number - ${prNumber}`);
|
||||
|
||||
// Set outputs for next job
|
||||
core.setOutput('permission_granted', 'true');
|
||||
core.setOutput('head_sha', headSha);
|
||||
await addReaction('+1');
|
||||
} catch (error) {
|
||||
console.log(`Failed to fetch PR details for PR #${prNumber}: ${error.message}`);
|
||||
await addReaction('confused');
|
||||
}
|
||||
|
||||
dispatch_workflow:
|
||||
name: Dispatch E2E Workflow
|
||||
needs: validate_and_prepare
|
||||
if: needs.validate_and_prepare.outputs.permission_granted == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Trigger E2E Workflow
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh workflow run e2e-tests-pr.yml \
|
||||
--ref ${{ needs.validate_and_prepare.outputs.head_sha }} \
|
||||
--repo ${{ github.repository }}
|
||||
@@ -3,6 +3,7 @@ name: PR E2E
|
||||
on:
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: e2e-${{ github.event.pull_request.number || github.ref }}-${{github.event.review.state}}
|
||||
@@ -11,7 +12,7 @@ concurrency:
|
||||
jobs:
|
||||
eligibility_check:
|
||||
name: Check Eligibility for Test Run
|
||||
if: github.event.review.state == 'approved'
|
||||
if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
|
||||
uses: ./.github/workflows/check-run-eligibility.yml
|
||||
with:
|
||||
is_pr_approved_by_maintainer: true
|
||||
@@ -20,14 +21,21 @@ jobs:
|
||||
name: Playwright
|
||||
uses: ./.github/workflows/playwright-test-reusable.yml
|
||||
needs: [eligibility_check]
|
||||
if: needs.eligibility_check.outputs.should_run == 'true'
|
||||
# Run for approved PRs or manual triggers
|
||||
if: |
|
||||
always() &&
|
||||
((github.event_name == 'pull_request_review' && needs.eligibility_check.outputs.should_run == 'true') ||
|
||||
(github.event_name == 'workflow_dispatch'))
|
||||
secrets: inherit
|
||||
|
||||
post-e2e-tests:
|
||||
name: E2E - Checks
|
||||
runs-on: ubuntu-latest
|
||||
needs: [eligibility_check, run-playwright-tests]
|
||||
if: always() && needs.eligibility_check.result != 'skipped'
|
||||
if: |
|
||||
always() &&
|
||||
((github.event_name == 'pull_request_review' && needs.eligibility_check.result != 'skipped') ||
|
||||
(github.event_name == 'workflow_dispatch'))
|
||||
steps:
|
||||
- name: Fail if tests failed
|
||||
if: needs.run-playwright-tests.result == 'failure'
|
||||
|
||||
Reference in New Issue
Block a user