|
| 1 | +name: Stop Full CI Suite |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + stop-full-ci: |
| 9 | + # Only run on PR comments that match the command |
| 10 | + if: | |
| 11 | + github.event.issue.pull_request && |
| 12 | + ( |
| 13 | + startsWith(github.event.comment.body, '/stop-run-skipped-ci') || |
| 14 | + contains(github.event.comment.body, '\n/stop-run-skipped-ci') |
| 15 | + ) |
| 16 | + runs-on: ubuntu-22.04 |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + issues: write |
| 21 | + steps: |
| 22 | + - name: Check if user has write access |
| 23 | + id: check_access |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + try { |
| 28 | + const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + username: context.actor |
| 32 | + }); |
| 33 | +
|
| 34 | + const hasAccess = ['admin', 'write'].includes(permission.permission); |
| 35 | + console.log(`User ${context.actor} has permission: ${permission.permission}`); |
| 36 | +
|
| 37 | + if (!hasAccess) { |
| 38 | + await github.rest.issues.createComment({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + issue_number: context.issue.number, |
| 42 | + body: `@${context.actor} Sorry, only repository collaborators with write access can stop full CI runs. 🔒` |
| 43 | + }); |
| 44 | + } |
| 45 | +
|
| 46 | + return hasAccess; |
| 47 | + } catch (error) { |
| 48 | + console.error('Error checking permissions:', error); |
| 49 | + return false; |
| 50 | + } |
| 51 | +
|
| 52 | + - name: Exit if no access |
| 53 | + if: steps.check_access.outputs.result == 'false' |
| 54 | + run: | |
| 55 | + echo "User does not have permission to stop full CI" |
| 56 | + exit 1 |
| 57 | +
|
| 58 | + - name: Add reaction to comment |
| 59 | + uses: peter-evans/create-or-update-comment@v4 |
| 60 | + with: |
| 61 | + comment-id: ${{ github.event.comment.id }} |
| 62 | + reactions: 'eyes' |
| 63 | + |
| 64 | + - name: Remove full-ci label |
| 65 | + uses: actions/github-script@v7 |
| 66 | + with: |
| 67 | + script: | |
| 68 | + try { |
| 69 | + await github.rest.issues.removeLabel({ |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + issue_number: context.issue.number, |
| 73 | + name: 'full-ci' |
| 74 | + }); |
| 75 | + console.log('✅ Removed full-ci label from PR'); |
| 76 | +
|
| 77 | + // Post success comment |
| 78 | + await github.rest.issues.createComment({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + issue_number: context.issue.number, |
| 82 | + body: `✅ **Full CI Mode Disabled** |
| 83 | +
|
| 84 | +The \`full-ci\` label has been removed. Future commits will use the standard CI suite (skipping tests for unchanged code). |
| 85 | + |
| 86 | +To re-enable full CI mode, use the \`/run-skipped-ci\` command.` |
| 87 | + }); |
| 88 | + } catch (error) { |
| 89 | + if (error.status === 404) { |
| 90 | + console.log('ℹ️ Label not found - already removed or never added'); |
| 91 | + await github.rest.issues.createComment({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + issue_number: context.issue.number, |
| 95 | + body: `ℹ️ **Full CI Mode Already Disabled** |
| 96 | +
|
| 97 | +The \`full-ci\` label is not present on this PR. CI is already running in standard mode.` |
| 98 | + }); |
| 99 | + } else { |
| 100 | + console.error('❌ Failed to remove label:', error); |
| 101 | + await github.rest.issues.createComment({ |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + issue_number: context.issue.number, |
| 105 | + body: `❌ **Error Removing Label** |
| 106 | +
|
| 107 | +Failed to remove the \`full-ci\` label: ${error.message}` |
| 108 | + }); |
| 109 | + throw error; |
| 110 | + } |
| 111 | + } |
0 commit comments