Skip to content

Commit

Permalink
Merge pull request #1288 from snyk/chore/auto-changelog
Browse files Browse the repository at this point in the history
Add custom changelog to goreleaser command
  • Loading branch information
sundowndev authored Dec 21, 2021
2 parents bc1ad7a + 76820f8 commit c26b619
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@

### driftctl
/.driftignore

CHANGELOG.md
5 changes: 5 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ if [ "$CI" != true ]; then
FLAGS+="--snapshot "
fi

if [ "$CI" == true ] && [ "$CMD" == "release" ]; then
./scripts/changelog.sh > CHANGELOG.md
FLAGS+="--release-notes CHANGELOG.md "
fi

CMD="goreleaser ${CMD} ${FLAGS}"

echo "+ Building using goreleaser"
Expand Down
38 changes: 15 additions & 23 deletions scripts/changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,26 @@ fi
# Keep IDs of merged pull requests
PRs=$(git log --pretty=oneline $BASE...$LATEST_TAG | grep 'Merge pull request #' | grep -oP '#[0-9]+' | sed 's/#//')

echo "Generating changelog for commits from $BASE to $LATEST_TAG..."

# Generating changelog for commits from $BASE to $LATEST_TAG
CHANGES=()
for pr in $PRs; do
str=$($GHCLI_BIN pr view $pr --repo $REPO -t '- {{ .title }} (#{{ .number }}) @{{ .author.login }} {{.labels}}' --json title,number,author,labels)
CHANGES+=("$str")
done

echo -e "\n## πŸš€ Enhancements\n"

for change in "${CHANGES[@]}"; do
if [[ $change =~ "kind/enhancement" ]]; then
echo $change | sed "s/\[map\[$PARTITION_COLUMN.*//"
fi
done

echo -e "\n## πŸ› Bug Fixes\n"

for change in "${CHANGES[@]}"; do
if [[ $change =~ "kind/bug" ]]; then
echo $change | sed "s/\[map\[$PARTITION_COLUMN.*//"
print_changes() {
local label=$1
local title=$2
if [[ "${CHANGES[@]}" =~ $label ]]; then
echo -e $title
for change in "${CHANGES[@]}"; do
if [[ $change =~ $label ]]; then
echo $change | sed "s/\[map\[$PARTITION_COLUMN.*//"
fi
done
fi
done

echo -e "\n## πŸ”¨ Maintenance\n"
}

for change in "${CHANGES[@]}"; do
if [[ $change =~ "kind/maintenance" ]]; then
echo $change | sed "s/\[map\[$PARTITION_COLUMN.*//"
fi
done
print_changes "kind/enhancement" "## πŸš€ Enhancements"
print_changes "kind/bug" "## πŸ› Bug Fixes"
print_changes "kind/maintenance" "## πŸ”¨ Maintenance"

0 comments on commit c26b619

Please sign in to comment.