Skip to content

Instantly share code, notes, and snippets.

@vszakats
Last active April 4, 2024 09:41
Show Gist options
  • Save vszakats/70dbe907de571c2beaa5e793d4f868da to your computer and use it in GitHub Desktop.
Save vszakats/70dbe907de571c2beaa5e793d4f868da to your computer and use it in GitHub Desktop.
libssh2 RELEASE-NOTES helper
#!/usr/bin/env bash
# Copyright (C) Viktor Szakats
# SPDX-License-Identifier: BSD-3-Clause
# 1. $ git format-patch "$(git describe --abbrev=0)"
# 2. Move low-impact commits to a subdirectory (e.g. 'unused')
# 3. Edit subjects as needed, add module prefix, fix typos, add backtick quotes, fix casing, shorten
# 4. Fixup author names, casing, add 'on github', fixup non-standard markup
# 5. Run this script
# 6. Delete changes with `-LOCAL` references as needed
# Changes
ver="$(grep -F 'LIBSSH2_VERSION' ../include/libssh2.h | grep -a -E -o '[0-9]+\.[0-9]+\.[0-9]+([A-Z_-]+)?')"
echo "libssh2 ${ver}"
echo ''
echo 'This release includes the following enhancements and bugfixes:'
echo ''
{
find . -maxdepth 1 -name '*.patch' | sort -r | while read -r f; do
s="$(grep -F 'Subject: ' "${f}" | sed -E 's|Subject: \[PATCH [0-9]+/[0-9]+\] ||g')"
echo "${s}" | grep -q -a -F 'RELEASE-NOTES' && continue
s2="$(head -n 5 < "${f}" | tail -n 1)"
echo "${s2}" | grep -q -a -i -F 'MIME-Version' && s2=''
s="$(printf '%s' "${s}${s2}" | sed -E -e 's/ \(#[0-9]{2,5}\)//g' -e 's/ *\[(ci skip|skip ci)\]//g')"
commit="$(head -n 1 < "${f}" | grep -i -E -o '[0-9a-f]{40}' | cut -c -8)"
s="$(echo "${s}" | sed \
-e 's|^appveyor:|ci/appveyor:|' \
-e 's|^gha:|ci/GHA:|' \
)"
closes=''
others=''
while read -r rel; do
if [ -n "${rel}" ]; then
# https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
spec="$(grep -E -i -o \
"((Closes|Closed|Close) ${rel}|\(${rel}\))" "${f}")"
if [ -n "${spec}" ]; then
closes="${closes} ${rel}"
else
others="${others} ${rel}"
fi
fi
done <<< "$(sed -E 's!https://github.com/libssh2/libssh2/(issues|pull|discussions)/!#!g' < "${f}" \
| grep -E -i -w '#[0-9]{2,5}' | grep -v -E -i '(Tested via|Cherry-picked from)' | grep -E -i -w -o '#[0-9]{2,5}' | sort -r -u)"
foll=''
while read -r id; do
if [ -n "${id}" ]; then
if grep -q -E "^From ${id}" ./*.patch; then
>&2 echo "${f}: Follow-up to ${id} LOCAL"
else
foll="$(printf '%s follow: %.8s' "${foll}" "${id}")"
fi
fi
done <<< "$(grep -E -i -o 'Follow-up to [0-9a-f]{5,40}' "${f}" | grep -E -i -w -o '[0-9a-f]{5,40}' | sort -u)"
regr=''
while read -r id; do
if [ -n "${id}" ]; then
if grep -q -E "^From ${id}" ./*.patch; then
>&2 echo "${f}: Regression from ${id} LOCAL"
else
regr="$(printf '%s regr: %.8s' "${regr}" "${id}")"
fi
fi
done <<< "$(grep -E -i -o '(Regression from) [0-9a-f]{5,40}' "${f}" | grep -E -i -w -o '[0-9a-f]{5,40}' | sort -u)"
while read -r id; do
if [ -n "${id}" ]; then
if grep -q -E "^From ${id}" ./*.patch; then
>&2 echo "${f}: Reverts ${id} LOCAL"
else
regr="$(printf '%s revert: %.8s' "${regr}" "${id}")"
fi
fi
done <<< "$(grep -E -i -o '(Revert|Reverts) [0-9a-f]{5,40}' "${f}" | grep -E -i -w -o '[0-9a-f]{5,40}' | sort -u)"
echo "- ${s} (${commit}${closes}${others}${regr}${foll})"
done
} | sort -t ':' -k 1,1f -s
# Credits
echo ''
echo 'This release would not have looked like this without help, code, reports and'
echo 'advice from friends like these:'
echo ''
{
find . -name '*.patch' | sort -r | while read -r f; do
{
grep -E -i -o '(^From:|-by:|Credit:) [^<]+' "${f}"
} | cut -d ':' -f 2- | sed -E -e 's/^ +//g' -e 's/ +$//g' | sort | uniq -i
done
} | sort -f | uniq -c -i | sort -k 1nr -k 2f | sed -E 's/^ +//g' | cut -d ' ' -f 2- \
| tr '\n' ',' | tr ' ' '±' | sed 's/,$//g' | sed 's/,/, /g' \
| fold -w 78 -s | tr '±' ' ' | sed 's/ $//g' | sed 's/^/ /g'
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment