File 0373-gh-Format-all-markdown-release-bodies.patch of Package erlang
From 484d5b210838980314dbf7928a352fbd8b195ce1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Backstr=C3=B6m?= <lukas@erlang.org>
Date: Tue, 6 May 2025 15:16:11 +0200
Subject: [PATCH] gh: Format all markdown release bodies
The github markdown rendered for releases render newlines as
<br/> so the release notes tend to look a bit strange. This
change update dthe sync tool to format all the bodies of
all releases to look correct.
---
.github/scripts/sync-github-releases.sh | 46 +++++++++++++++++----
.github/workflows/sync-github-releases.yaml | 7 ++--
2 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/.github/scripts/sync-github-releases.sh b/.github/scripts/sync-github-releases.sh
index f0242ece07..9126a5f52f 100755
--- a/.github/scripts/sync-github-releases.sh
+++ b/.github/scripts/sync-github-releases.sh
@@ -41,7 +41,7 @@ set -e
REPOSITORY=${1}
TOKEN=${2:-"token ${GITHUB_TOKEN}"}
-RELEASE_FILTER=${3}
+RELEASE_FILTER=${3:-"^[2-9][1-9]\\..*"}
TIME_LIMIT=${4:-120m}
HDR=(-H "Authorization: ${TOKEN}")
REPO="https://api.github.com/repos/${REPOSITORY}"
@@ -69,6 +69,14 @@ _curl_patch() {
"${@}"
}
+_format_markdown() {
+ TMP_BODY=$(mktemp)
+ echo "${1}" > "${TMP_BODY}"
+ mdformat --wrap no "${TMP_BODY}"
+ cat "${TMP_BODY}"
+ rm -rf "${TMP_BODY}"
+}
+
RI=()
ALL_TAGS=()
CREATE_RELEASE=()
@@ -124,16 +132,30 @@ while [ "${TAG_URL}" != "" ]; do
}
## Check if we need to patch the body of the release
- if ! echo "${RELEASE}" | jq -e 'select(.body != "")' > /dev/null; then
+ RELEASE_BODY=$(echo "${RELEASE}" | jq --raw-output '.body' | tr -d '\015')
+ UPDATE_RELEASE_BODY=yes
+ if [ "${RELEASE_BODY}" != "" ]; then
+ ## Check if we need to reformat the body
+ FORMATTED_BODY=$(_format_markdown "${RELEASE_BODY}")
+ if [ "${FORMATTED_BODY}" = "${RELEASE_BODY}" ]; then
+ UPDATE_RELEASE_BODY=no
+ else
+ UPDATE_RELEASE_BODY=format
+ fi
+ rm -rf "${TMP_BODY}"
+ fi
+ if [ "${UPDATE_RELEASE_BODY}" != "no" ]; then
RELEASE_ID=$(echo "${RELEASE}" | jq '.id')
UPDATE_BODY=("${UPDATE_BODY[@]}" "${name}:${RELEASE_ID}")
- if [[ ${RELEASE_VSN} -gt 26 ]]; then
- RM="${name}.README.md"
- else
- RM="${name}.README"
+ if [ "${UPDATE_RELEASE_BODY}" = "yes" ]; then
+ if [[ ${RELEASE_VSN} -gt 26 ]]; then
+ RM="${name}.README.md"
+ else
+ RM="${name}.README"
+ fi
+ echo "Sync ${RM} for ${name} (for update of release body, release id = ${RELEASE_ID})"
+ RI=("${RM}" "${RI[@]}")
fi
- echo "Sync ${RM} for ${name} (for update of release body, release id = ${RELEASE_ID})"
- RI=("${RM}" "${RI[@]}")
fi
_asset "${name}.README" "${name}.README" "otp_src_${stripped_name}.readme"
@@ -201,6 +223,7 @@ for name in "${CREATE_RELEASE[@]}"; do
echo "Create release for ${name}"
stripped_name=$(_strip_name ${name})
if [ -s "downloads/${name}.README.md" ]; then
+ mdformat --wrap no "downloads/${name}.README.md"
README=$(cat downloads/${name}.README.md)
README=$(_json_escape "${README}")
elif [ -s "downloads/${name}.README" ]; then
@@ -229,11 +252,18 @@ for name_id in "${UPDATE_BODY[@]}"; do
name=$(echo "${name_id}" | awk -F: '{print $1}')
RELEASE_ID=$(echo "${name_id}" | awk -F: '{print $2}')
if [ -s downloads/"${name}.README.md" ]; then
+ mdformat --wrap no "downloads/${name}.README.md"
README=$(cat downloads/"${name}.README.md")
README=$(_json_escape "${README}")
elif [ -s downloads/"${name}.README" ]; then
README=$(cat downloads/"${name}.README")
README=$(_json_escape "$(printf '```\n%s\n```' "${README}")")
+ else
+ ## This happens when we should reformat an already existing description
+ RELEASE=$(_curl_get "${REPO}/releases/tags/${name}")
+ README=$(echo "${RELEASE}" | jq --raw-output '.body' | tr -d '\015')
+ README=$(_format_markdown "${README}")
+ README=$(_json_escape "${README}")
fi
echo "Update body of ${name}"
_curl_patch "${REPO}/releases/${RELEASE_ID}" -d "{\"body\":${README}}"
diff --git a/.github/workflows/sync-github-releases.yaml b/.github/workflows/sync-github-releases.yaml
index 29e0f5349b..d27c013e92 100644
--- a/.github/workflows/sync-github-releases.yaml
+++ b/.github/workflows/sync-github-releases.yaml
@@ -51,6 +51,7 @@ jobs:
- name: Sync releases
env:
ERLANG_ORG_TOKEN: ${{ secrets.TRIGGER_ERLANG_ORG_BUILD }}
- run: >
- .github/scripts/sync-github-releases.sh ${{ github.repository }}
- "Bearer ${{ secrets.GITHUB_TOKEN }}" "^[2-9][1-9]\\..*" 25m
+ run: |
+ pip install mdformat mdformat-gfm
+ .github/scripts/sync-github-releases.sh ${{ github.repository }} \
+ "Bearer ${{ secrets.GITHUB_TOKEN }}" "^[2-9][1-9]\\..*" 25m
--
2.43.0