From 5d3ffc9a271206683dc8d9fc081340e13334dda2 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 20 Dec 2021 17:22:35 +0100 Subject: [PATCH] .github: Reflect more kernel versions in the changelog It happens that kernel update PRs are created faster than we merge them. In such case we create version gaps in the changelog. Remedy that by adding links to all the released kernel versions between the current one and the just released one. --- .../.github/workflows/common.sh | 23 ++++++++- .../.github/workflows/kernel-apply-patch.sh | 47 ++++++++++++++----- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh b/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh index 86b54cb327..d4e8e2c9c2 100644 --- a/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh +++ b/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh @@ -71,15 +71,36 @@ function regenerate_manifest() { popd || exit } +function join_by() { + local delimiter="${1-}" + local first="${2-}" + if shift 2; then + printf '%s' "${first}" "${@/#/${delimiter}}"; + fi +} + function generate_update_changelog() { local NAME="${1}" local VERSION="${2}" local URL="${3}" local UPDATE_NAME="${4}" + shift 4 + local file="changelog/updates/$(date '+%Y-%m-%d')-${UPDATE_NAME}-update.md" + local -a old_links pushd "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" >/dev/null || exit if [[ -d changelog/updates ]]; then - echo "- ${NAME} ([${VERSION}](${URL}))" > "changelog/updates/$(date '+%Y-%m-%d')-${UPDATE_NAME}-update.md" + printf '%s %s ([%s](%s)' '-' "${NAME}" "${VERSION}" "${URL}" > "${file}" + if [[ $# -gt 0 ]]; then + echo -n ' (includes ' >> "${file}" + while [[ $# -gt 1 ]]; do + old_links+=( "[${1}](${2})" ) + shift 2 + done + printf '%s' "$(join_by ', ' "${old_links[@]}")" >> "${file}" + echo -n ')' >> "${file}" + fi + echo ')' >> "${file}" fi popd >/dev/null || exit } diff --git a/sdk_container/src/third_party/coreos-overlay/.github/workflows/kernel-apply-patch.sh b/sdk_container/src/third_party/coreos-overlay/.github/workflows/kernel-apply-patch.sh index e093acae88..9846ccc5f8 100755 --- a/sdk_container/src/third_party/coreos-overlay/.github/workflows/kernel-apply-patch.sh +++ b/sdk_container/src/third_party/coreos-overlay/.github/workflows/kernel-apply-patch.sh @@ -36,19 +36,42 @@ done popd >/dev/null || exit -if ! curl -sfA 'Chrome' -L 'http://www.google.com/search?hl=en&q=site%3Alwn.net+linux+'"${VERSION_NEW}" -o search.html; then - echo 'curl failed' - touch search.html -fi -# can't use grep -m 1 -o … to replace head -n 1, because all the links -# seem to happen in one line, so grep prints all the links in the line -URL=$({ grep -o 'https://lwn.net/Articles/[0-9]\+' search.html || true ; } | head -n 1) -if [[ ! "${URL}" ]]; then - URL="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tag/?h=v${VERSION_NEW}" -fi -rm search.html +function get_lwn_link() { + local LINUX_VERSION="${1}" + local url -generate_update_changelog 'Linux' "${VERSION_NEW}" "${URL}" 'linux' + if ! curl -sfA 'Chrome' -L 'http://www.google.com/search?hl=en&q=site%3Alwn.net+linux+'"${LINUX_VERSION}" -o search.html >&2; then + echo 'curl failed' >&2 + touch search.html + fi + # can't use grep -m 1 -o … to replace head -n 1, because all the links + # seem to happen in one line, so grep prints all the links in the line + url=$({ grep -o 'https://lwn.net/Articles/[0-9]\+' search.html || true ; } | head -n 1) + if [[ ! "${url}" ]]; then + echo 'no valid links found in the search result' >&2 + url="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tag/?h=v${LINUX_VERSION}" + fi + rm search.html + echo "${url}" +} + +PATCH_VERSION_OLD=${VERSION_OLD##*.} +PATCH_VERSION_NEW=${VERSION_NEW##*.} + +PATCH_NUM=$((PATCH_VERSION_NEW - 1)) + +OLD_VERSIONS_AND_URLS=() + +while [[ ${PATCH_NUM} -gt ${PATCH_VERSION_OLD} ]]; do + TMP_VERSION="${VERSION_SHORT}.${PATCH_NUM}" + TMP_URL=$(get_lwn_link "${TMP_VERSION}") + OLD_VERSIONS_AND_URLS+=( "${TMP_VERSION}" "${TMP_URL}" ) + : $((PATCH_NUM--)) +done + +URL=$(get_lwn_link "${VERSION_NEW}") + +generate_update_changelog 'Linux' "${VERSION_NEW}" "${URL}" 'linux' "${OLD_VERSIONS_AND_URLS[@]}" generate_patches sys-kernel coreos-sources Kernel