Skip to content

test: Update default firmware version to trigger module monitor workflow #2

test: Update default firmware version to trigger module monitor workflow

test: Update default firmware version to trigger module monitor workflow #2

Workflow file for this run

name: Module Monitor
on:
push:
branches:
- main
- master
paths:
- 'zephyr/module.yml'
pull_request_target:
paths:
- 'zephyr/module.yml'
permissions:
contents: read
pull-requests: write
jobs:
module-monitor:
runs-on: ubuntu-24.04
name: Monitor Module Changes
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: 3.12
cache: pip
- name: Install PyYAML
run: |
pip install pyyaml
- name: Get module.yml changes and blob info
id: changes
run: |
# For pull requests, compare with base branch
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_REF="${{ github.event.pull_request.base.sha }}"
HEAD_REF="${{ github.event.pull_request.head.sha }}"
DIFF_OUTPUT=$(git diff $BASE_REF $HEAD_REF -- zephyr/module.yml || echo "No changes found")
else
# For push events, get the previous commit that modified module.yml
PREV_COMMIT=$(git log --oneline --follow -- zephyr/module.yml | head -2 | tail -1 | cut -d' ' -f1)
if [ -n "$PREV_COMMIT" ]; then
DIFF_OUTPUT=$(git diff $PREV_COMMIT HEAD -- zephyr/module.yml || echo "No changes found")
else
DIFF_OUTPUT="No previous commit found for module.yml"
fi
fi
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Parse YAML and extract blob information with version comparison
python3 << 'EOF'
import yaml

Check failure on line 62 in .github/workflows/module-monitor.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/module-monitor.yml

Invalid workflow file

You have an error in your yaml syntax on line 62
import sys
import os
import re
import requests
from urllib.parse import urlparse
def extract_commit_from_url(url):
"""Extract commit hash from GitHub URL"""
# Pattern for GitHub raw URLs with commit hash
pattern = r'raw/([a-f0-9]{40})/'
match = re.search(pattern, url)
if match:
return match.group(1)
return None
def get_github_api_url(url):
"""Convert raw GitHub URL to API URL to get file info"""
# Convert: https://github.com/nrfconnect/sdk-nrfxlib/raw/commit/bin/file.bin
# To: https://api.github.com/repos/nrfconnect/sdk-nrfxlib/git/blobs/commit
pattern = r'github\.com/([^/]+/[^/]+)/raw/([a-f0-9]{40})/(.+)'
match = re.search(pattern, url)
if match:
repo = match.group(1)
commit = match.group(2)
path = match.group(3)
return f"https://api.github.com/repos/{repo}/contents/{path}?ref={commit}"
return None
try:
# Read current module.yml
with open('zephyr/module.yml', 'r') as f:
current_data = yaml.safe_load(f)
# Read previous module.yml if it exists
previous_data = None
if "${{ github.event_name }}" == "pull_request":
# For PR, we need to checkout the base branch to get previous data
os.system("git checkout ${{ github.event.pull_request.base.sha }} -- zephyr/module.yml")
if os.path.exists('zephyr/module.yml'):
with open('zephyr/module.yml', 'r') as f:
previous_data = yaml.safe_load(f)
# Restore current version
os.system("git checkout ${{ github.event.pull_request.head.sha }} -- zephyr/module.yml")
else:
# For push, get previous commit
prev_commit = os.popen("git log --oneline --follow -- zephyr/module.yml | head -2 | tail -1 | cut -d' ' -f1").read().strip()
if prev_commit:
os.system(f"git show {prev_commit}:zephyr/module.yml > /tmp/previous_module.yml")
if os.path.exists('/tmp/previous_module.yml'):
with open('/tmp/previous_module.yml', 'r') as f:
previous_data = yaml.safe_load(f)
# Create comparison table
table_rows = []
current_blobs = current_data.get('blobs', [])
previous_blobs = previous_data.get('blobs', []) if previous_data else []
# Create lookup for previous blobs
prev_lookup = {}
for blob in previous_blobs:
path = blob.get('path', '')
prev_lookup[path] = blob
for blob in current_blobs:
path = blob.get('path', 'Unknown')
current_version = blob.get('version', 'Unknown')
current_sha256 = blob.get('sha256', 'Unknown')
current_url = blob.get('url', '')
# Extract variant name from path
variant = path.split('/')[-2] if '/' in path else 'Unknown'
# Get previous info
prev_blob = prev_lookup.get(path, {})
prev_version = prev_blob.get('version', 'N/A')
prev_sha256 = prev_blob.get('sha256', 'N/A')
# Extract commit from URL
commit = extract_commit_from_url(current_url)
commit_short = commit[:8] if commit else 'N/A'
# Create diff link if we have both URLs
prev_url = prev_blob.get('url', '')
if prev_url and current_url and prev_url != current_url:
# Extract repo info for diff link
repo_match = re.search(r'github\.com/([^/]+/[^/]+)/', current_url)
if repo_match:
repo = repo_match.group(1)
diff_link = f"https://github.com/{repo}/compare/{extract_commit_from_url(prev_url)[:8]}...{commit_short}"
else:
diff_link = "N/A"
else:
diff_link = "N/A"
table_rows.append({
'variant': variant,
'old_version': prev_version,
'new_version': current_version,
'old_sha256': prev_sha256[:16] + '...' if len(prev_sha256) > 16 else prev_sha256,
'new_sha256': current_sha256[:16] + '...' if len(current_sha256) > 16 else current_sha256,
'commit': commit_short,
'diff_link': diff_link
})
# Generate table output
print("blob_table<<EOF", file=sys.stdout)
if table_rows:
print("| Variant | Old Version | New Version | Old SHA256 | New SHA256 | Commit | Diff |", file=sys.stdout)
print("|---------|-------------|-------------|------------|------------|--------|------|", file=sys.stdout)
for row in table_rows:
diff_markdown = f"[{row['commit']}]({row['diff_link']})" if row['diff_link'] != "N/A" else "N/A"
print(f"| {row['variant']} | {row['old_version']} | {row['new_version']} | {row['old_sha256']} | {row['new_sha256']} | {row['commit']} | {diff_markdown} |", file=sys.stdout)
else:
print("No firmware blob changes detected.", file=sys.stdout)
print("EOF", file=sys.stdout)
# Also generate current blob summary
if current_blobs:
blob_info = []
for blob in current_blobs:
info = f"- **{blob.get('path', 'Unknown')}**\n"
info += f" - Version: {blob.get('version', 'Unknown')}\n"
info += f" - SHA256: {blob.get('sha256', 'Unknown')[:16]}...\n"
info += f" - Type: {blob.get('type', 'Unknown')}\n"
info += f" - Description: {blob.get('description', 'No description')}\n"
blob_info.append(info)
print("blob_summary<<EOF", file=sys.stdout)
print("## Current Firmware Blobs:", file=sys.stdout)
for info in blob_info:
print(info, file=sys.stdout)
print("EOF", file=sys.stdout)
else:
print("blob_summary<<EOF", file=sys.stdout)
print("No blobs found in module.yml", file=sys.stdout)
print("EOF", file=sys.stdout)
except Exception as e:
print("blob_table<<EOF", file=sys.stdout)
print(f"Error generating blob table: {e}", file=sys.stdout)
print("EOF", file=sys.stdout)
print("blob_summary<<EOF", file=sys.stdout)
print(f"Error parsing module.yml: {e}", file=sys.stdout)
print("EOF", file=sys.stdout)
EOF
- name: Create or update comment (Pull Request)
if: github.event_name == 'pull_request'
uses: actions/github-script@d7906e4ad0b1822421a7e57a40e5a1d82c19f2a5 # v7.0.1
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
// Find existing comment with our signature
const existingComment = comments.find(comment =>
comment.body.includes('🤖 **Module Monitor**')
);
const commentBody = `🤖 **Module Monitor**
## Firmware Blob Changes
The following firmware blobs have changed in this update:
${process.env.blob_table || 'No changes detected'}
${process.env.blob_summary || ''}
---
*This comment was automatically generated by the Module Monitor workflow*`;
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
env:
blob_table: ${{ steps.changes.outputs.blob_table }}
blob_summary: ${{ steps.changes.outputs.blob_summary }}
- name: Create commit comment (Push)
if: github.event_name == 'push'
uses: actions/github-script@d7906e4ad0b1822421a7e57a40e5a1d82c19f2a5 # v7.0.1
with:
script: |
const commentBody = `🤖 **Module Monitor**
## Firmware Blob Changes
The following firmware blobs have changed in this update:
${process.env.blob_table || 'No changes detected'}
${process.env.blob_summary || ''}
---
*This comment was automatically generated by the Module Monitor workflow*`;
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: commentBody
});
env:
blob_table: ${{ steps.changes.outputs.blob_table }}
blob_summary: ${{ steps.changes.outputs.blob_summary }}
- name: Output summary
run: |
echo "## Module Monitor Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Firmware Blob Changes:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.changes.outputs.blob_table }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.changes.outputs.blob_summary }}" >> $GITHUB_STEP_SUMMARY