Skip to content

Commit b3877b6

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 b3877b6

File tree

1 file changed

+164
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)