Skip to content

Commit 31221e3

Browse files
Copilotmikeharder
andauthored
[SDK Validation Status] trigger on PR reopen (#44026)
* Trigger spec-gen-sdk-status on PR reopen Co-authored-by: mikeharder <9459391+mikeharder@users.noreply.github.com> * restore details_url * Enhance comments for SDK Validation workflow Added important comments regarding workflow security and context. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mikeharder <9459391+mikeharder@users.noreply.github.com> Co-authored-by: Mike Harder <mharder@microsoft.com>
1 parent 8bee297 commit 31221e3

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

.github/workflows/spec-gen-sdk-status.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: "SDK Validation Status"
33
on:
44
check_run:
55
types: [completed]
6+
# Azure DevOps pipelines (which report the "SDK Validation" check runs) do not re-trigger when a
7+
# PR is reopened, so the "check_run" event alone would never refresh the status. Re-evaluate the
8+
# existing check runs on reopen using pull_request_target (privileged, runs in the target branch).
9+
pull_request_target:
10+
types: [reopened]
611

712
permissions:
813
contents: read
@@ -13,13 +18,23 @@ permissions:
1318
jobs:
1419
sdk-validation-status:
1520
if: |
16-
github.event.check_run.check_suite.app.name == 'Azure Pipelines' &&
17-
contains(github.event.check_run.name, 'SDK Validation')
21+
github.event_name == 'pull_request_target' ||
22+
(github.event.check_run.check_suite.app.name == 'Azure Pipelines' &&
23+
contains(github.event.check_run.name, 'SDK Validation'))
1824
name: "SDK Validation Status"
1925
runs-on: ubuntu-slim
2026
steps:
27+
# *** IMPORTANT ***
28+
# For workflows that are triggered by the pull_request_target event, the workflow runs in the
29+
# context of the base of the pull request. You should make sure that you do not check out,
30+
# build, or run untrusted code from the head of the pull request.
2131
- uses: actions/checkout@v6
2232
with:
33+
# Only needs .github folder for automation, not the files in the PR (analyzed in a
34+
# separate workflow).
35+
#
36+
# Uses the .github folder from the PR base branch (pull_request_target trigger),
37+
# or the repo default branch (other triggers).
2338
sparse-checkout: |
2439
.github
2540

.github/workflows/src/spec-gen-sdk-status.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export async function setSpecGenSdkStatusImpl({
7575
core.info(`- ${check.name}: ${check.status} (${check.conclusion})`);
7676
}
7777

78+
// No SDK Validation check runs exist for this commit (e.g. a PR without SDK-relevant changes that
79+
// was reopened). Skip setting a status, to avoid creating a spurious "pending" status that would
80+
// never be resolved, since the Azure DevOps pipelines won't run for such PRs.
81+
if (specGenSdkChecks.length === 0) {
82+
core.info("No SDK Validation check runs found. Skipping status update.");
83+
return;
84+
}
85+
7886
// Check if all SDK generation checks have completed
7987
const allCompleted =
8088
specGenSdkChecks.length > 0 &&

.github/workflows/test/spec-gen-sdk-status.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,30 @@ describe("spec-gen-sdk-status", () => {
352352
}),
353353
);
354354
});
355+
356+
it("should skip status update when no SDK Validation checks are found", async () => {
357+
// Simulates a reopened PR with no SDK-relevant changes: no SDK Validation check runs exist.
358+
mockGithub.rest.checks.listForRef.mockResolvedValue({
359+
data: {
360+
check_runs: [],
361+
},
362+
});
363+
364+
await setSpecGenSdkStatusImpl({
365+
owner: "testOwner",
366+
repo: "testRepo",
367+
head_sha: "testSha",
368+
target_url: "https://example.com",
369+
github: mockGithub,
370+
core: mockCore,
371+
issue_number: 123,
372+
});
373+
374+
// No status should be set when there are no SDK Validation checks.
375+
expect(mockGithub.rest.repos.createCommitStatus).not.toHaveBeenCalled();
376+
377+
// Outputs should still be set for downstream artifact upload steps.
378+
expect(mockCore.setOutput).toBeCalledWith("head_sha", "testSha");
379+
expect(mockCore.setOutput).toBeCalledWith("issue_number", 123);
380+
});
355381
});

0 commit comments

Comments
 (0)