Skip to content

Commit da46fc1

Browse files
[SW-218309] Updated Tests Workflow To Support Forked PR's (#930)
Changes: - Changed the trigger of the tests from pull_request to issue_comment. now tests will be triggered only if a CODEOWNER will comment on the PR /run-gaudi-tests - Add random string to hlctl container when running the tests. I noticed that a lot of times in case of re-runs , tests is failing due to the error of workload already exists. the random string will solve it - Added a job that will collect all tests status and will fail/pass based on the tests execution status. It will be used as a mandatory status check in order to merge a PR(means that without all tests passed, a PR cannot be merged)
1 parent 7a60b7f commit da46fc1

File tree

1 file changed

+227
-16
lines changed

1 file changed

+227
-16
lines changed

.github/workflows/trigger_jenkins.yml

Lines changed: 227 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,80 @@
11
name: Trigger Jenkins Tests
22
on:
3-
pull_request:
4-
types: [opened, reopened, edited, synchronize]
3+
issue_comment:
4+
types: [created]
55

66
permissions:
77
pull-requests: write
8+
statuses: write
9+
actions: read
810
jobs:
11+
read_codeowners:
12+
name: Check Commenter
13+
runs-on: generic-runner
14+
if: ${{ contains(github.event.comment.body, '/run-gaudi-tests') && github.event.issue.pull_request }}
15+
outputs:
16+
pr_number: ${{ steps.extract_pr.outputs.pr_number }}
17+
pr_branch: ${{ steps.extract_pr.outputs.pr_branch }}
18+
pr_target_branch: ${{ steps.extract_pr.outputs.pr_target_branch }}
19+
pr_sha: ${{ steps.extract_pr.outputs.pr_sha }}
20+
steps:
21+
- name: 'Checkout Repository'
22+
uses: actions/checkout@v4
23+
with:
24+
ref: habana_main
25+
fetch-depth: 0
26+
token: ${{ secrets.GH_PAT }}
27+
- name: Parse Comment
28+
run: |
29+
MAINTAINERS=$(grep -E '^[^#]' .github/CODEOWNERS | tr -d '@*')
30+
COMMENTER=${{ github.event.comment.user.login }}
31+
echo "Maintainers are: ${MAINTAINERS}"
32+
echo "Commenter Is: ${COMMENTER}"
33+
if ! echo "$MAINTAINERS" | grep -q "$COMMENTER"; then
34+
echo "❌ User $COMMENTER is not authorized to trigger tests."
35+
exit 1
36+
fi
37+
- name: Extract PR Number
38+
id: extract_pr
39+
run: |
40+
PR_NUMBER="${{ github.event.issue.number }}"
41+
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
42+
# It will work only on open PR's
43+
random_string=$(tr -dc 'a-z0-9' </dev/urandom | head -c 10)
44+
pr_temp_branch=$(echo "pr-${PR_NUMBER}-${random_string}")
45+
git fetch origin pull/${PR_NUMBER}/merge
46+
git checkout -b $pr_temp_branch FETCH_HEAD
47+
git push origin $pr_temp_branch
48+
echo "pr_branch=$pr_temp_branch" >> "$GITHUB_OUTPUT"
49+
echo "Parsing The Base Branch"
50+
target_branch=$(curl -sH "Authorization: token ${{ secrets.GH_PAT }}" https://api.github.com/repos/${{github.repository}}/pulls/${PR_NUMBER} | jq -r '.base.ref')
51+
echo "pr_target_branch=$target_branch" >> "$GITHUB_OUTPUT"
52+
pr_sha=$(curl -sH "Authorization: token ${{ secrets.GH_PAT }}" https://api.github.com/repos/${{github.repository}}/pulls/${PR_NUMBER} | jq -r '.head.sha')
53+
echo "pr_sha=$pr_sha" >> $GITHUB_OUTPUT
954
DependencyReview:
1055
name: Dependency Review
1156
runs-on: ubuntu-latest
57+
needs: [read_codeowners]
1258
steps:
13-
- name: 'Checkout Repository'
59+
- name: Checkout Repository
1460
uses: actions/checkout@v4
61+
with:
62+
ref: ${{ needs.read_codeowners.outputs.pr_branch }}
63+
token: ${{ secrets.GH_PAT }}
1564
- name: 'Dependency Review'
1665
uses: actions/dependency-review-action@v4
1766
with:
1867
fail-on-severity: high
1968
CodeQLScan:
2069
name: CodeQL Scan
2170
runs-on: ubuntu-latest
71+
needs: [read_codeowners]
2272
steps:
23-
- name: Checkout repository
24-
uses: actions/checkout@v4
73+
- name: Checkout Repository
74+
uses: actions/checkout@v4
75+
with:
76+
ref: ${{ needs.read_codeowners.outputs.pr_branch }}
77+
token: ${{ secrets.GH_PAT }}
2578
- name: Initialize CodeQL
2679
uses: github/codeql-action/init@v3
2780
with:
@@ -35,12 +88,15 @@ jobs:
3588
CalculateJobs:
3689
runs-on: generic-runner
3790
name: Calculate Tests To Trigger
38-
needs: [DependencyReview,CodeQLScan]
91+
needs: [DependencyReview,CodeQLScan,read_codeowners]
3992
outputs:
4093
tests_list: ${{ steps.tests.outputs.tests_list }}
4194
steps:
42-
- name: Checkout
95+
- name: Checkout Repository
4396
uses: actions/checkout@v4
97+
with:
98+
ref: ${{ needs.read_codeowners.outputs.pr_branch }}
99+
token: ${{ secrets.GH_PAT }}
44100
- name: Install YQ
45101
run: |
46102
wget https://github.com/mikefarah/yq/releases/download/v4.14.1/yq_linux_amd64.tar.gz -O - |\
@@ -50,9 +106,10 @@ jobs:
50106
run: |
51107
test_list=$(yq -oj e .jenkins/test_config.yaml | jq -c "[.stages[].steps[]]")
52108
echo "tests_list=${test_list}" >> "$GITHUB_OUTPUT"
109+
53110
TestRun:
54111
name: Test / ${{matrix.tests.name}}
55-
needs: [CalculateJobs]
112+
needs: [CalculateJobs,read_codeowners]
56113
runs-on: generic-runner
57114
strategy:
58115
fail-fast: false
@@ -64,6 +121,73 @@ jobs:
64121
POD_TEMPLATE: ${{ secrets.POD_TEMPLATE }}
65122
TEST_COMMAND: ${{ matrix.tests.command }}
66123
steps:
124+
- name: Get Job ID
125+
uses: actions/github-script@v7
126+
id: fetch_job_id
127+
with:
128+
script: |
129+
async function getJobIdWithRetry(retries = 5, delay = 5000) {
130+
const run_id = context.runId;
131+
const matrix_test_name = process.env.MATRIX_TEST_NAME;
132+
133+
console.log(`Searching for job: Test / ${matrix_test_name} in run: ${run_id}`);
134+
135+
for (let i = 0; i < retries; i++) {
136+
console.log(`Attempt ${i + 1}...`);
137+
138+
const response = await github.rest.actions.listJobsForWorkflowRun({
139+
owner: context.repo.owner,
140+
repo: context.repo.repo,
141+
run_id: run_id
142+
});
143+
144+
console.log("All Jobs:", response.data.jobs.map(j => j.name));
145+
146+
// Match job with correct naming convention
147+
const job = response.data.jobs.find(j =>
148+
j.name.trim() === `Test / ${matrix_test_name}`
149+
);
150+
151+
if (job) {
152+
console.log(`Found Job ID: ${job.id}`);
153+
return job.id;
154+
}
155+
156+
console.log(`Job not found, retrying in ${delay / 1000} seconds...`);
157+
await new Promise(res => setTimeout(res, delay));
158+
}
159+
160+
throw new Error(`Job ID not found after ${retries} attempts`);
161+
}
162+
163+
const job_id = await getJobIdWithRetry();
164+
core.setOutput("job_id", job_id);
165+
env:
166+
MATRIX_TEST_NAME: ${{ matrix.tests.name }}
167+
- name: Get Job URL
168+
id: job_url
169+
run: |
170+
url=$(echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.fetch_job_id.outputs.job_id }}")
171+
echo "url=$url" >> $GITHUB_OUTPUT
172+
173+
- name: Create Commit Status(Pending)
174+
uses: actions/github-script@v7
175+
env:
176+
GIT_SHA: ${{ needs.read_codeowners.outputs.pr_sha }}
177+
TARGET_URL: ${{ steps.job_url.outputs.url }}
178+
JOB_NAME: ${{matrix.tests.name}}
179+
with:
180+
script: |
181+
await github.rest.repos.createCommitStatus({
182+
owner: context.repo.owner,
183+
repo: context.repo.repo,
184+
sha: process.env.GIT_SHA,
185+
state: 'pending',
186+
description: `Running ${process.env.JOB_NAME}`,
187+
target_url: process.env.TARGET_URL,
188+
context: `Test / ${process.env.JOB_NAME}`
189+
});
190+
67191
- name: Download Hlctl
68192
run: |
69193
curl --show-error --silent ${{ secrets.HLCTL_ADDRESS }} | bash &> /dev/null
@@ -72,9 +196,9 @@ jobs:
72196
${{ secrets.HLCTL_COMMAND }} &> /dev/null
73197
- name: Create Pod Template
74198
env:
75-
TARGET_BRANCH: ${{ github.base_ref }}
199+
TARGET_BRANCH: ${{ needs.read_codeowners.outputs.pr_target_branch }}
76200
RELEASED_SYNAPSE_VERSION: ${{ vars.RELEASED_SYNAPSE_VERSION }}
77-
BASE_BRANCH: ${{github.head_ref}}
201+
BASE_BRANCH: ${{ needs.read_codeowners.outputs.pr_branch }}
78202
run: |
79203
if [[ $TARGET_BRANCH == "habana_main" ]]; then
80204
synapse_version=${RELEASED_SYNAPSE_VERSION#v}
@@ -99,14 +223,101 @@ jobs:
99223
echo "Pod Template Created"
100224
- name: Run Test
101225
run: |
102-
converted_test_name=$(echo ${{ matrix.tests.name }} | tr "_" "-")
103-
if [[ ${#converted_test_name} -ge 33 ]];then
104-
converted_test_name=${converted_test_name:12}
105-
fi
226+
random_string=$(tr -dc 'a-z0-9' </dev/urandom | head -c 10)
106227
hlctl create containers \
107228
--file=pod.yml \
108229
--flavor=${{ matrix.tests.flavor}} \
109-
--name="vllm-fork-${{github.event.number}}-${converted_test_name}" \
230+
--name="vllm-fork-${{github.event.issue.number}}-${random_string}" \
110231
--namespace="framework" \
111232
--retry \
112-
--shm=10240
233+
--shm=10240
234+
- name: Create Commit Status(Failure)
235+
uses: actions/github-script@v7
236+
if: failure()
237+
env:
238+
GIT_SHA: ${{ needs.read_codeowners.outputs.pr_sha }}
239+
TARGET_URL: ${{ steps.job_url.outputs.url }}
240+
JOB_NAME: ${{matrix.tests.name}}
241+
with:
242+
script: |
243+
await github.rest.repos.createCommitStatus({
244+
owner: context.repo.owner,
245+
repo: context.repo.repo,
246+
sha: process.env.GIT_SHA,
247+
state: 'failure',
248+
description: `${process.env.JOB_NAME} Test Failed!`,
249+
target_url: process.env.TARGET_URL,
250+
context: `Test / ${process.env.JOB_NAME}`
251+
});
252+
- name: Create Commit Status(Success)
253+
uses: actions/github-script@v7
254+
if: success()
255+
env:
256+
GIT_SHA: ${{ needs.read_codeowners.outputs.pr_sha }}
257+
TARGET_URL: ${{ steps.job_url.outputs.url }}
258+
JOB_NAME: ${{matrix.tests.name}}
259+
with:
260+
script: |
261+
await github.rest.repos.createCommitStatus({
262+
owner: context.repo.owner,
263+
repo: context.repo.repo,
264+
sha: process.env.GIT_SHA,
265+
state: 'success',
266+
description: `${process.env.JOB_NAME} Test Has Finished Successfully`,
267+
target_url: process.env.TARGET_URL,
268+
context: `Test / ${process.env.JOB_NAME}`
269+
});
270+
Summarize:
271+
name: Summarize Test Results
272+
runs-on: generic-runner
273+
needs: [TestRun,read_codeowners]
274+
if: always()
275+
steps:
276+
- name: Checkout Repository
277+
uses: actions/checkout@v4
278+
with:
279+
fetch-depth: 0
280+
token: ${{ secrets.GH_PAT }}
281+
- name: Delete Temp Branch
282+
run: |
283+
git push origin --delete ${{ needs.read_codeowners.outputs.pr_branch }}
284+
- name: Check Test Results
285+
run: |
286+
test_result="${{ needs.TestRun.result }}"
287+
echo "Test Finished with status ${test_result}"
288+
if [[ "${test_result}" != "success" ]]; then
289+
exit 1
290+
fi
291+
- name: Create Commit Status(Success)
292+
uses: actions/github-script@v7
293+
if: success()
294+
env:
295+
GIT_SHA: ${{ needs.read_codeowners.outputs.pr_sha }}
296+
with:
297+
script: |
298+
await github.rest.repos.createCommitStatus({
299+
owner: context.repo.owner,
300+
repo: context.repo.repo,
301+
sha: process.env.GIT_SHA,
302+
state: 'success',
303+
description: 'All Tests Passed Successfully!',
304+
context: 'Summarize Test Results'
305+
});
306+
- name: Create Commit Status(Failure)
307+
uses: actions/github-script@v7
308+
if: failure()
309+
env:
310+
GIT_SHA: ${{ needs.read_codeowners.outputs.pr_sha }}
311+
with:
312+
script: |
313+
await github.rest.repos.createCommitStatus({
314+
owner: context.repo.owner,
315+
repo: context.repo.repo,
316+
sha: process.env.GIT_SHA,
317+
state: 'failure',
318+
description: 'Test Failure! Check Jobs To See Why',
319+
context: 'Summarize Test Results'
320+
});
321+
322+
323+

0 commit comments

Comments
 (0)