From 9432983a57d4c55f4d8878b10917eb3ff0b475d9 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Sun, 18 Dec 2022 15:57:01 +0100
Subject: [PATCH] chore: update makefiles

---
 .chglog/CHANGELOG.tpl.md              | 27 +++++++++++++
 .chglog/config.yml                    | 58 +++++++++++++++++++++++++++
 makefiles/changelog.mk                |  4 +-
 makefiles/go.mk                       | 11 +++++
 makefiles/target-go-fetch-licenses.mk | 12 ++++--
 5 files changed, 108 insertions(+), 4 deletions(-)
 create mode 100644 .chglog/CHANGELOG.tpl.md
 create mode 100644 .chglog/config.yml

diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md
new file mode 100644
index 0000000..e0ffe42
--- /dev/null
+++ b/.chglog/CHANGELOG.tpl.md
@@ -0,0 +1,27 @@
+{{ range .Versions }}
+<a name="{{ .Tag.Name }}"></a>
+## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
+{{ range .CommitGroups -}}
+### {{ .Title }}
+{{ range .Commits -}}
+- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
+{{ end }}
+{{ end -}}
+
+{{- if .NoteGroups -}}
+{{ range .NoteGroups -}}
+### {{ .Title }}
+{{ range .Notes }}
+{{ .Body }}
+{{ end }}
+{{ end -}}
+{{ end -}}
+{{ end -}}
+
+{{- if .Versions }}
+{{ range .Versions -}}
+{{ if .Tag.Previous -}}
+[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
+{{ end -}}
+{{ end -}}
+{{ end -}}
diff --git a/.chglog/config.yml b/.chglog/config.yml
new file mode 100644
index 0000000..ad68c96
--- /dev/null
+++ b/.chglog/config.yml
@@ -0,0 +1,58 @@
+style: gitlab
+template: CHANGELOG.tpl.md
+info:
+  title: CHANGELOG
+  repository_url: https://gitlab.schukai.com/oss/libraries/go/markup/html
+options:
+  commits:
+    filters:
+      Type:
+        - feat
+        - fix
+        - doc
+        - refactor
+        - perf
+        - test
+        - chore
+        ## deprecated types and typos  
+        - docs
+        - documentation
+        - feat
+        - added
+        - add
+        - bugfix
+        - revert
+        - update
+        - updates
+        - change
+        - changed
+  commit_groups:
+    title_maps:
+      feat: Add Features
+      fix: Bug Fixes
+      doc: Documentation
+      refactor: Code Refactoring
+      perf: Performance Improvements
+      test: Tests
+      ## Chore is used for all other changes that don't fit in the other categories
+      chore: Changes
+      ## deprecated types and typos  
+      docs: Documentation
+      documentation: Documentation
+      added: Add Features
+      add: Add Features
+      bugfix: Bug Fixes
+      revert: Reverts
+      update: Changes
+      updates: Changes
+      change: Changes
+      changed: Changes
+  header:
+    pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
+    pattern_maps:
+      - Type
+      - Scope
+      - Subject
+  notes:
+    keywords:
+      - BREAKING CHANGE
diff --git a/makefiles/changelog.mk b/makefiles/changelog.mk
index f1d8fed..c3ae831 100644
--- a/makefiles/changelog.mk
+++ b/makefiles/changelog.mk
@@ -17,8 +17,10 @@ endif
 
 ifeq ($(GIT_CHGLOG_BIN),)
   $(shell $(GO) install github.com/git-chglog/git-chglog/cmd/git-chglog@latest)
+  GIT_CHGLOG_BIN := $(shell command -v git-chglog 2> /dev/null)
 endif     
 
+
 ifneq ($(shell test -d $(GIT_CHGLOG_CONFIG_DIR) && echo -n yes),yes)
     $(shell mkdir -p $(GIT_CHGLOG_CONFIG_DIR))
 endif
@@ -135,4 +137,4 @@ $(GIT_CHGLOG_CONFIG_DIR)/CHANGELOG.tpl.md:
 
 ## location of CHANGELOG.md file
 CHANGELOG_FILE ?= $(PROJECT_ROOT)CHANGELOG.md
-EXECUTABLES = $(EXECUTABLES:-) $(GIT_CHGLOG_BIN)
\ No newline at end of file
+EXECUTABLES = $(EXECUTABLES:-) $(GIT_CHGLOG_BIN)
diff --git a/makefiles/go.mk b/makefiles/go.mk
index 00ff947..6cb58e9 100644
--- a/makefiles/go.mk
+++ b/makefiles/go.mk
@@ -14,3 +14,14 @@ EXECUTABLES = $(EXECUTABLES:-) $(GO);
 ifeq ($(shell command -v $(GO) 2> /dev/null),)
   $(error "go is not installed. Please install go <https://go.dev/doc/install>")
 endif
+
+GOPATH=$(shell go env GOPATH)
+
+ifeq ($(GOPATH),)
+    DIRS := bin pkg src
+    GOPATH=$(DEPLOYMENT_PATH)/go/
+    $(shell mkdir -p $(GOPATH))
+	$(shell $(foreach entry,$(DIRS),mkdir -p "$(GOPATH)$(entry)";))
+    export PATH=$(PATH):$(GOPATH)/bin
+endif
+
diff --git a/makefiles/target-go-fetch-licenses.mk b/makefiles/target-go-fetch-licenses.mk
index 242f3d3..65fe5cd 100644
--- a/makefiles/target-go-fetch-licenses.mk
+++ b/makefiles/target-go-fetch-licenses.mk
@@ -11,16 +11,22 @@ ifeq ($(GO),)
 endif
 
 GO_MOD_FILE := $(SOURCE_PATH)go.mod
+GO_LICENSES_BIN := $(shell command -v go-licenses)
+
+
+ifeq ($(GO_LICENSES_BIN),)
+  $(shell $(GO) install github.com/google/go-licenses@latest)
+  GO_LICENSES_BIN := $(shell command -v go-licenses 2> /dev/null)
+  EXECUTABLES = $(EXECUTABLES:-) go-licenses;    
+endif   
 
 ifeq ($(shell test -e $(GO_MOD_FILE) && echo -n yes),yes)
   GO_CURRENT_MODULE := $(shell cat $(GO_MOD_FILE) | head -n1 | cut -d" " -f2)
-  # go install github.com/google/go-licenses@latest
-  EXECUTABLES = $(EXECUTABLES:-) go-licenses;    
 endif
 
 .PHONY: go-fetch-licenses
 ## Fetch licenses for all modules
-go-fetch-licenses:
+go-fetch-licenses: 
 ifeq ($(GO_CURRENT_MODULE),)
 	$(QUIET) $(ECHOERRORMARKER) "no go.mod file found, skipping fetching licenses"
 else
-- 
GitLab