From 1b7ac9958150f43f251e6cad4fffa493c22c4c68 Mon Sep 17 00:00:00 2001
From: Bryant Biggs <bryantbiggs@gmail.com>
Date: Sun, 7 Nov 2021 14:27:30 -0500
Subject: [PATCH] fix: update CI/CD process to enable auto-release workflow
 (#116)

---
 .chglog/CHANGELOG.tpl.md        | 111 --------------------------------
 .chglog/config.yml              |  10 ---
 .github/workflows/release.yml   |  31 +++++++++
 .pre-commit-config.yaml         |   1 +
 .releaserc.json                 |  28 ++++++++
 CHANGELOG.md                    |   9 ---
 Makefile                        |  12 ----
 examples/s3-replication/main.tf |   2 +-
 8 files changed, 61 insertions(+), 143 deletions(-)
 delete mode 100644 .chglog/CHANGELOG.tpl.md
 delete mode 100644 .chglog/config.yml
 create mode 100644 .github/workflows/release.yml
 create mode 100644 .releaserc.json
 delete mode 100644 Makefile

diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md
deleted file mode 100644
index 687d7023..00000000
--- a/.chglog/CHANGELOG.tpl.md
+++ /dev/null
@@ -1,111 +0,0 @@
-# Change Log
-
-All notable changes to this project will be documented in this file.
-
-{{ if .Versions -}}
-<a name="unreleased"></a>
-## [Unreleased]
-{{ if .Unreleased.CommitGroups -}}
-{{ range .Unreleased.CommitGroups -}}
-### {{ .Title }}
-{{ range .Commits -}}
-{{/* SKIPPING RULES - START */ -}}
-{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
-{{- if not (contains .Subject "[ci skip]") -}}
-{{- if not (contains .Subject "[skip ci]") -}}
-{{- if not (hasPrefix .Subject "Merge pull request ") -}}
-{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
-{{- /* SKIPPING RULES - END */ -}}
-- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
-{{/* SKIPPING RULES - START */ -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{/* SKIPPING RULES - END */ -}}
-{{ end }}
-{{ end -}}
-{{ else }}
-{{ range .Unreleased.Commits -}}
-{{/* SKIPPING RULES - START */ -}}
-{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
-{{- if not (contains .Subject "[ci skip]") -}}
-{{- if not (contains .Subject "[skip ci]") -}}
-{{- if not (hasPrefix .Subject "Merge pull request ") -}}
-{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
-{{- /* SKIPPING RULES - END */ -}}
-- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
-{{/* SKIPPING RULES - START */ -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{/* SKIPPING RULES - END */ -}}
-{{ end }}
-{{ end -}}
-{{ end -}}
-
-{{ range .Versions }}
-<a name="{{ .Tag.Name }}"></a>
-## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
-{{ if .CommitGroups -}}
-{{ range .CommitGroups -}}
-### {{ .Title }}
-{{ range .Commits -}}
-{{/* SKIPPING RULES - START */ -}}
-{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
-{{- if not (contains .Subject "[ci skip]") -}}
-{{- if not (contains .Subject "[skip ci]") -}}
-{{- if not (hasPrefix .Subject "Merge pull request ") -}}
-{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
-{{- /* SKIPPING RULES - END */ -}}
-- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
-{{/* SKIPPING RULES - START */ -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{/* SKIPPING RULES - END */ -}}
-{{ end }}
-{{ end -}}
-{{ else }}
-{{ range .Commits -}}
-{{/* SKIPPING RULES - START */ -}}
-{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
-{{- if not (contains .Subject "[ci skip]") -}}
-{{- if not (contains .Subject "[skip ci]") -}}
-{{- if not (hasPrefix .Subject "Merge pull request ") -}}
-{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
-{{- /* SKIPPING RULES - END */ -}}
-- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
-{{/* SKIPPING RULES - START */ -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-{{/* SKIPPING RULES - END */ -}}
-{{ end }}
-{{ end -}}
-
-{{- if .NoteGroups -}}
-{{ range .NoteGroups -}}
-### {{ .Title }}
-{{ range .Notes }}
-{{ .Body }}
-{{ end }}
-{{ end -}}
-{{ end -}}
-{{ end -}}
-
-{{- if .Versions }}
-[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
-{{ 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
deleted file mode 100644
index 5ebb8f3b..00000000
--- a/.chglog/config.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-style: github
-template: CHANGELOG.tpl.md
-info:
-  title: CHANGELOG
-  repository_url: https://github.com/terraform-aws-modules/terraform-aws-s3-bucket
-options:
-  header:
-    pattern: "^(.*)$"
-    pattern_maps:
-      - Subject
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 00000000..75567201
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,31 @@
+name: Release
+
+on:
+  push:
+    branches:
+      - main
+      - master
+    paths:
+      - '**/*.py'
+      - '**/*.tf'
+
+jobs:
+  release:
+    name: Release
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          persist-credentials: false
+          fetch-depth: 0
+
+      - name: Release
+        uses: cycjimmy/semantic-release-action@v2
+        with:
+          semantic_version: 18.0.0
+          extra_plugins: |
+            @semantic-release/changelog@6.0.0
+            @semantic-release/git@10.0.0
+        env:
+          GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 896c01ef..65c0f394 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -43,3 +43,4 @@ repos:
     rev: v4.0.1
     hooks:
       - id: check-merge-conflict
+      - id: end-of-file-fixer
diff --git a/.releaserc.json b/.releaserc.json
new file mode 100644
index 00000000..ca52a586
--- /dev/null
+++ b/.releaserc.json
@@ -0,0 +1,28 @@
+{
+  "branches": [
+    "main",
+    "master"
+  ],
+  "ci": false,
+  "plugins": [
+    "@semantic-release/commit-analyzer",
+    "@semantic-release/release-notes-generator",
+    "@semantic-release/github",
+    [
+      "@semantic-release/changelog",
+      {
+        "changelogFile": "CHANGELOG.md",
+        "changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file"
+      }
+    ],
+    [
+      "@semantic-release/git",
+      {
+        "assets": [
+          "CHANGELOG.md"
+        ],
+        "message": "chore(release): version ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
+      }
+    ]
+  ]
+}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4054871a..13a34fb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,3 @@
-# Change Log
-
-All notable changes to this project will be documented in this file.
-
-<a name="unreleased"></a>
-## [Unreleased]
-
-
-
 <a name="v2.11.0"></a>
 ## [v2.11.0] - 2021-11-07
 
diff --git a/Makefile b/Makefile
deleted file mode 100644
index f17351f1..00000000
--- a/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-.PHONY: changelog release
-
-scope ?= "minor"
-
-changelog-unrelease:
-	git-chglog --no-case -o CHANGELOG.md
-
-changelog:
-	git-chglog --no-case -o CHANGELOG.md --next-tag `semtag final -s $(scope) -o -f`
-
-release:
-	semtag final -s $(scope)
diff --git a/examples/s3-replication/main.tf b/examples/s3-replication/main.tf
index af3f0c1c..904abbf3 100644
--- a/examples/s3-replication/main.tf
+++ b/examples/s3-replication/main.tf
@@ -136,4 +136,4 @@ module "s3_bucket" {
     ]
   }
 
-}
\ No newline at end of file
+}