From 8c71ffc6e8c0a2470cd0d19d8c8f744ea65107b5 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Wed, 27 Oct 2021 16:58:50 +0200 Subject: [PATCH 1/6] New version of source_changelog Mostly copied from https://github.com/cli/cli/blob/4e219a9c8f4fb2b38c2b9ff001a39729b58d61f8/script/changelog but adapted to work with local repositories and Ignition changelogs --- source_changelog.bash | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/source_changelog.bash b/source_changelog.bash index 1f5c4a801..0816c25f3 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -1,24 +1,38 @@ #!/bin/bash +set -e -PREV_TAG=$1 +current_origin_remote=$(git config --get remote.origin.url) -git fetch --tags +if [[ -z ${current_origin_remote} ]]; then + echo "Script is unable to detect current remote.origin.url in this directory" + exit 1 +fi -REPO=$(basename `git rev-parse --show-toplevel`) -REPO_FULL="${REPO/ign-/ignition-}" -MAJOR=${PREV_TAG%.*.*} -BRANCH=${REPO/sdformat/sdf}${MAJOR} +if [[ -f "Changelog.md" ]]; then + software_name=$(head -1 Changelog*) + printf "%s (%s)\n\n" "${software_name}" "$(date +%Y-%m-%d)" +fi -COMMITS=$(git log ${BRANCH}...${REPO_FULL}${MAJOR}_${PREV_TAG} --pretty=format:"%h") +current_tag=$(git symbolic-ref HEAD) +start_ref="HEAD" -for COMMIT in $COMMITS -do - TITLE_FULL=$(git log --format="%s" -n 1 $COMMIT) - TITLE=${TITLE_FULL% (\#*)} - PR=${TITLE_FULL#*\#} - PR=${PR%)} - - echo "1. $TITLE" - echo " * [Pull request #$PR](https://github.com/ignitionrobotics/$REPO/pull/$PR)" - echo "" +# Find the previous release on the same branch, skipping prereleases if the +# current tag is a full release +previous_tag="" +while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; do + previous_tag="$(git describe --tags "$start_ref"^ --abbrev=0)" + start_ref="$previous_tag" done + +git log "$previous_tag".. --reverse --first-parent --oneline | \ + while read -r sha title; do + pr_num="$(grep -o '#[[:digit:]]\+' <<<"$title")" + pr_num="${pr_num:1}" + if [[ $title == "Merge pull request #"* ]]; then + pr_desc="$(git show -s --format=%b "$sha" | sed -n '1,/^$/p' | tr $'\n' ' ')" + else + pr_desc=${title/\ (#[[:digit:]]*)} + fi + printf "1. %s\n" "$pr_desc" + printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num" + done From c60d796cb15c61e042a34cbce9c403e54302a717 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Wed, 27 Oct 2021 17:18:40 +0200 Subject: [PATCH 2/6] Make the script to be able to display external contributions --- source_changelog.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source_changelog.bash b/source_changelog.bash index 0816c25f3..3e50eed86 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -4,13 +4,13 @@ set -e current_origin_remote=$(git config --get remote.origin.url) if [[ -z ${current_origin_remote} ]]; then - echo "Script is unable to detect current remote.origin.url in this directory" - exit 1 + echo "Script is unable to detect current remote.origin.url in this directory" + exit 1 fi if [[ -f "Changelog.md" ]]; then - software_name=$(head -1 Changelog*) - printf "%s (%s)\n\n" "${software_name}" "$(date +%Y-%m-%d)" + software_name=$(head -1 Changelog*) + printf "%s (%s)\n\n" "${software_name}" "$(date +%Y-%m-%d)" fi current_tag=$(git symbolic-ref HEAD) @@ -24,8 +24,8 @@ while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; start_ref="$previous_tag" done -git log "$previous_tag".. --reverse --first-parent --oneline | \ - while read -r sha title; do +git log "$previous_tag".. --reverse --first-parent --pretty=format:"%h|%s|%ae|%an" | \ + while IFS='|' read -r sha title author_email author || [[ -n ${sha} ]]; do pr_num="$(grep -o '#[[:digit:]]\+' <<<"$title")" pr_num="${pr_num:1}" if [[ $title == "Merge pull request #"* ]]; then @@ -35,4 +35,8 @@ git log "$previous_tag".. --reverse --first-parent --oneline | \ fi printf "1. %s\n" "$pr_desc" printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num" + if [[ "${author_email/@openrobotics.org}" != "${author_email}" ]]; then + printf " * A contribution from: %s <%s>\n" "$author" "$author_email" + fi + echo done From b78b9a9eb1a1239f0c1c905df8a3aec01a696c93 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Wed, 27 Oct 2021 17:22:05 +0200 Subject: [PATCH 3/6] Do not display openrobotics but external contributors Signed-off-by: Jose Luis Rivero --- source_changelog.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source_changelog.bash b/source_changelog.bash index 3e50eed86..d9ef49931 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -35,7 +35,7 @@ git log "$previous_tag".. --reverse --first-parent --pretty=format:"%h|%s|%ae|%a fi printf "1. %s\n" "$pr_desc" printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num" - if [[ "${author_email/@openrobotics.org}" != "${author_email}" ]]; then + if [[ "${author_email/@openrobotics.org}" == "${author_email}" ]]; then printf " * A contribution from: %s <%s>\n" "$author" "$author_email" fi echo From 0d7055f19c5e6db24bdc265ea89f8c0cdc9165ba Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Wed, 27 Oct 2021 20:21:58 +0200 Subject: [PATCH 4/6] Handle git@ style of remotes --- source_changelog.bash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source_changelog.bash b/source_changelog.bash index d9ef49931..b4cdf2a81 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -3,6 +3,12 @@ set -e current_origin_remote=$(git config --get remote.origin.url) +# need tweaks if using ssh +if [[ "${current_origin_remote/git@}" != "${current_origin_remote}" ]]; then + current_origin_remote=${current_origin_remote/\.git} + current_origin_remote=${current_origin_remote/git@github.com:/https://github.com/} +fi + if [[ -z ${current_origin_remote} ]]; then echo "Script is unable to detect current remote.origin.url in this directory" exit 1 From aa72488d564c53177e9b1652ca7468dd7f7b2984 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Wed, 27 Oct 2021 20:22:16 +0200 Subject: [PATCH 5/6] Exclude @osrfoundation.org emails and @noreply.github.com --- source_changelog.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source_changelog.bash b/source_changelog.bash index b4cdf2a81..aafca018d 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -41,7 +41,9 @@ git log "$previous_tag".. --reverse --first-parent --pretty=format:"%h|%s|%ae|%a fi printf "1. %s\n" "$pr_desc" printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num" - if [[ "${author_email/@openrobotics.org}" == "${author_email}" ]]; then + if [[ "${author_email/@openrobotics.org}" == "${author_email}" ]] && \ + [[ "${author_email/@osrfoundation.org}" == "${author_email}" ]] && \ + [[ "${author_email/@users.noreply.github.com}" == "${author_email}" ]]; then printf " * A contribution from: %s <%s>\n" "$author" "$author_email" fi echo From d577f2a9089cf1b97f03b3fe1dfb985c35cf08bd Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Thu, 28 Apr 2022 19:56:49 +0200 Subject: [PATCH 6/6] Modify the script to use current git log approach --- source_changelog.bash | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/source_changelog.bash b/source_changelog.bash index aafca018d..976580f11 100644 --- a/source_changelog.bash +++ b/source_changelog.bash @@ -14,6 +14,11 @@ if [[ -z ${current_origin_remote} ]]; then exit 1 fi +if [[ $(git branch --show-current) == 'main' ]]; then + echo "Error: main branch should not be used for releasing" + exit 1 +fi + if [[ -f "Changelog.md" ]]; then software_name=$(head -1 Changelog*) printf "%s (%s)\n\n" "${software_name}" "$(date +%Y-%m-%d)" @@ -30,15 +35,17 @@ while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; start_ref="$previous_tag" done -git log "$previous_tag".. --reverse --first-parent --pretty=format:"%h|%s|%ae|%an" | \ +REPO=$(basename `git rev-parse --show-toplevel`) +REPO_FULL="${REPO/ign-/ignition-}" +VERSION=${previous_tag/${REPO_FULL}*_} +MAJOR=${VERSION%.*.*} +BRANCH=${REPO/sdformat/sdf}${MAJOR} + +git log "${BRANCH}"..."${previous_tag}" --pretty=format:"%h|%s|%ae|%an" | \ while IFS='|' read -r sha title author_email author || [[ -n ${sha} ]]; do pr_num="$(grep -o '#[[:digit:]]\+' <<<"$title")" pr_num="${pr_num:1}" - if [[ $title == "Merge pull request #"* ]]; then - pr_desc="$(git show -s --format=%b "$sha" | sed -n '1,/^$/p' | tr $'\n' ' ')" - else - pr_desc=${title/\ (#[[:digit:]]*)} - fi + pr_desc=${title/\ (#[[:digit:]]*)} printf "1. %s\n" "$pr_desc" printf " * [Pull request #%s](%s/pull/%s)\n" "$pr_num" "$current_origin_remote" "$pr_num" if [[ "${author_email/@openrobotics.org}" == "${author_email}" ]] && \