From efab7b251e128c69d5cd0817897f03060f170912 Mon Sep 17 00:00:00 2001 From: Patrick Fernie Date: Sat, 5 Nov 2022 15:00:02 -0400 Subject: [PATCH] ci: setup for `git cliff` usage --- Cargo.toml | 2 +- cliff.toml | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ release.sh | 47 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 cliff.toml create mode 100755 release.sh diff --git a/Cargo.toml b/Cargo.toml index d4b56c8..0239c98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reqwest_cookie_store" -version = "0.5.0" +version = "0.5.0" # managed by release.sh authors = ["Patrick Fernie "] edition = "2018" description = "A simple crate providing an implementation of the `reqwest::cookie::CookieStore` trait for `cookie_store::CookieStore`" diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..6978276 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,64 @@ +# configuration file for git-cliff (0.1.0) + +[changelog] +# changelog header +header = """ +# Changelog\n +""" +# template for the changelog body +# https://tera.netlify.app/docs/#introduction +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 = """ +""" + +[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}](https://github.com/orhun/git-cliff/issues/${2}))"}, +] +# 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", group = "Miscellaneous Tasks"}, + { body = ".*security", group = "Security"}, +] +# 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 chronologically +date_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..c303518 --- /dev/null +++ b/release.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +git_status=`git status --porcelain` +if [[ ! -z $git_status ]]; then + echo -e "\e[31muncommitted state:\e[0m" + git status -s + echo -e "\e[31mplease commit or tidy uncommitted state before running release\e[0m" + exit +fi + +# takes the tag as an argument (e.g. v0.1.0) +if [ -n "$1" ]; then + if ! $(echo "${1}"|grep -q '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'); then + echo -e "\e[31m${1} not a version of the expected format; please use v#.#.# format\e[0m" + exit + fi + # update the version + msg="# managed by release.sh" + sed "s/^version = .* $msg$/version = \"${1#v}\" $msg/" -i Cargo.toml + # update the changelog + git cliff --date-order --sort newest --unreleased --tag "$1" --prepend CHANGELOG.md + git diff + echo -e -n "\e[33mProceed? \e[0m" + read -n 1 -s -p "[y/N] " proceed + echo + if [[ "${proceed}" != "y" ]]; then + echo -e "\e[31maborting; leaving dirty state:\e[0m" + git status -s + exit + fi + git add -A + git commit -m "chore(release): prepare for $1" + git show + # generate a changelog for the tag message + export GIT_CLIFF_TEMPLATE="\ + {% 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 }} ({{ commit.id | truncate(length=7, end=\"\") }})\ + {% endfor %} + {% endfor %}" + changelog=$(git cliff --date-order --sort newest --unreleased --strip all) + git tag "$1" -m "Release $1" -m "$changelog" + git show -q "$1" +else + echo "warn: please provide a tag" +fi