Skip to content

Commit 76c7feb

Browse files
committed
ci: Fix version and add DNM handling
* Fix version - it should be reverse * In case of PR reference add a DNM and if not remove DNM label Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 857d9da commit 76c7feb

File tree

1 file changed

+96
-3
lines changed

1 file changed

+96
-3
lines changed

.github/workflows/module-monitor.yml

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ jobs:
8686
return commit_part[:7]
8787
return "Unknown"
8888
89+
def parse_version(version_str):
90+
"""Parse and fix version string format"""
91+
if version_str == 'N/A':
92+
return version_str
93+
94+
# Split by dots and reverse the order if it looks like it's reversed
95+
parts = version_str.split('.')
96+
if len(parts) >= 4:
97+
# Check if the version looks reversed (e.g., 2.14.2.1 should be 1.2.14.2)
98+
# If the first part is larger than the last part, it's likely reversed
99+
try:
100+
first_part = int(parts[0])
101+
last_part = int(parts[-1])
102+
if first_part > last_part and first_part > 10:
103+
# Reverse the parts
104+
parts = parts[::-1]
105+
return '.'.join(parts)
106+
except ValueError:
107+
# If we can't parse as integers, return as is
108+
pass
109+
110+
return version_str
111+
89112
def get_commit_info(commit_hash):
90113
"""Get additional commit information like branch and PR references"""
91114
try:
@@ -228,8 +251,8 @@ jobs:
228251
old_blob = old_blobs.get(path, {})
229252
new_blob = new_blobs.get(path, {})
230253
231-
old_version = old_blob.get('version', 'N/A')
232-
new_version = new_blob.get('version', 'N/A')
254+
old_version = parse_version(old_blob.get('version', 'N/A'))
255+
new_version = parse_version(new_blob.get('version', 'N/A'))
233256
old_commit_hash = extract_commit_from_url(old_blob.get('url', ''))
234257
new_commit_hash = extract_commit_from_url(new_blob.get('url', ''))
235258
@@ -286,7 +309,7 @@ jobs:
286309
287310
for path in sorted(all_paths):
288311
new_blob = new_blobs.get(path, {})
289-
version = new_blob.get('version', 'N/A')
312+
version = parse_version(new_blob.get('version', 'N/A'))
290313
commit_hash = extract_commit_from_url(new_blob.get('url', ''))
291314
commit_display = commit_hash[:7] if commit_hash != "Unknown" else "Unknown"
292315
@@ -297,6 +320,23 @@ jobs:
297320
298321
diff_content.extend(summary_rows)
299322
323+
# Check for PR references to determine if DNM label should be added/removed
324+
has_pr_reference = False
325+
try:
326+
with open('new_module.yml', 'r') as f:
327+
content = f.read()
328+
# Look for PR metadata comment
329+
pr_match = re.search(r'# Generated from PR #(\d+) \(commit: ([a-f0-9]+)\)', content)
330+
if pr_match:
331+
has_pr_reference = True
332+
print(f"DEBUG: Found PR reference: PR #{pr_match.group(1)}", file=sys.stderr)
333+
except Exception as e:
334+
print(f"DEBUG: Error checking for PR reference: {e}", file=sys.stderr)
335+
336+
# Write PR reference status to file for GitHub Actions
337+
with open('pr_reference_status.txt', 'w') as f:
338+
f.write('true' if has_pr_reference else 'false')
339+
300340
# Write to file for GitHub Actions output
301341
print(f"DEBUG: Writing {len(diff_content)} lines to diff_output.txt", file=sys.stderr)
302342
with open('diff_output.txt', 'w') as f:
@@ -325,6 +365,15 @@ jobs:
325365
echo "diff_output_encoded=" >> $GITHUB_OUTPUT
326366
fi
327367
368+
if [ -f pr_reference_status.txt ]; then
369+
echo "DEBUG: pr_reference_status.txt exists" >&2
370+
PR_REFERENCE_STATUS=$(cat pr_reference_status.txt)
371+
echo "has_pr_reference=$PR_REFERENCE_STATUS" >> $GITHUB_OUTPUT
372+
else
373+
echo "DEBUG: pr_reference_status.txt not found" >&2
374+
echo "has_pr_reference=false" >> $GITHUB_OUTPUT
375+
fi
376+
328377
329378
330379
- name: Create or update comment
@@ -349,6 +398,49 @@ jobs:
349398
diffOutput + '\n\n' +
350399
'This comment was automatically generated.';
351400
401+
// Handle DNM label management
402+
const hasPrReference = process.env.has_pr_reference === 'true';
403+
console.log('DEBUG: has_pr_reference:', hasPrReference);
404+
405+
try {
406+
// Get current labels
407+
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
408+
owner: context.repo.owner,
409+
repo: context.repo.repo,
410+
issue_number: context.issue.number
411+
});
412+
413+
const hasDnmLabel = currentLabels.some(label => label.name === 'DNM');
414+
console.log('DEBUG: Current DNM label status:', hasDnmLabel);
415+
416+
// Add DNM label if PR reference is found and label doesn't exist
417+
if (hasPrReference && !hasDnmLabel) {
418+
console.log('Adding DNM label due to PR reference');
419+
await github.rest.issues.addLabels({
420+
owner: context.repo.owner,
421+
repo: context.repo.repo,
422+
issue_number: context.issue.number,
423+
labels: ['DNM']
424+
});
425+
}
426+
// Remove DNM label if PR reference is gone and label exists
427+
else if (!hasPrReference && hasDnmLabel) {
428+
console.log('Removing DNM label as PR reference is gone');
429+
await github.rest.issues.removeLabel({
430+
owner: context.repo.owner,
431+
repo: context.repo.repo,
432+
issue_number: context.issue.number,
433+
name: 'DNM'
434+
});
435+
}
436+
else {
437+
console.log('No DNM label action needed');
438+
}
439+
} catch (error) {
440+
console.log('Could not manage DNM label due to permissions or other error.');
441+
console.log('Error:', error.message);
442+
}
443+
352444
try {
353445
const { data: comments } = await github.rest.issues.listComments({
354446
owner: context.repo.owner,
@@ -390,6 +482,7 @@ jobs:
390482
}
391483
env:
392484
diff_output_encoded: ${{ steps.set-output.outputs.diff_output_encoded }}
485+
has_pr_reference: ${{ steps.set-output.outputs.has_pr_reference }}
393486

394487

395488

0 commit comments

Comments
 (0)