Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automatically select release level #612

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,4 +28,4 @@ jobs:
git config user.email "[email protected]"
git config user.name "Github Automation"
- name: Create release PR
run: make RELEASE_LEVEL=${{ github.event.inputs.level }} release-pr
run: make release-pr
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions ci-scripts/release_level.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ci-scripts/release_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -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 = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing s
trim = true
# postprocessors
postprocessors = [
{ pattern = '<REPO>', 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}](<REPO>/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 = "<!-- 0 -->🚀 Features" },
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
{ message = "^test", group = "<!-- 6 -->🧪 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 = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
{ message = ".*", group = "<!-- 10 -->💼 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 = ""
Loading