Skip to content

Commit 28ba38d

Browse files
committed
Debug
Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 6242ef3 commit 28ba38d

File tree

1 file changed

+177
-18
lines changed

1 file changed

+177
-18
lines changed

.github/workflows/module-monitor.yml

Lines changed: 177 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Module Monitor
22
on:
3-
pull_request_target:
3+
pull_request:
44
paths:
55
- 'zephyr/module.yml'
66

@@ -54,6 +54,7 @@ jobs:
5454
git show $HEAD_REF:zephyr/module.yml > new_module.yml
5555
5656
# Parse YAML and generate comparison table
57+
echo "DEBUG: Starting Python script..." >&2
5758
python3 << 'EOF'
5859
import yaml
5960
import sys
@@ -73,6 +74,87 @@ jobs:
7374
return commit_part[:7]
7475
return "Unknown"
7576
77+
def get_commit_info(commit_hash):
78+
"""Get additional commit information like branch and PR references"""
79+
try:
80+
import subprocess
81+
import json
82+
83+
# Get commit details
84+
result = subprocess.run(['git', 'log', '--format=%H|%s|%an|%ad', '--date=short', '-1', commit_hash],
85+
capture_output=True, text=True, timeout=10)
86+
if result.returncode == 0:
87+
parts = result.stdout.strip().split('|')
88+
if len(parts) >= 4:
89+
return {
90+
'hash': parts[0][:7],
91+
'subject': parts[1],
92+
'author': parts[2],
93+
'date': parts[3]
94+
}
95+
except:
96+
pass
97+
return {'hash': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"}
98+
99+
def get_commit_status(commit_hash):
100+
"""Check if commit is merged (on main/master) or has an associated PR"""
101+
try:
102+
import subprocess
103+
104+
# Check if commit is on main/master branch (merged)
105+
result = subprocess.run(['git', 'branch', '-r', '--contains', commit_hash],
106+
capture_output=True, text=True, timeout=10)
107+
if result.returncode == 0:
108+
branches = result.stdout.strip().split('\n')
109+
for branch in branches:
110+
branch = branch.strip()
111+
if branch and any(main_branch in branch for main_branch in ['origin/main', 'origin/master']):
112+
# Extract branch name (remove 'origin/' prefix)
113+
branch_name = branch.replace('origin/', '')
114+
return {
115+
'status': 'merged',
116+
'branch': branch_name,
117+
'display': f"{commit_hash[:7]} ({branch_name})" if commit_hash != "Unknown" else f"Unknown ({branch_name})"
118+
}
119+
120+
# Check if commit has an associated PR (not merged)
121+
result = subprocess.run(['git', 'log', '--oneline', '--grep=^Merge pull request', '-i', commit_hash],
122+
capture_output=True, text=True, timeout=10)
123+
if result.returncode == 0 and result.stdout.strip():
124+
import re
125+
pr_match = re.search(r'#(\d+)', result.stdout)
126+
if pr_match:
127+
pr_number = pr_match.group(1)
128+
return {
129+
'status': 'pr',
130+
'pr_number': pr_number,
131+
'pr_url': f"https://github.com/nrfconnect/sdk-nrfxlib/pull/{pr_number}",
132+
'display': f"[{commit_hash[:7]}]({pr_number})"
133+
}
134+
135+
# Check if commit is on a feature branch (might have PR)
136+
result = subprocess.run(['git', 'branch', '-r', '--contains', commit_hash],
137+
capture_output=True, text=True, timeout=10)
138+
if result.returncode == 0:
139+
branches = result.stdout.strip().split('\n')
140+
for branch in branches:
141+
branch = branch.strip()
142+
if branch and not any(main_branch in branch for main_branch in ['origin/main', 'origin/master']):
143+
return {
144+
'status': 'pr',
145+
'pr_number': '?',
146+
'pr_url': f"https://github.com/nrfconnect/sdk-nrfxlib/pulls?q=is:pr+{commit_hash}",
147+
'display': f"[{commit_hash[:7]}]({pr_number})"
148+
}
149+
except:
150+
pass
151+
152+
# Default: show short commit hash
153+
return {
154+
'status': 'merged',
155+
'display': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"
156+
}
157+
76158
def generate_diff_link(old_url, new_url):
77159
"""Generate diff link for the source repository"""
78160
old_commit = extract_commit_from_url(old_url)
@@ -85,9 +167,11 @@ jobs:
85167
return "N/A"
86168
87169
try:
170+
print("DEBUG: Loading old_module.yml...", file=sys.stderr)
88171
# Load old and new module.yml
89172
with open('old_module.yml', 'r') as f:
90173
old_data = yaml.safe_load(f)
174+
print("DEBUG: Loading new_module.yml...", file=sys.stderr)
91175
with open('new_module.yml', 'r') as f:
92176
new_data = yaml.safe_load(f)
93177
@@ -96,8 +180,8 @@ jobs:
96180
97181
# Generate comparison table
98182
table_rows = []
99-
table_rows.append("| Variant | Old Version | New Version | Old SHA256 | New SHA256 | Old Commit | New Commit | Diff Link |")
100-
table_rows.append("|---------|-------------|-------------|------------|------------|------------|------------|-----------|")
183+
table_rows.append("| Variant | Old Version | New Version | Old Commit | New Commit | Diff Link |")
184+
table_rows.append("|---------|-------------|-------------|------------|------------|-----------|")
101185
102186
all_paths = set(old_blobs.keys()) | set(new_blobs.keys())
103187
@@ -107,16 +191,27 @@ jobs:
107191
108192
old_version = old_blob.get('version', 'N/A')
109193
new_version = new_blob.get('version', 'N/A')
110-
old_sha = old_blob.get('sha256', 'N/A')[:16] + '...' if old_blob.get('sha256') else 'N/A'
111-
new_sha = new_blob.get('sha256', 'N/A')[:16] + '...' if new_blob.get('sha256') else 'N/A'
112-
old_commit = extract_commit_from_url(old_blob.get('url', ''))
113-
new_commit = extract_commit_from_url(new_blob.get('url', ''))
194+
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
195+
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
196+
197+
# Get additional commit information
198+
old_commit_info = get_commit_info(old_commit_hash)
199+
new_commit_info = get_commit_info(new_commit_hash)
200+
201+
# Check commit status (merged vs PR)
202+
old_commit_status = get_commit_status(old_commit_hash)
203+
new_commit_status = get_commit_status(new_commit_hash)
204+
205+
# Format commit display
206+
old_commit_display = old_commit_status['display']
207+
new_commit_display = new_commit_status['display']
208+
114209
diff_link = generate_diff_link(old_blob.get('url', ''), new_blob.get('url', ''))
115210
116211
# Extract variant name from path
117212
variant = path.split('/')[-2] if '/' in path else path
118213
119-
table_rows.append(f"| {variant} | {old_version} | {new_version} | {old_sha} | {new_sha} | {old_commit} | {new_commit} | {diff_link} |")
214+
table_rows.append(f"| {variant} | {old_version} | {new_version} | {old_commit_display} | {new_commit_display} | {diff_link} |")
120215
121216
# Check if there are any actual changes
122217
has_changes = False
@@ -135,6 +230,43 @@ jobs:
135230
diff_content.append("## Firmware Blob Changes")
136231
diff_content.append("")
137232
diff_content.extend(table_rows)
233+
234+
# Add commit details section
235+
diff_content.append("")
236+
diff_content.append("### Commit Details:")
237+
diff_content.append("")
238+
239+
# Collect unique commits
240+
unique_commits = set()
241+
for path in sorted(all_paths):
242+
old_blob = old_blobs.get(path, {})
243+
new_blob = new_blobs.get(path, {})
244+
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
245+
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
246+
if old_commit_hash != "Unknown":
247+
unique_commits.add(old_commit_hash)
248+
if new_commit_hash != "Unknown":
249+
unique_commits.add(new_commit_hash)
250+
251+
# Show commit details
252+
for commit_hash in sorted(unique_commits):
253+
commit_info = get_commit_info(commit_hash)
254+
commit_status = get_commit_status(commit_hash)
255+
256+
if 'subject' in commit_info:
257+
commit_line = f"- **{commit_info['hash']}**: {commit_info['subject']} (by {commit_info['author']} on {commit_info['date']})"
258+
if commit_status['status'] == 'pr':
259+
commit_line += f" - [PR #{commit_status['pr_number']}]({commit_status['pr_url']})"
260+
elif commit_status['status'] == 'merged' and 'branch' in commit_status:
261+
commit_line += f" - {commit_status['branch']}"
262+
diff_content.append(commit_line)
263+
else:
264+
commit_line = f"- **{commit_info['hash']}**: Commit details not available"
265+
if commit_status['status'] == 'pr':
266+
commit_line += f" - [PR #{commit_status['pr_number']}]({commit_status['pr_url']})"
267+
elif commit_status['status'] == 'merged' and 'branch' in commit_status:
268+
commit_line += f" - {commit_status['branch']}"
269+
diff_content.append(commit_line)
138270
else:
139271
diff_content.append("## No Changes Detected")
140272
diff_content.append("")
@@ -144,9 +276,12 @@ jobs:
144276
diff_content.extend(table_rows[2:]) # Skip header rows
145277
146278
# Write to file for GitHub Actions output
279+
print(f"DEBUG: Writing {len(diff_content)} lines to diff_output.txt", file=sys.stderr)
147280
with open('diff_output.txt', 'w') as f:
148281
f.write('\n'.join(diff_content))
149282
283+
print(f"DEBUG: Successfully wrote diff_output.txt", file=sys.stderr)
284+
150285
print("diff_output<<EOF", file=sys.stdout)
151286
print('\n'.join(diff_content), file=sys.stdout)
152287
print("EOF", file=sys.stdout)
@@ -164,9 +299,12 @@ jobs:
164299
blob_content = ["## Current Firmware Blobs:"] + blob_info
165300
166301
# Write to file for GitHub Actions output
302+
print(f"DEBUG: Writing {len(blob_content)} lines to blob_summary.txt", file=sys.stderr)
167303
with open('blob_summary.txt', 'w') as f:
168304
f.write('\n'.join(blob_content))
169305
306+
print(f"DEBUG: Successfully wrote blob_summary.txt", file=sys.stderr)
307+
170308
print("blob_summary<<EOF", file=sys.stdout)
171309
print('\n'.join(blob_content), file=sys.stdout)
172310
print("EOF", file=sys.stdout)
@@ -178,17 +316,38 @@ jobs:
178316
print("blob_summary<<EOF", file=sys.stdout)
179317
print(f"Error parsing module.yml: {e}", file=sys.stdout)
180318
print("EOF", file=sys.stdout)
319+
print("DEBUG: Python script completed successfully", file=sys.stderr)
181320
EOF
182321
183322
- name: Set output variables
323+
id: set-output
184324
run: |
185-
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
186-
cat diff_output.txt >> $GITHUB_OUTPUT
187-
echo "EOF" >> $GITHUB_OUTPUT
325+
echo "DEBUG: Checking if files exist..." >&2
326+
ls -la *.txt >&2 || echo "No .txt files found" >&2
327+
328+
if [ -f diff_output.txt ]; then
329+
echo "DEBUG: diff_output.txt exists, size: $(wc -c < diff_output.txt)" >&2
330+
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
331+
cat diff_output.txt >> $GITHUB_OUTPUT
332+
echo "EOF" >> $GITHUB_OUTPUT
333+
else
334+
echo "DEBUG: diff_output.txt not found" >&2
335+
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
336+
echo "No changes detected" >> $GITHUB_OUTPUT
337+
echo "EOF" >> $GITHUB_OUTPUT
338+
fi
188339
189-
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
190-
cat blob_summary.txt >> $GITHUB_OUTPUT
191-
echo "EOF" >> $GITHUB_OUTPUT
340+
if [ -f blob_summary.txt ]; then
341+
echo "DEBUG: blob_summary.txt exists, size: $(wc -c < blob_summary.txt)" >&2
342+
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
343+
cat blob_summary.txt >> $GITHUB_OUTPUT
344+
echo "EOF" >> $GITHUB_OUTPUT
345+
else
346+
echo "DEBUG: blob_summary.txt not found" >&2
347+
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
348+
echo "No blob summary available" >> $GITHUB_OUTPUT
349+
echo "EOF" >> $GITHUB_OUTPUT
350+
fi
192351
193352
- name: Create or update comment
194353
uses: actions/github-script@v7
@@ -228,8 +387,8 @@ jobs:
228387
});
229388
}
230389
env:
231-
diff_output: ${{ steps.changes.outputs.diff_output }}
232-
blob_summary: ${{ steps.changes.outputs.blob_summary }}
390+
diff_output: ${{ steps.set-output.outputs.diff_output }}
391+
blob_summary: ${{ steps.set-output.outputs.blob_summary }}
233392

234393

235394

@@ -239,7 +398,7 @@ jobs:
239398
echo "" >> $GITHUB_STEP_SUMMARY
240399
echo "### Changes in zephyr/module.yml:" >> $GITHUB_STEP_SUMMARY
241400
echo '```diff' >> $GITHUB_STEP_SUMMARY
242-
echo "${{ steps.changes.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
401+
echo "${{ steps.set-output.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
243402
echo '```' >> $GITHUB_STEP_SUMMARY
244403
echo "" >> $GITHUB_STEP_SUMMARY
245-
echo "${{ steps.changes.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY
404+
echo "${{ steps.set-output.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)