From 2f9238f3e8f6cfa0c10d2d1b5e359034d774c168 Mon Sep 17 00:00:00 2001 From: dark0dave Date: Thu, 14 Dec 2023 11:07:18 +0000 Subject: [PATCH 1/2] feat(git-cliff): Add git-cliff Signed-off-by: dark0dave --- Makefile | 2 +- cliff.toml | 82 +++++++++++++++++++++++++++++++++++++ scripts/alpine-setup.sh | 6 +-- scripts/changelog.tmpl | 72 -------------------------------- scripts/github-changelog.sh | 21 ---------- 5 files changed, 84 insertions(+), 99 deletions(-) create mode 100644 cliff.toml delete mode 100644 scripts/changelog.tmpl delete mode 100755 scripts/github-changelog.sh diff --git a/Makefile b/Makefile index c4d5dd71..bf31b52c 100644 --- a/Makefile +++ b/Makefile @@ -98,5 +98,5 @@ clean: ## Generate Changelog based on PRs changelog: - OUTPUT_FILE=$(RELEASE_DIR)/$(CHANGELOG) ./scripts/github-changelog.sh + git cliff --latest -o $(RELEASE_DIR)/$(CHANGELOG) .PHONY: changelog diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000..3688e1d6 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,82 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://tera.netlify.app/docs +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" +# postprocessors +postprocessors = [ + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL +] +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, # replace issue numbers +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^doc", group = "Documentation" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactor" }, + { message = "^style", group = "Styling" }, + { message = "^test", group = "Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|ci", group = "Miscellaneous Tasks" }, + { body = ".*security", group = "Security" }, + { message = "^revert", group = "Revert" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = false +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 diff --git a/scripts/alpine-setup.sh b/scripts/alpine-setup.sh index a9aa42dc..c1768013 100755 --- a/scripts/alpine-setup.sh +++ b/scripts/alpine-setup.sh @@ -5,12 +5,12 @@ set -eou pipefail LC_CTYPE=C OPA_VERSION="0.22.0" -CHANGELOG_VERSION="1.1.0" apk add --update --no-cache \ bash \ curl \ git \ + git-cliff \ jq \ make \ tar \ @@ -18,7 +18,3 @@ apk add --update --no-cache \ wget -q -O "/usr/local/bin/opa" "https://github.com/open-policy-agent/opa/releases/download/v${OPA_VERSION}/opa_linux_amd64" chmod +x "/usr/local/bin/opa" - -wget -q "https://github.com/paultyng/changelog-gen/releases/download/v${CHANGELOG_VERSION}/changelog-gen_Linux_x86_64.tar.gz" -O - | tar -xz -chmod +x changelog-gen -mv changelog-gen /usr/local/bin/changelog-gen diff --git a/scripts/changelog.tmpl b/scripts/changelog.tmpl deleted file mode 100644 index 9c1cd4d0..00000000 --- a/scripts/changelog.tmpl +++ /dev/null @@ -1,72 +0,0 @@ -{{- $announcements := newStringList -}} -{{- $breaking := newStringList -}} -{{- $features := newStringList -}} -{{- $changes := newStringList -}} -{{- $fixes := newStringList -}} -{{- $other := newStringList -}} - -{{- range . -}} - {{if has "announcement" .Labels -}} - {{$features = append $announcements (renderReleaseNote .) -}} - {{else if .BreakingChange -}} - {{$breaking = append $breaking (renderReleaseNote .) -}} - {{else if has "feature" .Labels -}} - {{$features = append $features (renderReleaseNote .) -}} - {{else if has "change" .Labels -}} - {{$fixes = append $changes (renderReleaseNote .) -}} - {{else if has "fix" .Labels -}} - {{$fixes = append $fixes (renderReleaseNote .) -}} - {{else -}} - {{$other = append $other (renderReleaseNote .) -}} - {{end -}} -{{- end -}} - -{{- if gt (len $announcements) 0 -}} -{{range $announcements | sortAlpha -}} -{{. }} -{{end -}} -{{- end -}} - -**Docker Image**: `{{ expandenv "$REGISTRY/$IMAGE_NAME:$GITHUB_REF_NAME" }}` - -### Changelog - -{{- if gt (len $breaking) 0}} -**Breaking Changes**: - -{{range $breaking | sortAlpha -}} -* {{. }} -{{end -}} -{{- end -}} - -{{- if gt (len $features) 0}} -**Features**: - -{{range $features | sortAlpha -}} -* {{. }} -{{end -}} -{{- end -}} - -{{- if gt (len $changes) 0}} -**Changes**: - -{{range $changes | sortAlpha -}} -* {{. }} -{{end -}} -{{- end -}} - -{{- if gt (len $fixes) 0}} -**Fixes**: - -{{range $fixes | sortAlpha -}} -* {{. }} -{{end -}} -{{- end -}} - -{{- if gt (len $other) 0}} -**Internal/Other**: - -{{range $other | sortAlpha -}} -* {{. }} -{{end -}} -{{- end -}} diff --git a/scripts/github-changelog.sh b/scripts/github-changelog.sh deleted file mode 100755 index 2ae44a4d..00000000 --- a/scripts/github-changelog.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env sh -# Set strict error checking -set -eou pipefail - -GH_ORG="doitintl" -GH_REPO="kube-no-trouble" -CHANGELOG_TEMPLATE="./scripts/changelog.tmpl" -OUTPUT_FILE="${OUTPUT_FILE:="./changelog.md"}" - -# Needed for ci -git config --global --add safe.directory "${GITHUB_WORKSPACE:-$PWD}" || true - -RELEASE_SHA="$(curl --silent "https://api.github.com/repos/${GH_ORG}/${GH_REPO}/releases/latest" \ - | jq -r '.target_commitish')" -MASTER_SHA="$(git rev-parse origin/master)" - -echo "- Generating changelog (${OUTPUT_FILE})" - -changelog-gen -changelog "${CHANGELOG_TEMPLATE}" \ - -owner "${GH_ORG}" -repo "${GH_REPO}" \ - "${RELEASE_SHA}" "${MASTER_SHA}" | tee "${OUTPUT_FILE}" From e15bb40cf199a78aad97f7f3b0a86c4b62ede738 Mon Sep 17 00:00:00 2001 From: dark0dave Date: Thu, 14 Dec 2023 12:10:38 +0000 Subject: [PATCH 2/2] chore(bump): Bump alpine linux version for git-cliff Signed-off-by: dark0dave --- .github/workflows/main.yaml | 4 ++-- Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index a96e2dd5..db04474e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,7 +21,7 @@ jobs: test: name: test runs-on: ubuntu-latest - container: golang:1.21-alpine3.17 + container: golang:1.21-alpine3.19 steps: - name: Install git run: apk add --update --no-cache git @@ -37,7 +37,7 @@ jobs: build: name: build runs-on: ubuntu-latest - container: golang:1.21-alpine3.17 + container: golang:1.21-alpine3.19 strategy: matrix: os: [linux, darwin, windows] diff --git a/Dockerfile b/Dockerfile index 05e6f568..3ee18e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.21-alpine3.17 AS builder +FROM --platform=$BUILDPLATFORM golang:1.21-alpine3.19 AS builder ARG GITHUB_REF GITHUB_SHA WORKDIR /src COPY go.mod go.sum ./