Skip to content

Commit 8387639

Browse files
authored
92 polarion check should not fail if no pr exits (#93)
* Improved validation if a PR exits or not * Add PR context check to workflow and conditionally find pull request * Update GitHub Actions to latest versions in workflow YAML files * Trying to fix this. * Improve PR detection by checking event context and matching head branch * Improve branch extraction from github.ref and add detailed logging for PR search * Remove extraneous closing bracket in find PR step of workflow
1 parent e79d3b8 commit 8387639

5 files changed

Lines changed: 68 additions & 22 deletions

File tree

.github/workflows/AddRebaseInstructionsOnPROpen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Add rebase instructions to PR body
20-
uses: actions/github-script@v7
20+
uses: actions/github-script@v8
2121
with:
2222
script: |
2323
const instructions = `

.github/workflows/PublishReviewSession.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
6464
- name: Create sessionfile name
6565
id: session_file
66-
uses: actions/github-script@v7
66+
uses: actions/github-script@v8
6767
with:
6868
result-encoding: string
6969
script: |
@@ -95,7 +95,7 @@ jobs:
9595
9696
- name: Post new model comment to PR
9797
if: steps.baseDownload.outputs.result == 'notFound'
98-
uses: actions/github-script@v7
98+
uses: actions/github-script@v8
9999
with:
100100
script: |
101101
const COMMENT_MARKER = '<!-- lemontree-review -->';
@@ -150,7 +150,7 @@ jobs:
150150
lta-dir: ${{ env.LTA_DIR }}
151151

152152
- name: Publish Model Artifact
153-
uses: actions/upload-artifact@v4
153+
uses: actions/upload-artifact@v7.0.0
154154
with:
155155
name: ModelFiles
156156
path: .\*.qeax
@@ -292,22 +292,22 @@ jobs:
292292

293293
- name: Archive Session Files
294294
if: steps.baseDownload.outputs.result == 'downloaded'
295-
uses: actions/upload-artifact@v4
295+
uses: actions/upload-artifact@v7.0.0
296296
with:
297297
name: Review Session File
298298
path: ${{ steps.session_file.outputs.result }}
299299
retention-days: 2
300300

301301
- name: Archive DiffReport.xml
302-
uses: actions/upload-artifact@v4
302+
uses: actions/upload-artifact@v7.0.0
303303
with:
304304
name: DiffReport
305305
path: ${{ env.DiffReportFilename }}
306306
retention-days: 2
307307

308308
- name: Create PR comment
309309
if: steps.baseDownload.outputs.result == 'downloaded'
310-
uses: actions/github-script@v7
310+
uses: actions/github-script@v8
311311
with:
312312
script: |
313313
const COMMENT_MARKER = '<!-- lemontree-review -->';

.github/workflows/RebasePRByComments.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
steps:
3232
- name: Post start message in PR
33-
uses: actions/github-script@v7
33+
uses: actions/github-script@v8
3434
with:
3535
script: |
3636
await github.rest.issues.createComment({
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Retrieve Rull Request details
4444
id: pr_details
45-
uses: actions/github-script@v7
45+
uses: actions/github-script@v8
4646
with:
4747
result-encoding: string
4848
script: |
@@ -175,7 +175,7 @@ jobs:
175175
176176
- name: Create Finish Message in PR
177177
if: always()
178-
uses: actions/github-script@v7
178+
uses: actions/github-script@v8
179179
with:
180180
script: |
181181
await github.rest.issues.createComment({

.github/workflows/ReviewModelCheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
102102
- name: Post Model Check Results to PR
103103
if: github.event_name == 'pull_request' && always()
104-
uses: actions/github-script@v7
104+
uses: actions/github-script@v8
105105
with:
106106
script: |
107107
const fs = require('fs');

.github/workflows/ReviewPolarionRequirements.yml

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ jobs:
152152
$prNumber = if ('${{ github.event.pull_request.number }}' -eq '') { '' } else { '${{ github.event.pull_request.number }}' }
153153
& .\scripts\ProcessSvgDiagrams.ps1 -DiffReportFilename "${{env.DiffReportFilename}}" -GitUserName "${{env.GitUserName}}" -GitUserEmail "${{env.GitUserEmail}}" -PullRequestNumber "$prNumber" -RepositoryName "${{github.repository}}"
154154
- name: Publish DiffReport.xml
155-
uses: actions/upload-artifact@v4
155+
uses: actions/upload-artifact@v7.0.0
156156
with:
157157
name: DiffReport
158158
path: .\*.xml
159159
retention-days: 2
160160

161161
- name: Publish SessionFile
162-
uses: actions/upload-artifact@v4
162+
uses: actions/upload-artifact@v7.0.0
163163
with:
164164
name: SessionFile
165165
path: .\*.ltsfs
@@ -196,26 +196,72 @@ jobs:
196196
- name: Extract branch name
197197
id: extract_branch
198198
run: |
199-
Write-Output "branch=$env:GITHUB_HEAD_REF" >> $env:GITHUB_OUTPUT
199+
$branch = git branch --show-current
200+
Write-Output "branch=$branch" >> $env:GITHUB_OUTPUT
201+
Write-Output "Current branch: $branch"
200202
201203
- name: Print Session URL
202204
run: |
203205
Write-Output "${{steps.uploadSession.outputs.SessionURL}}"
204206
205-
- name: Find Pull Request
206-
uses: juliangruber/find-pull-request-action@v1
207-
id: find-pull-request
207+
- name: Find and validate Pull Request
208+
id: find-pr
209+
uses: actions/github-script@v8
208210
with:
209-
branch: ${{steps.extract_branch.outputs.branch }}
211+
result-encoding: string
212+
script: |
213+
// Extract branch name from github.ref
214+
const ref = context.ref;
215+
const branch = ref.startsWith('refs/heads/') ? ref.slice('refs/heads/'.length) : ref;
216+
console.log(`GitHub ref: ${ref}`);
217+
console.log(`Extracted branch: ${branch}`);
218+
219+
// First check if we have a PR context from the event
220+
if (context.payload.pull_request) {
221+
const pr = context.payload.pull_request;
222+
console.log(`Found PR from event context: #${pr.number}`);
223+
core.setOutput('pr_exists', 'true');
224+
core.setOutput('pr_number', pr.number);
225+
return;
226+
}
227+
228+
console.log(`Searching for open PRs with head ref: ${branch}`);
229+
230+
// Search for open PRs with matching head ref
231+
const prs = await github.rest.pulls.list({
232+
owner: context.repo.owner,
233+
repo: context.repo.repo,
234+
state: 'open',
235+
per_page: 100
236+
});
237+
238+
console.log(`Found ${prs.data.length} open PRs`);
239+
240+
// Filter PRs by matching head branch
241+
const matchingPrs = prs.data.filter(pr => {
242+
const headRef = pr.head.ref;
243+
console.log(` PR #${pr.number}: head=${headRef}`);
244+
return headRef === branch;
245+
});
246+
247+
if (matchingPrs.length > 0) {
248+
const pr = matchingPrs[0];
249+
console.log(`✓ Found PR #${pr.number} with matching branch`);
250+
core.setOutput('pr_exists', 'true');
251+
core.setOutput('pr_number', pr.number);
252+
} else {
253+
console.log(`✗ No open PR found for branch: ${branch}`);
254+
core.setOutput('pr_exists', 'false');
255+
}
210256
211257
- name: Post Finish message in PR
212-
if: ${{ steps.find-pull-request.outputs.number != '' }}
213-
uses: actions/github-script@v7
258+
if: ${{ steps.find-pr.outputs.pr_exists == 'true' }}
259+
uses: actions/github-script@v8
214260
with:
215261
script: |
262+
const prNumber = ${{steps.find-pr.outputs.pr_number}};
216263
const COMMENT_MARKER = '<!-- polarion-review -->';
217264
const body = COMMENT_MARKER + '\nPolarion vs Model comparison in current Branch\n${{steps.uploadSession.outputs.SfsFileNameLinks}}\n\n${{ steps.processSvgs.outputs.svgLinksMarkdown }}${{steps.pcsDiff.outputs.CommitID}}\n\nChanged Requirements:\n${{steps.diffreport.outputs.ModifiedRequirements}}';
218-
const prNumber = ${{steps.find-pull-request.outputs.number}};
219265
const { data: comments } = await github.rest.issues.listComments({
220266
owner: context.repo.owner,
221267
repo: context.repo.repo,
@@ -247,7 +293,7 @@ jobs:
247293
Write-Output "${{steps.uploadSession.outputs.SfsFileNameLinks}}" >> $env:GITHUB_STEP_SUMMARY
248294
249295
- name: Publish Model Artifact
250-
uses: actions/upload-artifact@v4
296+
uses: actions/upload-artifact@v7.0.0
251297
with:
252298
name: ModelFiles
253299
path: .\*.qeax

0 commit comments

Comments
 (0)