Skip to content

Commit 87cf646

Browse files
committed
adding github workflow to check dspa integration test workflow
Signed-off-by: Nelesh Singla <[email protected]>
1 parent 324ddef commit 87cf646

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Stable Branch Gate
2+
3+
# This workflow ensures that PRs to the stable branch cannot be merged
4+
# until the remote stable-merge-check workflow has completed successfully
5+
on:
6+
pull_request:
7+
branches: [stable]
8+
types: [opened, synchronize, reopened, ready_for_review]
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
checks: write
14+
issues: write
15+
16+
jobs:
17+
check-remote-workflow-status:
18+
name: Check Remote Integration Tests
19+
runs-on: ubuntu-latest
20+
21+
# Only run on PRs targeting stable branch
22+
if: github.event.pull_request.base.ref == 'stable'
23+
24+
steps:
25+
- name: Check remote workflow status
26+
id: check-remote
27+
uses: actions/github-script@v7
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
script: |
31+
// Get PR information
32+
const prNumber = context.payload.pull_request.number;
33+
const headSha = context.payload.pull_request.head.sha;
34+
const headRef = context.payload.pull_request.head.ref;
35+
36+
console.log(`Checking remote workflow status for PR #${prNumber}`);
37+
console.log(`Head SHA: ${headSha}`);
38+
console.log(`Head Ref: ${headRef}`);
39+
40+
try {
41+
const remoteOwner = 'opendatahub-io';
42+
const remoteRepo = 'data-science-pipelines';
43+
44+
// Try to get workflow runs for the stable-merge-check workflow
45+
const { data: workflows } = await github.rest.actions.listWorkflowRuns({
46+
owner: remoteOwner,
47+
repo: remoteRepo,
48+
workflow_id: 'stable-merge-check.yml',
49+
branch: headRef, // Look for runs on the same branch name
50+
per_page: 20
51+
});
52+
53+
console.log(`Found ${workflows.total_count} workflow runs for branch ${headRef}`);
54+
55+
// Look for successful runs
56+
const successfulRuns = workflows.workflow_runs.filter(run =>
57+
run.conclusion === 'success' &&
58+
run.status === 'completed'
59+
);
60+
61+
if (successfulRuns.length > 0) {
62+
const latestSuccessful = successfulRuns[0];
63+
console.log(`✅ Found ${successfulRuns.length} successful remote workflow run(s)`);
64+
console.log(`Latest successful run: ${latestSuccessful.html_url}`);
65+
core.setOutput('status', 'success');
66+
core.setOutput('message', `Remote integration tests passed`);
67+
core.setOutput('workflow_url', latestSuccessful.html_url);
68+
} else {
69+
// Check for any runs at all
70+
const anyRuns = workflows.workflow_runs.length > 0;
71+
if (anyRuns) {
72+
const latestRun = workflows.workflow_runs[0];
73+
console.log(`❌ No successful runs found. Latest run status: ${latestRun.status}, conclusion: ${latestRun.conclusion}`);
74+
core.setOutput('status', 'failure');
75+
core.setOutput('message', `Remote integration tests have not passed (status: ${latestRun.conclusion || latestRun.status})`);
76+
core.setOutput('workflow_url', latestRun.html_url);
77+
} else {
78+
console.log('❌ No workflow runs found for this branch');
79+
core.setOutput('status', 'failure');
80+
core.setOutput('message', 'No remote integration test runs found for this branch');
81+
core.setOutput('workflow_url', `https://github.com/${remoteOwner}/${remoteRepo}/actions/workflows/stable-merge-check.yml`);
82+
}
83+
}
84+
} catch (error) {
85+
console.error(`Error checking workflow status: ${error.message}`);
86+
core.setOutput('status', 'failure');
87+
core.setOutput('message', `Error checking remote integration test status: ${error.message}`);
88+
core.setOutput('workflow_url', 'https://github.com/opendatahub-io/data-science-pipelines/actions/workflows/stable-merge-check.yml');
89+
}
90+
91+
- name: Set status check
92+
uses: actions/github-script@v7
93+
with:
94+
github-token: ${{ secrets.GITHUB_TOKEN }}
95+
script: |
96+
const status = '${{ steps.check-remote.outputs.status }}';
97+
const message = '${{ steps.check-remote.outputs.message }}';
98+
const workflowUrl = '${{ steps.check-remote.outputs.workflow_url }}';
99+
100+
const state = status === 'success' ? 'success' : 'failure';
101+
102+
await github.rest.repos.createCommitStatus({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
sha: context.payload.pull_request.head.sha,
106+
state: state,
107+
target_url: workflowUrl,
108+
description: message,
109+
context: 'stable-branch-gate/remote-integration-tests'
110+
});
111+
112+
if (state === 'failure') {
113+
core.setFailed(message);
114+
}
115+
116+
provide-instructions:
117+
name: Provide Instructions
118+
runs-on: ubuntu-latest
119+
if: github.event.pull_request.base.ref == 'stable' && github.event.action == 'opened'
120+
121+
steps:
122+
- name: Comment with instructions
123+
uses: actions/github-script@v7
124+
with:
125+
github-token: ${{ secrets.GITHUB_TOKEN }}
126+
script: |
127+
const prNumber = context.payload.pull_request.number;
128+
129+
const comment = `
130+
## 🔒 Stable Branch Protection
131+
132+
This PR targets the **stable** branch and requires integration test verification from the upstream repository.
133+
134+
### Requirements:
135+
The [stable-merge-check workflow](https://github.com/opendatahub-io/data-science-pipelines/blob/master/.github/workflows/stable-merge-check.yml) in the **opendatahub-io/data-science-pipelines** repository must complete successfully for a branch with the same name as this PR.
136+
137+
### How it works:
138+
- This workflow automatically checks if the remote integration tests have passed
139+
- If successful, the PR will be eligible for merge
140+
- If not, ensure the corresponding branch exists in the upstream repo and tests pass there
141+
142+
📋 **Status**: Checking remote integration test status...
143+
`;
144+
145+
await github.rest.issues.createComment({
146+
owner: context.repo.owner,
147+
repo: context.repo.repo,
148+
issue_number: prNumber,
149+
body: comment
150+
});

0 commit comments

Comments
 (0)