2525 - " test/testdata/**"
2626
2727jobs :
28+ # New Job: Checks permissions for PRs and outputs the result.
29+ check-permissions :
30+ name : Check PR author permissions
31+ # This job only runs for pull_request_target events.
32+ if : github.event_name == 'pull_request_target'
33+ runs-on : ubuntu-latest
34+ outputs :
35+ granted : ${{ steps.permission_check.outputs.result }}
36+ steps :
37+ - name : Check user permissions
38+ id : permission_check
39+ uses : actions/github-script@v7
40+ with :
41+ result-encoding : string # Capture the script's return value as an output
42+ script : |
43+ const actor = context.payload.pull_request.user.login;
44+
45+ // Allow dependabot and other bots unconditionally.
46+ if (actor.endsWith('[bot]')) {
47+ core.info(`User @${actor} is a bot, allowing.`);
48+ return 'true';
49+ }
50+
51+ try {
52+ const response = await github.rest.repos.getCollaboratorPermissionLevel({
53+ owner: context.repo.owner,
54+ repo: context.repo.repo,
55+ username: actor,
56+ });
57+
58+ const permission = response.data.permission;
59+ if (permission === 'admin' || permission === 'write') {
60+ core.info(`✅ User @${actor} has '${permission}' permission. Proceeding.`);
61+ return 'true';
62+ } else {
63+ core.warning(`User @${actor} has '${permission}' permission. 'write' or 'admin' is required. Skipping E2E tests.`);
64+ return 'false';
65+ }
66+ } catch (error) {
67+ core.warning(`Could not verify permission for @${actor}. They might not be a collaborator. Error: ${error.message}`);
68+ return 'false';
69+ }
70+
71+ # Modified Job: Now depends on the check-permissions job.
2872 e2e-tests :
29- # Run on schedule, unconditional workflow_dispatch,
30- # or pull_request_target if the actor has write/admin permissions .
73+ needs : [check-permissions] # It depends on the result of the check.
74+ # The job runs on schedule/dispatch, or on PRs if the check-permissions job granted access .
3175 if : >
3276 github.event_name == 'schedule' ||
3377 github.event_name == 'workflow_dispatch' ||
34- github.event_name == 'pull_request_target'
78+ ( github.event_name == 'pull_request_target' && needs.check-permissions.outputs.granted == 'true')
3579 concurrency :
3680 group : ${{ github.workflow }}-${{ matrix.provider }}-${{ github.event.pull_request.number || github.ref_name }}
3781 cancel-in-progress : true
@@ -68,39 +112,12 @@ jobs:
68112 TEST_BITBUCKET_SERVER_USER : pipelines
69113 TEST_BITBUCKET_SERVER_E2E_REPOSITORY : PAC/pac-e2e-tests
70114 steps :
71- - name : Check user permissions (detailed)
72- id : check_perms
73- uses : actions/github-script@v7
74- with :
75- script : |
76- const actor = context.actor;
77- const { owner, repo } = context.repo;
78-
79- try {
80- const response = await github.rest.repos.getCollaboratorPermissionLevel({
81- owner,
82- repo,
83- username: actor,
84- });
85-
86- const userPermission = response.data.permission;
87-
88- if (userPermission === 'admin') {
89- core.info(`✅ Permission check successful. User @${actor} is an ADMIN.`);
90- } else if (userPermission === 'write') {
91- core.info(`✅ Permission check successful. User @${actor} has WRITE permission.`);
92- } else {
93- core.setFailed(`❌ Permission check failed. User @${actor} has '${userPermission}' permission, but 'write' or 'admin' is required to proceed.`);
94- }
95-
96- } catch (error) {
97- core.setFailed(`Could not verify permission for @${actor}. They might not be a collaborator. Error: ${error.message}`);
98- }
99-
100115 - uses : actions/checkout@v5
101116 with :
102117 ref : ${{ inputs.target_ref || github.event.pull_request.head.sha || github.sha }}
103118
119+ # The permission check step has been moved to the `check-permissions` job.
120+
104121 - uses : actions/setup-go@v5
105122 with :
106123 go-version-file : " go.mod"
@@ -122,8 +139,8 @@ jobs:
122139 nohup gosmee client --saveDir /tmp/gosmee-replay ${{ secrets.PYSMEE_URL }} "http://${CONTROLLER_DOMAIN_URL}" &
123140
124141 - name : Setup tmate session
125- uses : mxschmitt/action-tmate@v3
126142 if : ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
143+ uses : mxschmitt/action-tmate@v3
127144 with :
128145 detached : true
129146 limit-access-to-actor : true
@@ -150,11 +167,8 @@ jobs:
150167 run : |
151168 ./hack/gh-workflow-ci.sh create_second_github_app_controller_on_ghe
152169
153- # Adjusted step-level conditions based on the new job-level logic
154170 - name : Run E2E Tests
155- # This step runs for schedule, PR target (if job started), or workflow_dispatch (if job started)
156- # Remove the old label check which is no longer relevant for triggering.
157- if : ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request_target' }}
171+ # The job-level `if` condition already handles this, so the step can run unconditionally
158172 env :
159173 TEST_PROVIDER : ${{ matrix.provider }}
160174 TEST_BITBUCKET_CLOUD_TOKEN : ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
@@ -171,7 +185,6 @@ jobs:
171185 ./hack/gh-workflow-ci.sh run_e2e_tests
172186
173187 - name : Run E2E Tests on nightly
174- # This step still runs specifically for schedule or workflow_dispatch
175188 if : ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
176189 env :
177190 NIGHTLY_E2E_TEST : " true"
@@ -217,3 +230,4 @@ jobs:
217230 notify_when : " failure"
218231 env :
219232 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
233+
0 commit comments