From ff57c28af72d1a0ac0385800de57296d86008746 Mon Sep 17 00:00:00 2001 From: Chaithanya Balakavi Date: Fri, 15 May 2026 12:49:22 +0000 Subject: [PATCH] ci: fix the sed errors The workflow now uses a robust Python script to: - Generate the summary table and per-image details. - Extract and deduplicate the "What's Changed" sections from each image's release notes. - Fill the template placeholders in combined-release.md without sed, avoiding multiline and special character issues. - Present a full, clear, and non-duplicated combined release note. --- .../combined-release-template.md | 11 +++- .github/scripts/generate-combined-release.py | 58 +++++++++++++++++++ .github/workflows/combine-release.yml | 26 +-------- 3 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 .github/scripts/generate-combined-release.py diff --git a/.github/release-notes/combined-release-template.md b/.github/release-notes/combined-release-template.md index 9677aa2..93ef11a 100644 --- a/.github/release-notes/combined-release-template.md +++ b/.github/release-notes/combined-release-template.md @@ -6,10 +6,15 @@ --- -## Image Release Notes +## Image Quick Start & Details -{{IMAGE_NOTES}} +{{IMAGE_DETAILS}} --- -*This is an automated combined release. See individual image releases for detailed changelogs and instructions.* +## What's Changed + +{{WHATS_CHANGED}} + +--- +*This is an automated combined release. See individual image releases for more details.* diff --git a/.github/scripts/generate-combined-release.py b/.github/scripts/generate-combined-release.py new file mode 100644 index 0000000..73a8bb9 --- /dev/null +++ b/.github/scripts/generate-combined-release.py @@ -0,0 +1,58 @@ +import os +import re +import subprocess +import sys + +TEMPLATE_PATH = ".github/release-notes/combined-release-template.md" +OUTPUT_PATH = "combined-release.md" + +release_version = os.environ.get("RELEASE_VERSION") +artifacts_dir = os.getcwd() +images = ["core-image-minimal", "core-image-medtech"] + +# Generate summary table +summary_table = ["| Image | SSH Mode | Artifact |", "|-------|----------|----------|"] +image_details = [] +whats_changed_sections = set() + +# Find artifact folders (assume artifacts are in subdirs) +for f in sorted([x for x in os.listdir(artifacts_dir) if os.path.isdir(x)]): + for artifact in os.listdir(f): + img = "-".join(artifact.split("-")[:3]) + mode_match = re.search(r"(public-hardened|internal-keyed)", artifact) + mode = mode_match.group(1) if mode_match else "-" + summary_table.append(f"| {img} | {mode} | [{artifact}]({f}/{artifact}) |") + +for img in images: + tag = f"{img}-{release_version}" + try: + note = subprocess.check_output([ + "gh", "release", "view", tag, "--json", "body", "--jq", ".body" + ], text=True).strip() + except subprocess.CalledProcessError: + note = f"_No release notes found for {tag}_" + # Extract What's Changed section + match = re.search(r"(?s)(##? What's Changed.*?)(?:\n##|\Z)", note) + if match: + whats_changed_sections.add(match.group(1).strip()) + # Remove What's Changed from image details + note_wo_wc = re.sub(r"(?s)##? What's Changed.*", "", note).strip() + image_details.append(f"### {img}\n\n{note_wo_wc}\n") + +# Combine What's Changed sections, deduplicated +whats_changed = '\n\n'.join(sorted(whats_changed_sections)) if whats_changed_sections else '_No changes found._' + +# Read template +with open(TEMPLATE_PATH, 'r') as f: + template = f.read() + +# Replace placeholders +out = template.replace('{{RELEASE_VERSION}}', release_version) +out = out.replace('{{SUMMARY_TABLE}}', '\n'.join(summary_table)) +out = out.replace('{{IMAGE_DETAILS}}', '\n'.join(image_details)) +out = out.replace('{{WHATS_CHANGED}}', whats_changed) + +with open(OUTPUT_PATH, 'w') as f: + f.write(out) + +print(f"Combined release notes written to {OUTPUT_PATH}") diff --git a/.github/workflows/combine-release.yml b/.github/workflows/combine-release.yml index 6373446..fdcec1b 100644 --- a/.github/workflows/combine-release.yml +++ b/.github/workflows/combine-release.yml @@ -38,33 +38,11 @@ jobs: - name: Prepare combined release notes from template id: notes run: | - set -e - cp .github/release-notes/combined-release-template.md combined-release.md - - # Generate summary table - summary_table="| Image | SSH Mode | Artifact |\n|-------|----------|----------|" - for f in */*; do - img=$(echo "$f" | cut -d'-' -f1-3 | sed 's#/.*$##') - mode=$(echo "$f" | grep -oE '(public-hardened|internal-keyed)' || echo '-') - summary_table+="\n| $img | $mode | [$(basename "$f")]($f) |" - done - - # Generate image notes - image_notes="" - for img in core-image-minimal core-image-medtech; do - tag="$img-${{ github.event.inputs.release_version }}" - image_notes+="\n### $img\n" - note=$(gh release view "$tag" --json body --jq '.body' 2>/dev/null || echo "_No release notes found for $tag_") - image_notes+="$note\n" - done - - # Replace placeholders in template - sed -i "s|{{RELEASE_VERSION}}|${{ github.event.inputs.release_version }}|g" combined-release.md - sed -i "s|{{SUMMARY_TABLE}}|$summary_table|g" combined-release.md - sed -i "s|{{IMAGE_NOTES}}|$image_notes|g" combined-release.md + python .github/scripts/generate-combined-release.py cat combined-release.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_VERSION: ${{ github.event.inputs.release_version }} - name: Upload combined release notes uses: actions/upload-artifact@v4