Skip to content

Commit

Permalink
cleanup emptylines from the generated changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
barryib committed Mar 14, 2020
1 parent 84bc40d commit dcbaa0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ .Title }}
{{ range .Commits -}}
{{- if .Subject -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{- end -}}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Unreleased.Commits -}}
{{- if .Subject -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{- end -}}
{{ end }}
{{ end -}}
{{ end -}}
Expand All @@ -20,20 +24,24 @@
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ if .CommitGroups -}}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ .Title }}
{{ range .Commits -}}
{{- if .Subject -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{- end -}}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Commits -}}
{{- if .Subject -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{- end -}}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SEMTAG=tools/semtag

CHANGELOG_FILE=CHANGELOG.md
OLD_CHANGELOG_LAST_TAG=v10.0.0
OLD_CHANGELOG_LAST_TAG_REGEX='\[$(OLD_CHANGELOG_LAST_TAG)\]|name="$(OLD_CHANGELOG_LAST_TAG)"'
TAG_QUERY=$(OLD_CHANGELOG_LAST_TAG)..

BEGIN_PLACEHOLDER:=<!-- BEGIN GIT-CHGLOG -->
Expand All @@ -17,13 +18,13 @@ SED:=$(shell which gsed)
scope ?= "minor"

changelog-unrelease:
git-chglog $(TAG_QUERY) | grep -v $(OLD_CHANGELOG_LAST_TAG) > $(TMPFILE)
git-chglog $(TAG_QUERY) | grep -vE $(OLD_CHANGELOG_LAST_TAG_REGEX) | $(SED) 'N;s/\n$$//g;P;D' > $(TMPFILE)
$(SED) '/$(BEGIN_PLACEHOLDER)/,/$(END_PLACEHOLDER)/{//!d}' $(CHANGELOG_FILE) > $(TMPFILE_CHANGELOG)
$(SED) -i '/$(BEGIN_PLACEHOLDER)/r $(TMPFILE)' $(TMPFILE_CHANGELOG)
mv $(TMPFILE_CHANGELOG) $(CHANGELOG_FILE) && rm -f $(TMPFILE)

changelog:
git-chglog --next-tag `$(SEMTAG) final -s $(scope) -o -f` $(TAG_QUERY) | grep -v $(OLD_CHANGELOG_LAST_TAG) > $(TMPFILE)
git-chglog --next-tag `$(SEMTAG) final -s $(scope) -o -f` $(TAG_QUERY) | grep -vE $(OLD_CHANGELOG_LAST_TAG_REGEX) | $(SED) 'N;s/\n$$//g;P;D' > $(TMPFILE)
$(SED) '/$(BEGIN_PLACEHOLDER)/,/$(END_PLACEHOLDER)/{//!d}' $(CHANGELOG_FILE) > $(TMPFILE_CHANGELOG)
$(SED) -i '/$(BEGIN_PLACEHOLDER)/r $(TMPFILE)' $(TMPFILE_CHANGELOG)
mv $(TMPFILE_CHANGELOG) $(CHANGELOG_FILE) && rm -f $(TMPFILE)
Expand Down

0 comments on commit dcbaa0c

Please sign in to comment.