|
4 | 4 | issue_comment: |
5 | 5 | types: [created] |
6 | 6 |
|
| 7 | +# Prevent concurrent runs per PR |
| 8 | +concurrency: |
| 9 | + group: full-ci-${{ github.event.issue.number }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
7 | 12 | jobs: |
8 | 13 | trigger-full-ci: |
9 | 14 | # Only run on PR comments that match the command |
10 | 15 | if: | |
11 | 16 | github.event.issue.pull_request && |
12 | | - contains(github.event.comment.body, '/run-full-ci') |
| 17 | + ( |
| 18 | + startsWith(github.event.comment.body, '/run-full-ci') || |
| 19 | + contains(github.event.comment.body, '\n/run-full-ci') |
| 20 | + ) |
13 | 21 | runs-on: ubuntu-22.04 |
14 | 22 | permissions: |
15 | 23 | contents: read |
16 | 24 | pull-requests: write |
17 | 25 | actions: write |
18 | 26 | steps: |
| 27 | + - name: Check if user has write access |
| 28 | + id: check_access |
| 29 | + uses: actions/github-script@v7 |
| 30 | + with: |
| 31 | + script: | |
| 32 | + try { |
| 33 | + const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + username: context.actor |
| 37 | + }); |
| 38 | +
|
| 39 | + const hasAccess = ['admin', 'write'].includes(permission.permission); |
| 40 | + console.log(`User ${context.actor} has permission: ${permission.permission}`); |
| 41 | +
|
| 42 | + if (!hasAccess) { |
| 43 | + await github.rest.issues.createComment({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + issue_number: context.issue.number, |
| 47 | + body: `@${context.actor} Sorry, only repository collaborators with write access can trigger full CI runs. 🔒` |
| 48 | + }); |
| 49 | + } |
| 50 | +
|
| 51 | + return hasAccess; |
| 52 | + } catch (error) { |
| 53 | + console.error('Error checking permissions:', error); |
| 54 | + return false; |
| 55 | + } |
| 56 | +
|
| 57 | + - name: Exit if no access |
| 58 | + if: steps.check_access.outputs.result == 'false' |
| 59 | + run: | |
| 60 | + echo "User does not have permission to trigger full CI" |
| 61 | + exit 1 |
| 62 | +
|
19 | 63 | - name: Add reaction to comment |
20 | 64 | uses: peter-evans/create-or-update-comment@v4 |
21 | 65 | with: |
@@ -52,70 +96,59 @@ jobs: |
52 | 96 |
|
53 | 97 | View progress in the [Actions tab](${{ github.server_url }}/${{ github.repository }}/actions). |
54 | 98 |
|
55 | | - - name: Trigger main workflow |
| 99 | + - name: Trigger all workflows and collect results |
| 100 | + id: trigger_workflows |
56 | 101 | uses: actions/github-script@v7 |
57 | 102 | with: |
58 | 103 | script: | |
59 | 104 | const prData = ${{ steps.pr.outputs.result }}; |
60 | | - try { |
61 | | - await github.rest.actions.createWorkflowDispatch({ |
62 | | - owner: context.repo.owner, |
63 | | - repo: context.repo.repo, |
64 | | - workflow_id: 'main.yml', |
65 | | - ref: prData.ref |
66 | | - }); |
67 | | - console.log('✅ Triggered main.yml'); |
68 | | - } catch (error) { |
69 | | - console.error('❌ Failed to trigger main.yml:', error.message); |
70 | | - } |
| 105 | + const workflows = [ |
| 106 | + 'main.yml', |
| 107 | + 'examples.yml', |
| 108 | + 'pro-integration-tests.yml', |
| 109 | + 'pro-package-tests.yml' |
| 110 | + ]; |
71 | 111 |
|
72 | | - - name: Trigger examples workflow |
73 | | - uses: actions/github-script@v7 |
74 | | - with: |
75 | | - script: | |
76 | | - const prData = ${{ steps.pr.outputs.result }}; |
77 | | - try { |
78 | | - await github.rest.actions.createWorkflowDispatch({ |
79 | | - owner: context.repo.owner, |
80 | | - repo: context.repo.repo, |
81 | | - workflow_id: 'examples.yml', |
82 | | - ref: prData.ref |
83 | | - }); |
84 | | - console.log('✅ Triggered examples.yml'); |
85 | | - } catch (error) { |
86 | | - console.error('❌ Failed to trigger examples.yml:', error.message); |
87 | | - } |
| 112 | + const succeeded = []; |
| 113 | + const failed = []; |
88 | 114 |
|
89 | | - - name: Trigger Pro integration tests |
90 | | - uses: actions/github-script@v7 |
91 | | - with: |
92 | | - script: | |
93 | | - const prData = ${{ steps.pr.outputs.result }}; |
94 | | - try { |
95 | | - await github.rest.actions.createWorkflowDispatch({ |
96 | | - owner: context.repo.owner, |
97 | | - repo: context.repo.repo, |
98 | | - workflow_id: 'pro-integration-tests.yml', |
99 | | - ref: prData.ref |
100 | | - }); |
101 | | - console.log('✅ Triggered pro-integration-tests.yml'); |
102 | | - } catch (error) { |
103 | | - console.error('❌ Failed to trigger pro-integration-tests.yml:', error.message); |
| 115 | + for (const workflowId of workflows) { |
| 116 | + try { |
| 117 | + await github.rest.actions.createWorkflowDispatch({ |
| 118 | + owner: context.repo.owner, |
| 119 | + repo: context.repo.repo, |
| 120 | + workflow_id: workflowId, |
| 121 | + ref: prData.ref |
| 122 | + }); |
| 123 | + console.log(`✅ Triggered ${workflowId}`); |
| 124 | + succeeded.push(workflowId); |
| 125 | + } catch (error) { |
| 126 | + console.error(`❌ Failed to trigger ${workflowId}:`, error.message); |
| 127 | + failed.push(workflowId); |
| 128 | + } |
104 | 129 | } |
105 | 130 |
|
106 | | - - name: Trigger Pro package tests |
107 | | - uses: actions/github-script@v7 |
108 | | - with: |
109 | | - script: | |
110 | | - const prData = ${{ steps.pr.outputs.result }}; |
111 | | - try { |
112 | | - await github.rest.actions.createWorkflowDispatch({ |
113 | | - owner: context.repo.owner, |
114 | | - repo: context.repo.repo, |
115 | | - workflow_id: 'pro-package-tests.yml', |
116 | | - ref: prData.ref |
117 | | - }); |
118 | | - console.log('✅ Triggered pro-package-tests.yml'); |
119 | | - } catch (error) { |
120 | | - console.error('❌ Failed to trigger pro-package-tests.yml:', error.message); |
| 131 | + // Build the comment body |
| 132 | + const status = failed.length === 0 ? '✅ **Successfully triggered all workflows**' : '⚠️ **Some workflows failed to trigger**'; |
| 133 | + const succeededList = succeeded.length > 0 ? succeeded.map(w => `- ✅ ${w}`).join('\n') : '- None'; |
| 134 | + const failedList = failed.length > 0 ? `\n\n**Failed workflows:**\n${failed.map(w => `- ❌ ${w}`).join('\n')}` : ''; |
| 135 | +
|
| 136 | + const body = `${status} |
| 137 | +
|
| 138 | + **Triggered workflows:** |
| 139 | + ${succeededList}${failedList} |
| 140 | +
|
| 141 | + View progress in the [Actions tab](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions).`; |
| 142 | +
|
| 143 | + // Post the comment |
| 144 | + await github.rest.issues.createComment({ |
| 145 | + owner: context.repo.owner, |
| 146 | + repo: context.repo.repo, |
| 147 | + issue_number: context.issue.number, |
| 148 | + body: body |
| 149 | + }); |
| 150 | +
|
| 151 | + // Fail the job if any workflows failed to trigger |
| 152 | + if (failed.length > 0) { |
| 153 | + core.setFailed(`Failed to trigger ${failed.length} workflow(s): ${failed.join(', ')}`); |
121 | 154 | } |
0 commit comments