@@ -176,14 +176,17 @@ jobs:
176176 - name : " Set PR context (workflow_run)"
177177 if : github.event_name == 'workflow_run'
178178 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
179+ env :
180+ PR_NUMBER : ${{ steps.get-pr-number.outputs.pr_number }}
179181 with :
180182 github-token : ${{ github.token }}
181183 script : |
182184 const payload = context.payload.workflow_run;
183185 const fs = require('fs');
184- const prNumber = '${{ steps.get-pr-number.outputs.pr_number }}';
186+ // Use env var to avoid syntax errors from newlines in the output
187+ const prNumber = (process.env.PR_NUMBER || '').trim();
185188
186- let baseSha = "" ;
189+ let baseSha = '' ;
187190 let checkoutRepo = payload.head_repository.full_name;
188191 let checkoutRef = payload.head_sha;
189192
@@ -195,10 +198,17 @@ jobs:
195198 ...context.repo,
196199 pull_number: parseInt(prNumber, 10)
197200 });
198- baseSha = pr.base.sha;
201+
202+ baseSha = pr.base?.sha || baseSha;
203+
199204 // Use PR head info which works for both fork and non-fork PRs
200- checkoutRepo = pr.head.repo.full_name;
201- checkoutRef = pr.head.sha;
205+ if (pr.head && pr.head.repo) {
206+ checkoutRepo = pr.head.repo.full_name;
207+ checkoutRef = pr.head.sha;
208+ } else {
209+ console.log(`PR #${prNumber} head repo missing; falling back to workflow_run payload data.`);
210+ }
211+
202212 console.log(`Fetched PR #${prNumber}: base_sha=${baseSha}, head_repo=${checkoutRepo}, head_sha=${checkoutRef}`);
203213 } catch (error) {
204214 console.log(`Warning: Could not fetch PR #${prNumber}: ${error.message}`);
@@ -212,12 +222,20 @@ jobs:
212222 baseSha = payload.pull_requests[0].base.sha;
213223 }
214224
225+ if (!baseSha) {
226+ console.log(
227+ `Warning: BASE_SHA is empty for workflow_run (PR: ${prNumber || 'n/a'}). Change detection may be skipped.`
228+ );
229+ }
230+
215231 // Set environment variables
216- fs.appendFileSync(process.env.GITHUB_ENV,
232+ fs.appendFileSync(
233+ process.env.GITHUB_ENV,
217234 `CHECKOUT_REPO=${checkoutRepo}\n` +
218- `CHECKOUT_REF=${checkoutRef}\n` +
219- `PR_NUMBER=${prNumber}\n` +
220- `BASE_SHA=${baseSha}\n`);
235+ `CHECKOUT_REF=${checkoutRef}\n` +
236+ `PR_NUMBER=${prNumber}\n` +
237+ `BASE_SHA=${baseSha}\n`
238+ );
221239
222240 - name : Set DE image and tag (repository_dispatch from de-functional-test)
223241 if : github.event_name == 'repository_dispatch'
0 commit comments