Skip to content

Commit 2ca2dd3

Browse files
committed
ci: Fix format
Signed-off-by: Chaitanya Tata <[email protected]>
1 parent c8a6d4d commit 2ca2dd3

File tree

1 file changed

+91
-26
lines changed

1 file changed

+91
-26
lines changed

.github/workflows/module-monitor.yml

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,109 @@ jobs:
4747
echo "DEBUG: Current HEAD is $(git rev-parse HEAD)" >&2
4848
echo "DEBUG: Available commits:" >&2
4949
git log --oneline -5 >&2
50-
DIFF_OUTPUT=$(git diff $BASE_REF $HEAD_REF -- zephyr/module.yml || echo "No changes found")
51-
echo "DEBUG: Diff result: $DIFF_OUTPUT" >&2
5250
53-
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
54-
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
55-
echo "EOF" >> $GITHUB_OUTPUT
51+
# Get old and new module.yml content
52+
git show $BASE_REF:zephyr/module.yml > old_module.yml
53+
cp zephyr/module.yml new_module.yml
5654
57-
# Parse YAML and extract blob information
55+
# Parse YAML and generate comparison table
5856
python3 << 'EOF'
5957
import yaml
6058
import sys
6159
import os
60+
import re
61+
from urllib.parse import urlparse
62+
63+
def extract_commit_from_url(url):
64+
"""Extract commit hash from GitHub raw URL"""
65+
if 'raw/' in url:
66+
parts = url.split('raw/')
67+
if len(parts) > 1:
68+
commit_part = parts[1].split('/')[0]
69+
if len(commit_part) == 40: # Full SHA
70+
return commit_part
71+
elif len(commit_part) >= 7: # Short SHA
72+
return commit_part[:7]
73+
return "Unknown"
74+
75+
def generate_diff_link(url):
76+
"""Generate diff link for the source repository"""
77+
if 'github.com' in url and 'raw/' in url:
78+
# Convert raw URL to repository URL
79+
repo_url = url.replace('/raw/', '/blob/')
80+
# Extract commit and path
81+
if '/raw/' in url:
82+
parts = url.split('/raw/')
83+
if len(parts) > 1:
84+
commit_path = parts[1]
85+
commit = commit_path.split('/')[0]
86+
path = '/'.join(commit_path.split('/')[1:])
87+
# Create diff link (this would need to be updated with actual previous commit)
88+
return f"https://github.com/nrfconnect/sdk-nrfxlib/compare/{commit}...{commit}"
89+
return "N/A"
6290
6391
try:
64-
with open('zephyr/module.yml', 'r') as f:
65-
data = yaml.safe_load(f)
92+
# Load old and new module.yml
93+
with open('old_module.yml', 'r') as f:
94+
old_data = yaml.safe_load(f)
95+
with open('new_module.yml', 'r') as f:
96+
new_data = yaml.safe_load(f)
97+
98+
old_blobs = {blob['path']: blob for blob in old_data.get('blobs', [])}
99+
new_blobs = {blob['path']: blob for blob in new_data.get('blobs', [])}
100+
101+
# Generate comparison table
102+
table_rows = []
103+
table_rows.append("| Variant | Old Version | New Version | Old SHA256 | New SHA256 | Old Commit | New Commit | Diff Link |")
104+
table_rows.append("|---------|-------------|-------------|------------|------------|------------|------------|-----------|")
66105
67-
if 'blobs' in data:
68-
blob_info = []
69-
for blob in data['blobs']:
70-
info = f"- **{blob.get('path', 'Unknown')}**\n"
71-
info += f" - Version: {blob.get('version', 'Unknown')}\n"
72-
info += f" - SHA256: {blob.get('sha256', 'Unknown')[:16]}...\n"
73-
info += f" - Type: {blob.get('type', 'Unknown')}\n"
74-
info += f" - Description: {blob.get('description', 'No description')}\n"
75-
blob_info.append(info)
106+
all_paths = set(old_blobs.keys()) | set(new_blobs.keys())
107+
108+
for path in sorted(all_paths):
109+
old_blob = old_blobs.get(path, {})
110+
new_blob = new_blobs.get(path, {})
111+
112+
old_version = old_blob.get('version', 'N/A')
113+
new_version = new_blob.get('version', 'N/A')
114+
old_sha = old_blob.get('sha256', 'N/A')[:16] + '...' if old_blob.get('sha256') else 'N/A'
115+
new_sha = new_blob.get('sha256', 'N/A')[:16] + '...' if new_blob.get('sha256') else 'N/A'
116+
old_commit = extract_commit_from_url(old_blob.get('url', ''))
117+
new_commit = extract_commit_from_url(new_blob.get('url', ''))
118+
diff_link = generate_diff_link(new_blob.get('url', ''))
119+
120+
# Extract variant name from path
121+
variant = path.split('/')[-2] if '/' in path else path
76122
77-
print("blob_summary<<EOF", file=sys.stdout)
78-
print("## Current Firmware Blobs:", file=sys.stdout)
79-
for info in blob_info:
80-
print(info, file=sys.stdout)
81-
print("EOF", file=sys.stdout)
82-
else:
83-
print("blob_summary<<EOF", file=sys.stdout)
84-
print("No blobs found in module.yml", file=sys.stdout)
85-
print("EOF", file=sys.stdout)
123+
table_rows.append(f"| {variant} | {old_version} | {new_version} | {old_sha} | {new_sha} | {old_commit} | {new_commit} | {diff_link} |")
124+
125+
# Output the table
126+
print("diff_output<<EOF", file=sys.stdout)
127+
print("## Firmware Blob Changes", file=sys.stdout)
128+
print("", file=sys.stdout)
129+
for row in table_rows:
130+
print(row, file=sys.stdout)
131+
print("EOF", file=sys.stdout)
132+
133+
# Also output current blob summary
134+
blob_info = []
135+
for blob in new_data.get('blobs', []):
136+
info = f"- **{blob.get('path', 'Unknown')}**\n"
137+
info += f" - Version: {blob.get('version', 'Unknown')}\n"
138+
info += f" - SHA256: {blob.get('sha256', 'Unknown')[:16]}...\n"
139+
info += f" - Type: {blob.get('type', 'Unknown')}\n"
140+
info += f" - Description: {blob.get('description', 'No description')}\n"
141+
blob_info.append(info)
142+
143+
print("blob_summary<<EOF", file=sys.stdout)
144+
print("## Current Firmware Blobs:", file=sys.stdout)
145+
for info in blob_info:
146+
print(info, file=sys.stdout)
147+
print("EOF", file=sys.stdout)
86148
87149
except Exception as e:
150+
print("diff_output<<EOF", file=sys.stdout)
151+
print(f"Error generating comparison: {e}", file=sys.stdout)
152+
print("EOF", file=sys.stdout)
88153
print("blob_summary<<EOF", file=sys.stdout)
89154
print(f"Error parsing module.yml: {e}", file=sys.stdout)
90155
print("EOF", file=sys.stdout)

0 commit comments

Comments
 (0)