diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index c14bc2784..fc1972ecf 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -6,17 +6,7 @@ permissions: pull-requests: write on: - workflow_dispatch: - inputs: - level: - description: 'Release level' - required: true - default: 'minor' - type: choice - options: - - patch - - minor - - major + workflow_dispatch: {} jobs: release: @@ -38,4 +28,4 @@ jobs: git config user.email "github@3box.io" git config user.name "Github Automation" - name: Create release PR - run: make RELEASE_LEVEL=${{ github.event.inputs.level }} release-pr + run: make release-pr diff --git a/Makefile b/Makefile index 80dc9c06c..4f793741e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,6 @@ RUSTFLAGS = -D warnings --cfg tokio_unstable CARGO = RUSTFLAGS='${RUSTFLAGS}' cargo -RELEASE_LEVEL ?= minor - # ECS environment to deploy image to DEPLOY_ENV ?= dev @@ -81,7 +79,7 @@ debug: # Prepare a release PR. .PHONY: release-pr release-pr: - ./ci-scripts/release_pr.sh ${RELEASE_LEVEL} + ./ci-scripts/release_pr.sh .PHONY: test test: diff --git a/ci-scripts/release_level.sh b/ci-scripts/release_level.sh new file mode 100755 index 000000000..d319d4d20 --- /dev/null +++ b/ci-scripts/release_level.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Script to determine the next release level based on conventional commits. +# +# Possible levels: +# * patch +# * minor +# +# Any feature commits indicates a minor release. The lack of feature commits indicates +# a patch release. Major releases are expected to be handled manually. +# +# Assumptions: +# * git is installed +# * git-cliff is installed +# * grep is installed + +# Ensure we are in the git root +cd $(git rev-parse --show-toplevel) + +level=patch + +# Using git cliff determine if there are any feat commits that do not belong to a tag. +git cliff --unreleased --strip all --body "{% for group, commits in commits | group_by(attribute=\"group\") %} +{{ group }} {{ commits | length }} +{% endfor %}" | grep Features > /dev/null +ret=$? +if [[ $ret = 0 ]] +then + level=minor +fi + +echo $level diff --git a/ci-scripts/release_pr.sh b/ci-scripts/release_pr.sh index 3c94f0ade..e1996d7b8 100755 --- a/ci-scripts/release_pr.sh +++ b/ci-scripts/release_pr.sh @@ -22,7 +22,7 @@ set -e cd $(git rev-parse --show-toplevel) # First determine the next release level -level=$1 +level=$(./ci-scripts/release_level.sh) # Print commits since last tag cargo release changes diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..a25d2fa80 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,90 @@ +# 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] +# template for the changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/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 | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing s +trim = true +# postprocessors +postprocessors = [ + { pattern = '', replace = "https://github.com/ceramicnetwork/rust-ceramic" }, # replace repository URL +] +# render body even when there are no releases to process +# render_always = true +# output file path +# output = "test.md" + +[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 = [ + # Replace issue numbers + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))" }, + # Check spelling of the commit with https://github.com/crate-ci/typos + # If the spelling is incorrect, it will be automatically fixed. + #{ pattern = '.*', replace_command = 'typos --write-changes -' }, +] +# 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" }, + { message = ".*", group = "๐Ÿ’ผ Other" }, +] +# filter out the commits that are not matched by commit parsers +filter_commits = false +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "" +# regex for ignoring tags +ignore_tags = ""