Skip to content

Commit f0b148d

Browse files
Create PR against the branch from which we checked out
Signed-off-by: Shreeya Patel <spatel@ciq.com>
1 parent c395bb1 commit f0b148d

File tree

1 file changed

+81
-44
lines changed

1 file changed

+81
-44
lines changed

.github/workflows/kernel-build-and-test-x86_64.yml

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -348,47 +348,84 @@ jobs:
348348
fi
349349
350350
- name: Create Pull Request
351-
uses: peter-evans/create-pull-request@v6
352-
with:
353-
token: ${{ secrets.GITHUB_TOKEN }}
354-
commit-message: "Automated PR: All tests passed"
355-
title: "[${{ github.ref_name }}] ${{ steps.commit_msg.outputs.commit_subject }}"
356-
body: |
357-
## Summary
358-
This PR has been automatically created after successful completion of all CI stages.
359-
360-
## Commit Message
361-
```
362-
${{ steps.commit_msg.outputs.commit_message }}
363-
```
364-
365-
## Test Results
366-
367-
### ✅ Build Stage
368-
- Status: Passed
369-
- Build Time: ${{ steps.build_info.outputs.build_time }}
370-
- Total Time: ${{ steps.build_info.outputs.total_time }}
371-
- [View build logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
372-
373-
### ✅ Boot Verification
374-
- Status: Passed
375-
- [View boot logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
376-
377-
### ✅ Kernel Selftests
378-
- **Passed:** ${{ steps.stats.outputs.passed }}
379-
- **Failed:** ${{ steps.stats.outputs.failed }}
380-
- [View kselftest logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
381-
382-
### ✅ Test Comparison
383-
- Comparison against previous run: Within acceptable threshold (±3 tests)
384-
- Branch: ${{ github.ref_name }}
385-
386-
---
387-
🤖 This PR was automatically generated by GitHub Actions
388-
Run ID: ${{ github.run_id }}
389-
branch: pr/${{ github.ref_name }}-tested
390-
delete-branch: true
391-
labels: |
392-
automated
393-
tested
394-
ready-for-review
351+
env:
352+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
353+
run: |
354+
# Determine base branch from the upstream tracking branch
355+
BASE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null | sed 's|^origin/||' || echo "")
356+
357+
if [ -z "$BASE_BRANCH" ]; then
358+
# Fallback: use merge-base to find the common ancestor branch
359+
echo "No upstream tracking branch found, using merge-base to find parent branch"
360+
for branch in lts-9.2 lts-9 main master; do
361+
if git rev-parse origin/$branch >/dev/null 2>&1; then
362+
MERGE_BASE=$(git merge-base HEAD origin/$branch 2>/dev/null || echo "")
363+
if [ -n "$MERGE_BASE" ]; then
364+
BASE_BRANCH=$branch
365+
echo "Found common ancestor with origin/$branch"
366+
break
367+
fi
368+
fi
369+
done
370+
fi
371+
372+
if [ -z "$BASE_BRANCH" ]; then
373+
echo "ERROR: Could not determine base branch for PR"
374+
exit 1
375+
fi
376+
377+
echo "Creating PR from ${{ github.ref_name }} to $BASE_BRANCH"
378+
379+
# Create PR body
380+
cat > pr_body.md << 'EOF'
381+
## Summary
382+
This PR has been automatically created after successful completion of all CI stages.
383+
384+
## Commit Message(s)
385+
```
386+
${{ steps.commit_msg.outputs.commit_message }}
387+
```
388+
389+
## Test Results
390+
391+
### ✅ Build Stage
392+
- Status: Passed
393+
- Build Time: ${{ steps.build_info.outputs.build_time }}
394+
- Total Time: ${{ steps.build_info.outputs.total_time }}
395+
- [View build logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
396+
397+
### ✅ Boot Verification
398+
- Status: Passed
399+
- [View boot logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
400+
401+
### ✅ Kernel Selftests
402+
- **Passed:** ${{ steps.stats.outputs.passed }}
403+
- **Failed:** ${{ steps.stats.outputs.failed }}
404+
- [View kselftest logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
405+
406+
### ✅ Test Comparison
407+
- Comparison against previous run: Within acceptable threshold (±3 tests)
408+
- Branch: ${{ github.ref_name }}
409+
410+
---
411+
🤖 This PR was automatically generated by GitHub Actions
412+
Run ID: ${{ github.run_id }}
413+
EOF
414+
415+
# Check if PR already exists
416+
EXISTING_PR=$(gh pr list --head "${{ github.ref_name }}" --base "$BASE_BRANCH" --json number --jq '.[0].number' || echo "")
417+
418+
if [ -n "$EXISTING_PR" ]; then
419+
echo "PR #$EXISTING_PR already exists, updating it"
420+
gh pr edit "$EXISTING_PR" \
421+
--title "[${{ github.ref_name }}] ${{ steps.commit_msg.outputs.commit_subject }}" \
422+
--body-file pr_body.md
423+
else
424+
echo "Creating new PR from ${{ github.ref_name }} to $BASE_BRANCH"
425+
gh pr create \
426+
--base "$BASE_BRANCH" \
427+
--head "${{ github.ref_name }}" \
428+
--title "[${{ github.ref_name }}] ${{ steps.commit_msg.outputs.commit_subject }}" \
429+
--body-file pr_body.md \
430+
--label "automated,tested,ready-for-review"
431+
fi

0 commit comments

Comments
 (0)