Skip to content

Commit 50023f7

Browse files
committed
addressed review comments
1 parent 7e50a98 commit 50023f7

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

.github/workflows/post-coverage-comment.yml renamed to .github/workflows/forked-pr-coverage-comment.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
name: Post Coverage Comment
22

3+
# This workflow handles posting coverage comments for FORKED PRs.
4+
#
5+
# Why a separate workflow?
6+
# - Forked PRs have restricted GITHUB_TOKEN permissions for security
7+
# - They cannot write comments directly to the base repository's PRs
8+
# - workflow_run triggers run in the BASE repository context with full permissions
9+
# - This allows us to safely post comments on forked PRs
10+
#
11+
# How it works:
12+
# 1. PR Code Coverage workflow uploads coverage data as an artifact (forked PRs only)
13+
# 2. This workflow triggers when PR Code Coverage completes successfully
14+
# 3. Downloads the artifact and posts the comment with full write permissions
15+
#
16+
# Same-repo PRs post comments directly in pr-code-coverage.yml (faster)
17+
# Forked PRs use this workflow (required for permissions)
18+
319
on:
420
workflow_run:
521
workflows: ["PR Code Coverage"]
@@ -21,9 +37,22 @@ jobs:
2137
env:
2238
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2339
run: |
24-
gh run download ${{ github.event.workflow_run.id }} \
40+
# Download artifact with error handling for non-existent artifacts
41+
if ! gh run download ${{ github.event.workflow_run.id }} \
2542
--repo ${{ github.repository }} \
26-
--name coverage-comment-data
43+
--name coverage-comment-data 2>&1; then
44+
echo "⚠️ No coverage-comment-data artifact found"
45+
echo "This is expected for same-repo PRs (they post comments directly)"
46+
echo "Exiting gracefully..."
47+
exit 0
48+
fi
49+
50+
# Verify artifact was downloaded
51+
if [[ ! -f pr-info.json ]]; then
52+
echo "⚠️ Artifact downloaded but pr-info.json not found"
53+
echo "This may indicate an issue with artifact upload"
54+
exit 1
55+
fi
2756
2857
- name: Read coverage data
2958
id: coverage

.github/workflows/pr-code-coverage.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,14 @@ jobs:
451451
cat coverage-comment-data/pr-info.json
452452
453453
- name: Upload coverage comment data
454+
# Only upload artifact for forked PRs since same-repo PRs post comment directly
455+
# This prevents unnecessary workflow_run triggers for same-repo PRs
456+
if: github.event.pull_request.head.repo.full_name != github.repository
454457
uses: actions/upload-artifact@v4
455458
with:
456459
name: coverage-comment-data
457460
path: coverage-comment-data/
458-
retention-days: 1
461+
retention-days: 7
459462

460463
- name: Comment coverage summary on PR
461464
# Skip for forked PRs due to token permission restrictions

main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
# Clean one-liner: set level and output mode together
66
setup_logging(output="both")
7-
print("Logging is set up.")
8-
print("This is a test PR for mssql-python.")
7+
98
conn_str = os.getenv("DB_CONNECTION_STRING")
109
conn = connect(conn_str)
1110
cursor = conn.cursor()

0 commit comments

Comments
 (0)