|
14 | 14 | push: |
15 | 15 | branches: [main] |
16 | 16 | paths-ignore: *ignore_paths |
| 17 | + repository_dispatch: |
| 18 | + types: [ ok-to-test-command ] |
17 | 19 |
|
18 | 20 | concurrency: |
19 | | - group: e2e-${{ github.event.pull_request.head.ref }} |
| 21 | + group: >- |
| 22 | + ${{ github.event_name == 'pull_request' && |
| 23 | + format('e2e-{0}', github.event.pull_request.head.ref) || |
| 24 | + format('e2e-{0}', github.event.client_payload.pull_request.head.ref) }} |
20 | 25 | cancel-in-progress: true # cancel previous job runs for the same branch |
21 | 26 |
|
22 | 27 | jobs: |
23 | 28 | check-external-pr: |
24 | 29 | runs-on: ubuntu-latest |
25 | | - if: github.event_name == 'pull_request' |
| 30 | + outputs: |
| 31 | + condition: ${{ steps.check.outputs.condition }} |
26 | 32 | steps: |
27 | 33 | - name: Check if PR is from external contributor |
| 34 | + id: check |
28 | 35 | run: | |
29 | | - if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
30 | | - echo "❌ External PR detected. This workflow requires approval from a maintainer." |
31 | | - echo "Please ask a maintainer to run '/ok-to-test' command to trigger the fork workflow." |
32 | | - exit 1 |
| 36 | + echo "Event name: ${{ github.event_name }}" |
| 37 | + echo "Repository: ${{ github.repository }}" |
| 38 | + |
| 39 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 40 | + # For pull_request events, check if PR is from external fork |
| 41 | + echo "PR head repo: ${{ github.event.pull_request.head.repo.full_name }}" |
| 42 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
| 43 | + echo "condition=skip" >> $GITHUB_OUTPUT |
| 44 | + echo "Setting condition=skip (external fork PR creation)" |
| 45 | + else |
| 46 | + echo "condition=pr-creation-maintainer" >> $GITHUB_OUTPUT |
| 47 | + echo "Setting condition=pr-creation-maintainer (internal PR creation)" |
| 48 | + fi |
| 49 | + elif [ "${{ github.event_name }}" == "repository_dispatch" ]; then |
| 50 | + # For repository_dispatch events (ok-to-test), check if sha matches |
| 51 | + SHA_PARAM="${{ github.event.client_payload.slash_command.args.named.sha }}" |
| 52 | + PR_HEAD_SHA="${{ github.event.client_payload.pull_request.head.sha }}" |
| 53 | + |
| 54 | + echo "Checking dispatch event conditions..." |
| 55 | + echo "SHA from command: $SHA_PARAM" |
| 56 | + echo "PR head SHA: $PR_HEAD_SHA" |
| 57 | + |
| 58 | + if [ -n "$SHA_PARAM" ] && [[ "$PR_HEAD_SHA" == *"$SHA_PARAM"* ]]; then |
| 59 | + echo "condition=dispatch-event" >> $GITHUB_OUTPUT |
| 60 | + echo "Setting condition=dispatch-event (sha matches)" |
| 61 | + else |
| 62 | + echo "condition=skip" >> $GITHUB_OUTPUT |
| 63 | + echo "Setting condition=skip (sha does not match or empty)" |
| 64 | + fi |
| 65 | + else |
| 66 | + # Unknown event type |
| 67 | + echo "condition=skip" >> $GITHUB_OUTPUT |
| 68 | + echo "Setting condition=skip (unknown event type: ${{ github.event_name }})" |
33 | 69 | fi |
34 | | - echo "✅ Internal PR detected. Proceeding with tests." |
35 | 70 |
|
36 | | - e2e-test: |
| 71 | + # Run tests for: |
| 72 | + # 1. Internal PRs on pull_request events |
| 73 | + # 2. External PRs on repository_dispatch (ok-to-test) events |
| 74 | + e2e: |
37 | 75 | needs: check-external-pr |
38 | | - if: always() && (needs.check-external-pr.result == 'success' || github.event_name != 'pull_request') |
| 76 | + if: | |
| 77 | + (needs.check-external-pr.outputs.condition == 'pr-creation-maintainer') |
| 78 | + || |
| 79 | + (needs.check-external-pr.outputs.condition == 'dispatch-event') |
39 | 80 | uses: ./.github/workflows/e2e-tests.yml |
40 | 81 | secrets: |
41 | 82 | OP_CONNECT_CREDENTIALS: ${{ secrets.OP_CONNECT_CREDENTIALS }} |
42 | 83 | OP_CONNECT_TOKEN: ${{ secrets.OP_CONNECT_TOKEN }} |
43 | 84 | OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} |
| 85 | + |
| 86 | + comment-pr: |
| 87 | + needs: [check-external-pr, e2e] |
| 88 | + runs-on: ubuntu-latest |
| 89 | + if: always() && needs.check-external-pr.outputs.condition == 'dispatch-event' |
| 90 | + permissions: |
| 91 | + pull-requests: write |
| 92 | + steps: |
| 93 | + - name: Create URL to the run output |
| 94 | + id: vars |
| 95 | + run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT |
| 96 | + |
| 97 | + - name: Create comment on PR |
| 98 | + uses: peter-evans/create-or-update-comment@v5 |
| 99 | + with: |
| 100 | + issue-number: ${{ github.event.client_payload.pull_request.number }} |
| 101 | + body: | |
| 102 | + ${{ |
| 103 | + needs.e2e-test.result == 'success' && '✅ E2E tests passed.' || |
| 104 | + needs.e2e-test.result == 'failure' && '❌ E2E tests failed.' || |
| 105 | + '⚠️ E2E tests completed.' |
| 106 | + }} |
| 107 | +
|
| 108 | + [View test run output][1] |
| 109 | +
|
| 110 | + [1]: ${{ steps.vars.outputs.run-url }} |
0 commit comments