Skip to content

Commit

Permalink
tools/generate_release_notes: account for edge cases (#41)
Browse files Browse the repository at this point in the history
account for the cases where there are no upstream changes, or there are
no datadog changes.

also make the commit detection more robust.
  • Loading branch information
Gandem authored Jul 10, 2024
1 parent c5f16b5 commit f1cd0b1
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions tools/generate_release_notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fi
# None
# Outputs:
# A string with the format "upstream_commit1...upstream_commit2" that can be used as a reference to the upstream commits between the two tags
# If there are no changes in the upstream commits between the two tags, an empty string is returned
#######################################
function get_upstream_diff() {
local first_datadog_commit_name="Add options to control reporter interval / sampling frequency"
Expand All @@ -64,7 +65,12 @@ function get_upstream_diff() {
local new_upstream
new_upstream=$(git show -s --pretty=%P "${new_first_datadog_commit}")

echo "$previous_upstream...$new_upstream"
if [ "${previous_upstream}" == "${new_upstream}" ]; then
echo ""
return
fi

echo "${previous_upstream}...${new_upstream}"
}

#######################################
Expand All @@ -76,6 +82,7 @@ function get_upstream_diff() {
# None
# Outputs:
# A string with the format "commit1...commit2" that can be used as a reference to the upstream commits between the two tags
# If there are no changes in the upstream commits between the two tags, an empty string is returned
#######################################
function get_datadog_diff() {
local previous_tag_last_commit
Expand All @@ -84,12 +91,20 @@ function get_datadog_diff() {
local previous_tag_last_commit_name
previous_tag_last_commit_name=$(git log -1 "${previous_tag_last_commit}" --pretty=%B | head -n+1)

# Strip out the PR number / jira ticket from the commit message since they might confuse the grep
previous_tag_last_commit_name=$(echo "${previous_tag_last_commit_name}" | sed -E 's/\(#[0-9]+\)//g' | sed -E 's/\[[a-zA-Z]+-[0-9]+\]//g' | sed -E 's/^\s+|\s+$//g')

local new_tag_first_commit
new_tag_first_commit=$(git log "${NEW_TAG}" --grep="${previous_tag_last_commit_name}" --pretty=format:"%H" | tail -n 1)

local new_tag_commit
new_tag_commit=$(git rev-list -n 1 "${NEW_TAG}")

if [ "${new_tag_first_commit}" == "${new_tag_commit}" ]; then
echo ""
return
fi

echo "${new_tag_first_commit}...${new_tag_commit}"
}

Expand All @@ -112,7 +127,9 @@ function generate_release_notes() {

echo "# Major updates"
echo -e "\n"
echo "* Updated upstream for otel-profiling-agent ${upstream_diff}"
if [ -n "${upstream_diff}" ]; then
echo "* Updated upstream for otel-profiling-agent ${upstream_diff}"
fi
echo "* <...> fill in the major updates here <...>"
echo -e "\n"

Expand All @@ -121,15 +138,24 @@ function generate_release_notes() {
echo "<summary>Expand to see the full changelog</summary>"
echo -e "\n"
echo "### Upstream changes:"
# get rid of PR number and just show the commit hash and message
git log --pretty=format:"* %h %s" "${upstream_diff}" | cat | sed -E 's/\(#[0-9]+\)//g'
echo -e "\n"
echo "**Upstream Changelog**: [link](https://github.com/DataDog/otel-profiling-agent/compare/${upstream_diff})"
if [ -n "${upstream_diff}" ]; then
# get rid of PR number and just show the commit hash and message
git log --pretty=format:"* %h %s" "${upstream_diff}" | cat | sed -E 's/\(#[0-9]+\)//g'
echo -e "\n"
echo "**Upstream Changelog**: [link](https://github.com/DataDog/otel-profiling-agent/compare/${upstream_diff})"
else
echo "No changes"
fi
echo -e "\n"

echo "### Datadog changes:"
git log --pretty=format:"* %h %s" "${datadog_diff}" | cat
echo -e "\n"
echo "**Datadog Changelog**: [link](https://github.com/DataDog/otel-profiling-agent/compare/${datadog_diff})"
if [ -n "${datadog_diff}" ]; then
git log --pretty=format:"* %h %s" "${datadog_diff}" | cat
echo -e "\n"
echo "**Datadog Changelog**: [link](https://github.com/DataDog/otel-profiling-agent/compare/${datadog_diff})"
else
echo "No changes"
fi
echo "</details>"
}

Expand Down

0 comments on commit f1cd0b1

Please sign in to comment.