Skip to content

ci: Add authors to release notes #5834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions scripts/release/check_commit_metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ range="$from_ref..$to_ref"
dependencies gh

COMMIT_METADATA_BREAKING=0
declare -A COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
declare -A COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS

# This environment variable can be set to 1 to ignore missing commit metadata,
# useful for dry-runs.
Expand Down Expand Up @@ -66,22 +66,26 @@ main() {
#
# Example output:
#
# 27386d49d08455b6f8fbf2c18f38244d03fda892 label:security
# d9f2aaf3b430d8b6f3d5f24032ed6357adaab1f1
# fd54512858c906e66f04b0744d8715c2e0de97e6 label:stale label:enhancement
# 27386d49d08455b6f8fbf2c18f38244d03fda892 author:hello labels:label:security
# d9f2aaf3b430d8b6f3d5f24032ed6357adaab1f1 author:world
# fd54512858c906e66f04b0744d8715c2e0de97e6 author:bye labels:label:stale label:enhancement
from_commit_date=2023-01-18
mapfile -t pr_labels_raw < <(
gh pr list \
--base main \
--state merged \
--limit 10000 \
--search "merged:>=$from_commit_date" \
--json mergeCommit,labels \
--jq '.[] | .mergeCommit.oid + " " + (["label:" + .labels[].name] | join(" "))'
--json mergeCommit,labels,author \
--jq '.[] | "\( .mergeCommit.oid ) author:\( .author.login ) labels:\(["label:\( .labels[].name )"] | join(" "))"'
)
declare -A labels
declare -A authors labels
for entry in "${pr_labels_raw[@]}"; do
commit_sha_long=${entry%% *}
all_labels=${entry#* }
commit_author=${entry#* author:}
commit_author=${commit_author%% *}
authors[$commit_sha_long]=$commit_author
all_labels=${entry#* labels:}
labels[$commit_sha_long]=$all_labels
done

Expand All @@ -92,7 +96,7 @@ main() {
commit_prefix=${parts[2]}

# Safety-check, guarantee all commits had their metadata fetched.
if [[ ! -v labels[$commit_sha_long] ]]; then
if [[ ! -v authors[$commit_sha_long] ]] || [[ ! -v labels[$commit_sha_long] ]]; then
if [[ $ignore_missing_metadata != 1 ]]; then
error "Metadata missing for commit $commit_sha_short"
else
Expand All @@ -104,6 +108,9 @@ main() {
title=${parts[*]:2}
title=${title%$'\n'}
COMMIT_METADATA_TITLE[$commit_sha_short]=$title
if [[ -v authors[$commit_sha_long] ]]; then
COMMIT_METADATA_AUTHORS[$commit_sha_short]="@${authors[$commit_sha_long]}"
fi

# First, check the title for breaking changes. This avoids doing a
# GH API request if there's a match.
Expand Down Expand Up @@ -132,12 +139,12 @@ main() {
}

declare_print_commit_metadata() {
declare -p COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
declare -p COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
}

export_commit_metadata() {
_COMMIT_METADATA_CACHE="${range}:$(declare_print_commit_metadata)"
export _COMMIT_METADATA_CACHE COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY
export _COMMIT_METADATA_CACHE COMMIT_METADATA_BREAKING COMMIT_METADATA_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
}

# _COMMIT_METADATA_CACHE is used to cache the results of this script in
Expand Down
7 changes: 5 additions & 2 deletions scripts/release/generate_release_notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ for cat in "${!section_titles[@]}"; do
done

for commit in "${commits[@]}"; do
line="- $commit ${COMMIT_METADATA_TITLE[$commit]}\n"
line="- $commit ${COMMIT_METADATA_TITLE[$commit]}"
if [[ -v COMMIT_METADATA_AUTHORS[$commit] ]]; then
line+=" (${COMMIT_METADATA_AUTHORS[$commit]})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the markdown link make them show up as a contributor in the release (this is a newish GH feature)? If not we need to use @ instead I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, but I can def. revert back to @

fi

# Default to "other" category.
cat=other
Expand All @@ -122,7 +125,7 @@ for commit in "${commits[@]}"; do
break
fi
done
declare "$cat"_changelog+="$line"
declare "$cat"_changelog+="$line"$'\n'
done

changelog="$(
Expand Down