From efc581b5e66efde4b2329f11d4a054f5146fcc0c Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 16 May 2026 18:07:09 -0400 Subject: [PATCH] fix(update-flathub-repo): Improve Flathub metainfo changelog insertion Set CHANGELOG from the release body and robustly insert it into the generated .metainfo.xml. Escape XML-sensitive characters (&, <, >), disable patsub_replacement to treat replacement text literally, and read the full metainfo file while preserving newlines. Fail with a clear error if the expected placeholder is missing. Replace the placeholder using Bash string substitution and write the updated contents back (replacing the previous sed-based approach) to avoid issues with sed and multiline input. --- .../workflows/__call-update-flathub-repo.yml | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/__call-update-flathub-repo.yml b/.github/workflows/__call-update-flathub-repo.yml index 86a8726c..dc7182f0 100644 --- a/.github/workflows/__call-update-flathub-repo.yml +++ b/.github/workflows/__call-update-flathub-repo.yml @@ -130,15 +130,34 @@ jobs: if: >- steps.check-label.outputs.hasTopic == 'true' && steps.check-release.outputs.isLatestRelease == 'true' + env: + CHANGELOG: ${{ github.event.release.body }} run: | + # Set the metainfo file and placeholder generated by the release asset. xml_file="flathub/${{ env.FLATHUB_PKG }}/${{ env.FLATHUB_PKG }}.metainfo.xml" + placeholder="" + + # Treat replacement text literally during Bash parameter substitutions. + shopt -u patsub_replacement 2>/dev/null || true + + # Escape XML-sensitive characters from the release body. + changelog="${CHANGELOG:-}" + changelog="${changelog//&/&}" + changelog="${changelog///>}" + + # Read the full metainfo file, preserving newlines. + IFS= read -r -d '' contents < "$xml_file" || true - # Extract release information - changelog="${{ github.event.release.body }}" && changelog="${changelog//&/&}" && \ - changelog="${changelog///>}" + # Fail clearly if the generated metainfo file no longer has the expected marker. + if [[ "$contents" != *"$placeholder"* ]]; then + echo "$placeholder not found in $xml_file" + exit 1 + fi - # Replace changelog placeholder with actual changelog - sed -i "s||$changelog|g" "$xml_file" + # Replace the placeholder with the escaped changelog and write the file back. + contents="${contents//$placeholder/$changelog}" + printf '%s' "$contents" > "$xml_file" - name: Update submodule if: >-