-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Generate release changelog based on commits #465
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# This script obtains the changelog to be introduced in the new release. | ||
|
||
set -eu | ||
|
||
function log_error() { | ||
echo "Error:" "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
function log_info() { | ||
echo -e "[+]" "$@" | ||
} | ||
|
||
GIT_BIN=$(which git) || log_error 'git is not installed. Please follow https://github.com/git-guides/install-git for instructions' | ||
|
||
# Generate the changelog between the provided tag and origin/master. | ||
function generate_changelog() { | ||
local tag="$1" | ||
# From the remote origin url, get a link to pull requests. | ||
remote_link=$($GIT_BIN config --get remote.origin.url | sed 's/\.git/\/pull\//g') || log_error 'Failed to get remote origin url' | ||
|
||
prs=$($GIT_BIN --no-pager log --pretty=format:"%s" "$tag"..origin/master) || log_error 'Failed to obtain commit list' | ||
|
||
log_info "Changelog\n" | ||
while IFS= read -r line; do | ||
# Obtain the pr number from each line. The regex should match, as provided by the previous grep. | ||
if [[ $line =~ "(#"([0-9]+)")"$ ]]; then | ||
pr_number="${BASH_REMATCH[1]}" | ||
else | ||
continue | ||
fi | ||
|
||
# Generate a valid PR link. | ||
pr_link="$remote_link$pr_number" | ||
# Generate the link as markdown. | ||
pr_md_link=" ([#$pr_number]($pr_link))" | ||
# Print the changelog line as `- commit-title pr-link`. | ||
echo "$line" | awk -v var="$pr_md_link" '{NF--; printf "- "; printf; print var}' | ||
done <<< "$prs" | ||
} | ||
|
||
# Get latest release tag. | ||
tag=$($GIT_BIN describe --match "v[0-9]*" --abbrev=0 origin/master) || log_error 'Failed to obtain the latest release tag' | ||
log_info "Latest release tag: $tag" | ||
# TODO: verify that the tag is part of an actual release | ||
$GIT_BIN verify-tag "$tag" > /dev/null 2>&1 || log_error 'Failed to verify tag' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like verify-tag is all about verifyingthe signature of the tag is valid, so perhaps the |
||
|
||
generate_changelog "$tag" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a usage example here (and/or print the help when args are missing?)