Skip to content

Commit db05241

Browse files
committed
ci: Add an action to publish FW blob information
This is based on manifest GH action in Zephyr and publishes the blob information. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent ee35b36 commit db05241

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Module Monitor
2+
on:
3+
push:
4+
paths:
5+
- 'zephyr/module.yml'
6+
pull_request_target:
7+
paths:
8+
- 'zephyr/module.yml'
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
issues: write
14+
15+
jobs:
16+
module-monitor:
17+
runs-on: ubuntu-24.04
18+
name: Monitor Module Changes
19+
steps:
20+
- name: Checkout the code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
persist-credentials: false
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.12
30+
31+
- name: Install PyYAML
32+
run: |
33+
pip install pyyaml
34+
35+
- name: Get module.yml changes and blob info
36+
id: changes
37+
env:
38+
GITHUB_EVENT_NAME: ${{ github.event_name }}
39+
GITHUB_BASE_SHA: ${{ github.event.pull_request.base.sha || '' }}
40+
GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha || '' }}
41+
run: |
42+
# For pull requests, compare with base branch
43+
if [ "$GITHUB_EVENT_NAME" = "pull_request_target" ]; then
44+
BASE_REF="$GITHUB_BASE_SHA"
45+
HEAD_REF="$GITHUB_HEAD_SHA"
46+
DIFF_OUTPUT=$(git diff $BASE_REF $HEAD_REF -- zephyr/module.yml || echo "No changes found")
47+
else
48+
# For push events, get the previous commit that modified module.yml
49+
PREV_COMMIT=$(git log --oneline --follow -- zephyr/module.yml | head -2 | tail -1 | cut -d' ' -f1)
50+
if [ -n "$PREV_COMMIT" ]; then
51+
DIFF_OUTPUT=$(git diff $PREV_COMMIT HEAD -- zephyr/module.yml || echo "No changes found")
52+
else
53+
DIFF_OUTPUT="No previous commit found for module.yml"
54+
fi
55+
fi
56+
57+
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
58+
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
59+
echo "EOF" >> $GITHUB_OUTPUT
60+
61+
# Parse YAML and extract blob information
62+
python3 << 'EOF'
63+
import yaml
64+
import sys
65+
import os
66+
67+
try:
68+
with open('zephyr/module.yml', 'r') as f:
69+
data = yaml.safe_load(f)
70+
71+
if 'blobs' in data:
72+
blob_info = []
73+
for blob in data['blobs']:
74+
info = f"- **{blob.get('path', 'Unknown')}**\n"
75+
info += f" - Version: {blob.get('version', 'Unknown')}\n"
76+
info += f" - SHA256: {blob.get('sha256', 'Unknown')[:16]}...\n"
77+
info += f" - Type: {blob.get('type', 'Unknown')}\n"
78+
info += f" - Description: {blob.get('description', 'No description')}\n"
79+
blob_info.append(info)
80+
81+
print("blob_summary<<EOF", file=sys.stdout)
82+
print("## Current Firmware Blobs:", file=sys.stdout)
83+
for info in blob_info:
84+
print(info, file=sys.stdout)
85+
print("EOF", file=sys.stdout)
86+
else:
87+
print("blob_summary<<EOF", file=sys.stdout)
88+
print("No blobs found in module.yml", file=sys.stdout)
89+
print("EOF", file=sys.stdout)
90+
91+
except Exception as e:
92+
print("blob_summary<<EOF", file=sys.stdout)
93+
print(f"Error parsing module.yml: {e}", file=sys.stdout)
94+
print("EOF", file=sys.stdout)
95+
EOF
96+
97+
- name: Create or update comment (Pull Request)
98+
if: github.event_name == 'pull_request_target'
99+
uses: actions/github-script@v7
100+
with:
101+
script: |
102+
const { data: comments } = await github.rest.issues.listComments({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
issue_number: context.issue.number
106+
});
107+
108+
const existingComment = comments.find(comment =>
109+
comment.body.includes('Module Monitor')
110+
);
111+
112+
const commentBody = 'Module Monitor\n\nChanges detected in module.yml\n\n' +
113+
(process.env.diff_output || 'No changes detected') + '\n\n' +
114+
(process.env.blob_summary || '') + '\n\n' +
115+
'This comment was automatically generated.';
116+
117+
try {
118+
if (existingComment) {
119+
await github.rest.issues.updateComment({
120+
owner: context.repo.owner,
121+
repo: context.repo.repo,
122+
comment_id: existingComment.id,
123+
body: commentBody
124+
});
125+
} else {
126+
await github.rest.issues.createComment({
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
issue_number: context.issue.number,
130+
body: commentBody
131+
});
132+
}
133+
} catch (error) {
134+
console.log('Could not create/update comment due to permissions. This is normal for forks.');
135+
console.log('Error:', error.message);
136+
}
137+
env:
138+
diff_output: ${{ steps.changes.outputs.diff_output }}
139+
blob_summary: ${{ steps.changes.outputs.blob_summary }}
140+
141+
- name: Create commit comment (Push)
142+
if: github.event_name == 'push'
143+
uses: actions/github-script@v7
144+
with:
145+
script: |
146+
const commentBody = 'Module Monitor\n\nChanges detected in module.yml\n\n' +
147+
(process.env.diff_output || 'No changes detected') + '\n\n' +
148+
(process.env.blob_summary || '') + '\n\n' +
149+
'This comment was automatically generated.';
150+
151+
try {
152+
await github.rest.repos.createCommitComment({
153+
owner: context.repo.owner,
154+
repo: context.repo.repo,
155+
commit_sha: context.sha,
156+
body: commentBody
157+
});
158+
} catch (error) {
159+
console.log('Could not create commit comment due to permissions. This is normal for forks.');
160+
console.log('Error:', error.message);
161+
}
162+
env:
163+
diff_output: ${{ steps.changes.outputs.diff_output }}
164+
blob_summary: ${{ steps.changes.outputs.blob_summary }}
165+
166+
- name: Output summary
167+
run: |
168+
echo "## Module Monitor Summary" >> $GITHUB_STEP_SUMMARY
169+
echo "" >> $GITHUB_STEP_SUMMARY
170+
echo "### Changes in zephyr/module.yml:" >> $GITHUB_STEP_SUMMARY
171+
echo '```diff' >> $GITHUB_STEP_SUMMARY
172+
echo "${{ steps.changes.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
173+
echo '```' >> $GITHUB_STEP_SUMMARY
174+
echo "" >> $GITHUB_STEP_SUMMARY
175+
echo "${{ steps.changes.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)