Skip to content

Commit 7acba70

Browse files
committed
Debug
Signed-off-by: Chaitanya Tata <[email protected]>
1 parent b920557 commit 7acba70

File tree

1 file changed

+194
-18
lines changed

1 file changed

+194
-18
lines changed

.github/workflows/module-monitor.yml

Lines changed: 194 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

@@ -25,6 +25,12 @@ jobs:
2525
run: |
2626
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-head
2727
28+
- name: Setup sdk-nrfxlib repository
29+
run: |
30+
git clone --depth=1000 https://github.com/nrfconnect/sdk-nrfxlib.git sdk-nrfxlib-repo
31+
cd sdk-nrfxlib-repo
32+
git fetch --depth=1000
33+
2834
- name: Set up Python
2935
uses: actions/setup-python@v5
3036
with:
@@ -54,6 +60,7 @@ jobs:
5460
git show $HEAD_REF:zephyr/module.yml > new_module.yml
5561
5662
# Parse YAML and generate comparison table
63+
echo "DEBUG: Starting Python script..." >&2
5764
python3 << 'EOF'
5865
import yaml
5966
import sys
@@ -73,6 +80,98 @@ jobs:
7380
return commit_part[:7]
7481
return "Unknown"
7582
83+
def get_commit_info(commit_hash):
84+
"""Get additional commit information like branch and PR references"""
85+
try:
86+
import subprocess
87+
import json
88+
import os
89+
90+
# Use the cloned sdk-nrfxlib repository
91+
sdk_repo_dir = 'sdk-nrfxlib-repo'
92+
if not os.path.exists(sdk_repo_dir):
93+
return {'hash': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"}
94+
95+
# Get commit details from the sdk-nrfxlib repository
96+
result = subprocess.run(['git', 'log', '--format=%H|%s|%an|%ad', '--date=short', '-1', commit_hash],
97+
cwd=sdk_repo_dir, capture_output=True, text=True, timeout=10)
98+
if result.returncode == 0 and result.stdout.strip():
99+
parts = result.stdout.strip().split('|')
100+
if len(parts) >= 4:
101+
return {
102+
'hash': parts[0][:7],
103+
'subject': parts[1],
104+
'author': parts[2],
105+
'date': parts[3]
106+
}
107+
except:
108+
pass
109+
110+
# Fallback: return basic info
111+
return {'hash': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"}
112+
113+
def get_commit_status(commit_hash):
114+
"""Get commit status and branch information"""
115+
try:
116+
import subprocess
117+
import os
118+
import re
119+
120+
# First, check if we have PR metadata in the module.yml file
121+
try:
122+
with open('zephyr/module.yml', 'r') as f:
123+
content = f.read()
124+
# Look for PR metadata comment
125+
pr_match = re.search(r'# Generated from PR #(\d+) \(commit: ([a-f0-9]+)\)', content)
126+
if pr_match and pr_match.group(2) == commit_hash:
127+
pr_number = pr_match.group(1)
128+
return {
129+
'display': f"[{commit_hash[:7]}](PR #{pr_number})",
130+
'is_pr': True,
131+
'pr_number': pr_number,
132+
'pr_url': f"https://github.com/nrfconnect/sdk-nrfxlib/pull/{pr_number}"
133+
}
134+
except:
135+
pass
136+
137+
# Change to sdk-nrfxlib repository directory
138+
sdk_repo_dir = 'sdk-nrfxlib-repo'
139+
if not os.path.exists(sdk_repo_dir):
140+
return {'display': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"}
141+
142+
# Get all branches containing this commit
143+
result = subprocess.run(['git', 'branch', '-r', '--contains', commit_hash],
144+
cwd=sdk_repo_dir, capture_output=True, text=True, timeout=10)
145+
if result.returncode == 0:
146+
branches = result.stdout.strip().split('\n')
147+
branch_names = []
148+
is_on_main = False
149+
150+
for branch in branches:
151+
branch = branch.strip()
152+
if branch:
153+
branch_name = branch.replace('origin/', '')
154+
branch_names.append(branch_name)
155+
if branch_name in ['main', 'master']:
156+
is_on_main = True
157+
158+
if is_on_main:
159+
return {
160+
'display': f"{commit_hash[:7]} (main)" if commit_hash != "Unknown" else "Unknown (main)"
161+
}
162+
elif branch_names:
163+
# Show the first branch found
164+
return {
165+
'display': f"{commit_hash[:7]} ({branch_names[0]})" if commit_hash != "Unknown" else f"Unknown ({branch_names[0]})"
166+
}
167+
except:
168+
pass
169+
170+
# Default: show short commit hash
171+
return {
172+
'display': commit_hash[:7] if commit_hash != "Unknown" else "Unknown"
173+
}
174+
76175
def generate_diff_link(old_url, new_url):
77176
"""Generate diff link for the source repository"""
78177
old_commit = extract_commit_from_url(old_url)
@@ -85,9 +184,11 @@ jobs:
85184
return "N/A"
86185
87186
try:
187+
print("DEBUG: Loading old_module.yml...", file=sys.stderr)
88188
# Load old and new module.yml
89189
with open('old_module.yml', 'r') as f:
90190
old_data = yaml.safe_load(f)
191+
print("DEBUG: Loading new_module.yml...", file=sys.stderr)
91192
with open('new_module.yml', 'r') as f:
92193
new_data = yaml.safe_load(f)
93194
@@ -96,8 +197,8 @@ jobs:
96197
97198
# Generate comparison table
98199
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("|---------|-------------|-------------|------------|------------|------------|------------|-----------|")
200+
table_rows.append("| Variant | Old Version | New Version | Old Commit | New Commit | Diff Link |")
201+
table_rows.append("|---------|-------------|-------------|------------|------------|-----------|")
101202
102203
all_paths = set(old_blobs.keys()) | set(new_blobs.keys())
103204
@@ -107,16 +208,27 @@ jobs:
107208
108209
old_version = old_blob.get('version', 'N/A')
109210
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', ''))
211+
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
212+
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
213+
214+
# Get additional commit information
215+
old_commit_info = get_commit_info(old_commit_hash)
216+
new_commit_info = get_commit_info(new_commit_hash)
217+
218+
# Check commit status (merged vs PR)
219+
old_commit_status = get_commit_status(old_commit_hash)
220+
new_commit_status = get_commit_status(new_commit_hash)
221+
222+
# Format commit display
223+
old_commit_display = old_commit_status['display']
224+
new_commit_display = new_commit_status['display']
225+
114226
diff_link = generate_diff_link(old_blob.get('url', ''), new_blob.get('url', ''))
115227
116228
# Extract variant name from path
117229
variant = path.split('/')[-2] if '/' in path else path
118230
119-
table_rows.append(f"| {variant} | {old_version} | {new_version} | {old_sha} | {new_sha} | {old_commit} | {new_commit} | {diff_link} |")
231+
table_rows.append(f"| {variant} | {old_version} | {new_version} | {old_commit_display} | {new_commit_display} | {diff_link} |")
120232
121233
# Check if there are any actual changes
122234
has_changes = False
@@ -135,6 +247,43 @@ jobs:
135247
diff_content.append("## Firmware Blob Changes")
136248
diff_content.append("")
137249
diff_content.extend(table_rows)
250+
251+
# Add commit details section
252+
diff_content.append("")
253+
diff_content.append("### Commit Details:")
254+
diff_content.append("")
255+
256+
# Collect unique commits
257+
unique_commits = set()
258+
for path in sorted(all_paths):
259+
old_blob = old_blobs.get(path, {})
260+
new_blob = new_blobs.get(path, {})
261+
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
262+
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
263+
if old_commit_hash != "Unknown":
264+
unique_commits.add(old_commit_hash)
265+
if new_commit_hash != "Unknown":
266+
unique_commits.add(new_commit_hash)
267+
268+
# Show commit details
269+
for commit_hash in sorted(unique_commits):
270+
commit_info = get_commit_info(commit_hash)
271+
commit_status = get_commit_status(commit_hash)
272+
273+
if 'subject' in commit_info:
274+
commit_line = f"- **{commit_info['hash']}**: {commit_info['subject']} (by {commit_info['author']} on {commit_info['date']})"
275+
# Add branch information if available
276+
if 'display' in commit_status and '(' in commit_status['display']:
277+
branch_info = commit_status['display'].split('(')[1].rstrip(')')
278+
commit_line += f" - {branch_info}"
279+
diff_content.append(commit_line)
280+
else:
281+
commit_line = f"- **{commit_info['hash']}**: Commit details not available"
282+
# Add branch information if available
283+
if 'display' in commit_status and '(' in commit_status['display']:
284+
branch_info = commit_status['display'].split('(')[1].rstrip(')')
285+
commit_line += f" - {branch_info}"
286+
diff_content.append(commit_line)
138287
else:
139288
diff_content.append("## No Changes Detected")
140289
diff_content.append("")
@@ -144,9 +293,12 @@ jobs:
144293
diff_content.extend(table_rows[2:]) # Skip header rows
145294
146295
# Write to file for GitHub Actions output
296+
print(f"DEBUG: Writing {len(diff_content)} lines to diff_output.txt", file=sys.stderr)
147297
with open('diff_output.txt', 'w') as f:
148298
f.write('\n'.join(diff_content))
149299
300+
print(f"DEBUG: Successfully wrote diff_output.txt", file=sys.stderr)
301+
150302
print("diff_output<<EOF", file=sys.stdout)
151303
print('\n'.join(diff_content), file=sys.stdout)
152304
print("EOF", file=sys.stdout)
@@ -164,9 +316,12 @@ jobs:
164316
blob_content = ["## Current Firmware Blobs:"] + blob_info
165317
166318
# Write to file for GitHub Actions output
319+
print(f"DEBUG: Writing {len(blob_content)} lines to blob_summary.txt", file=sys.stderr)
167320
with open('blob_summary.txt', 'w') as f:
168321
f.write('\n'.join(blob_content))
169322
323+
print(f"DEBUG: Successfully wrote blob_summary.txt", file=sys.stderr)
324+
170325
print("blob_summary<<EOF", file=sys.stdout)
171326
print('\n'.join(blob_content), file=sys.stdout)
172327
print("EOF", file=sys.stdout)
@@ -178,17 +333,38 @@ jobs:
178333
print("blob_summary<<EOF", file=sys.stdout)
179334
print(f"Error parsing module.yml: {e}", file=sys.stdout)
180335
print("EOF", file=sys.stdout)
336+
print("DEBUG: Python script completed successfully", file=sys.stderr)
181337
EOF
182338
183339
- name: Set output variables
340+
id: set-output
184341
run: |
185-
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
186-
cat diff_output.txt >> $GITHUB_OUTPUT
187-
echo "EOF" >> $GITHUB_OUTPUT
342+
echo "DEBUG: Checking if files exist..." >&2
343+
ls -la *.txt >&2 || echo "No .txt files found" >&2
344+
345+
if [ -f diff_output.txt ]; then
346+
echo "DEBUG: diff_output.txt exists, size: $(wc -c < diff_output.txt)" >&2
347+
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
348+
cat diff_output.txt >> $GITHUB_OUTPUT
349+
echo "EOF" >> $GITHUB_OUTPUT
350+
else
351+
echo "DEBUG: diff_output.txt not found" >&2
352+
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
353+
echo "No changes detected" >> $GITHUB_OUTPUT
354+
echo "EOF" >> $GITHUB_OUTPUT
355+
fi
188356
189-
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
190-
cat blob_summary.txt >> $GITHUB_OUTPUT
191-
echo "EOF" >> $GITHUB_OUTPUT
357+
if [ -f blob_summary.txt ]; then
358+
echo "DEBUG: blob_summary.txt exists, size: $(wc -c < blob_summary.txt)" >&2
359+
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
360+
cat blob_summary.txt >> $GITHUB_OUTPUT
361+
echo "EOF" >> $GITHUB_OUTPUT
362+
else
363+
echo "DEBUG: blob_summary.txt not found" >&2
364+
echo "blob_summary<<EOF" >> $GITHUB_OUTPUT
365+
echo "No blob summary available" >> $GITHUB_OUTPUT
366+
echo "EOF" >> $GITHUB_OUTPUT
367+
fi
192368
193369
- name: Create or update comment
194370
uses: actions/github-script@v7
@@ -228,8 +404,8 @@ jobs:
228404
});
229405
}
230406
env:
231-
diff_output: ${{ steps.changes.outputs.diff_output }}
232-
blob_summary: ${{ steps.changes.outputs.blob_summary }}
407+
diff_output: ${{ steps.set-output.outputs.diff_output }}
408+
blob_summary: ${{ steps.set-output.outputs.blob_summary }}
233409

234410

235411

@@ -239,7 +415,7 @@ jobs:
239415
echo "" >> $GITHUB_STEP_SUMMARY
240416
echo "### Changes in zephyr/module.yml:" >> $GITHUB_STEP_SUMMARY
241417
echo '```diff' >> $GITHUB_STEP_SUMMARY
242-
echo "${{ steps.changes.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
418+
echo "${{ steps.set-output.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
243419
echo '```' >> $GITHUB_STEP_SUMMARY
244420
echo "" >> $GITHUB_STEP_SUMMARY
245-
echo "${{ steps.changes.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY
421+
echo "${{ steps.set-output.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)