Skip to content

Commit 0ea3d42

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 0ea3d42

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
fetch-depth: 0
23+
persist-credentials: false
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
27+
with:
28+
python-version: 3.12
29+
cache: pip
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" ]; 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'
99+
uses: actions/github-script@d7906e4ad0b1822421a7e57a40e5a1d82c19f2a5 # v7.0.1
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+
if (existingComment) {
118+
await github.rest.issues.updateComment({
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
comment_id: existingComment.id,
122+
body: commentBody
123+
});
124+
} else {
125+
await github.rest.issues.createComment({
126+
owner: context.repo.owner,
127+
repo: context.repo.repo,
128+
issue_number: context.issue.number,
129+
body: commentBody
130+
});
131+
}
132+
env:
133+
diff_output: ${{ steps.changes.outputs.diff_output }}
134+
blob_summary: ${{ steps.changes.outputs.blob_summary }}
135+
136+
- name: Create commit comment (Push)
137+
if: github.event_name == 'push'
138+
uses: actions/github-script@d7906e4ad0b1822421a7e57a40e5a1d82c19f2a5 # v7.0.1
139+
with:
140+
script: |
141+
const commentBody = 'Module Monitor\n\nChanges detected in module.yml\n\n' +
142+
(process.env.diff_output || 'No changes detected') + '\n\n' +
143+
(process.env.blob_summary || '') + '\n\n' +
144+
'This comment was automatically generated.';
145+
146+
await github.rest.repos.createCommitComment({
147+
owner: context.repo.owner,
148+
repo: context.repo.repo,
149+
commit_sha: context.sha,
150+
body: commentBody
151+
});
152+
env:
153+
diff_output: ${{ steps.changes.outputs.diff_output }}
154+
blob_summary: ${{ steps.changes.outputs.blob_summary }}
155+
156+
- name: Output summary
157+
run: |
158+
echo "## Module Monitor Summary" >> $GITHUB_STEP_SUMMARY
159+
echo "" >> $GITHUB_STEP_SUMMARY
160+
echo "### Changes in zephyr/module.yml:" >> $GITHUB_STEP_SUMMARY
161+
echo '```diff' >> $GITHUB_STEP_SUMMARY
162+
echo "${{ steps.changes.outputs.diff_output }}" >> $GITHUB_STEP_SUMMARY
163+
echo '```' >> $GITHUB_STEP_SUMMARY
164+
echo "" >> $GITHUB_STEP_SUMMARY
165+
echo "${{ steps.changes.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)