ci: [OCISDEV-1488] validate PR titles as conventional commits

Release notes will be generated from the squash-merge commits with
git-cliff, so the PR title has to be a conventional commit. Add the title
check, the git-cliff config with a preview target and a short convention
document.

Signed-off-by: Matteo <matteo.sonnenholzner@kiteworks.com>
This commit is contained in:
Matteo committed 2026-10-26 08:06:34 +01:00
1 parent 45e2b94b5e
commit 77f0c263dd
7 files changed
+199

No files matched your search

+2
View File
@@ -9,6 +9,8 @@ To make it possible for us to get your change reviewed and merged please careful
Please note that any kind of change needs first be submitted to the master branch which holds the next version of oCIS.
The PR title is used in the release notes, see COMMIT_CONVENTION.md.
Please set the following labels:
- Set label "Status:Needs-Review" for review or "Status:In-Progress" if the PR still has open tasks.
+28
View File
@@ -0,0 +1,28 @@
name: Validate PR title
# The squash-merge commit uses the PR title, and the release notes are
# generated from it (see cliff.toml), so the title must be a conventional commit.
on:
pull_request_target:
branches: [master, stable-*]
types: [opened, edited, synchronize, reopened]
permissions:
contents: read
pull-requests: read
jobs:
validate-pr-title:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# allow CI markers such as "[full-ci][tests-only]" in front of the type
headerPattern: '^(?:\[[a-z0-9.-]+\]\s*)*(\w*)(?:\((.*)\))?(!)?:\s(.*)$'
headerPatternCorrespondence: type, scope, breaking, subject
# lowercase description, as in the spec examples
subjectPattern: '^(?![A-Z]).+$'
subjectPatternError: 'The description "{subject}" must start with a lowercase letter.'
+47
View File
@@ -0,0 +1,47 @@
# Commit and PR Title Convention
Commits and PR titles follow [Conventional Commits](https://www.conventionalcommits.org).
PRs are squash-merged, so the PR title becomes the commit title on the target branch, and
the release notes are generated from these titles with [git-cliff](https://git-cliff.org)
(see [cliff.toml](cliff.toml)).
```
type(scope): description
```
- `type`: `fix`, `feat`, `perf`, `revert`, `chore`, `test`, `build`, `ci`, `docs`, `style` or `refactor`
- `scope`: optional, the area of the change, e.g. a service name like `graph` or `web`
- `!` before the colon marks a breaking change: `feat(proxy)!: remove the PROXY_LEGACY_AUTH option`
- `description`: lowercase, imperative, no trailing period
CI markers such as `[full-ci]` in front and a ticket key after the colon are allowed, they
are removed from the release notes:
```
[full-ci] fix(graph): [OCISDEV-1506] apply $filter before resolving users from other instances
```
## Release notes
Only `fix`, `feat`, `perf` and `revert` are listed, breaking changes additionally in their
own section. Each entry is the description, so it has to tell an admin what changed without
opening the PR:
| Instead of | Write |
|---|---|
| `fix: share listing` | `fix(graph): return shares of disabled spaces in the shared-with-me list` |
| `chore: fix public share` | `fix(frontend): resolve password protected public links` |
| `feat: harden nats` | `feat: add TLS support for the NATS store and registry connections` |
## Backports
Cherry-pick the change to the stable branch and keep the original PR title, so the fix
reads the same in both releases.
## Preview the release notes
Install [git-cliff](https://git-cliff.org/docs/installation), then:
```bash
make changelog-generate CHANGELOG_VERSION=v9.0.0
```
+3
View File
@@ -7,3 +7,6 @@ Please read the full contributing guidelines at:
For development setup, coding standards, and pull request process,
see the README in this repository.
PR titles must follow the [commit and PR title convention](COMMIT_CONVENTION.md), the
release notes are generated from them.
+8
View File
@@ -275,6 +275,14 @@ endif
mkdir -p ocis/dist
$(CALENS) --version $(CHANGELOG_VERSION) -o ocis/dist/CHANGELOG.md
# Release notes from conventional commits (see cliff.toml and scripts/changelog.sh).
.PHONY: changelog-generate
changelog-generate:
ifndef CHANGELOG_VERSION
$(error CHANGELOG_VERSION is undefined)
endif
@scripts/changelog.sh $(CHANGELOG_VERSION)
.PHONY: changelog-lint
changelog-lint:
@FAILED=0; \
+85
View File
@@ -0,0 +1,85 @@
# git-cliff configuration: generate release notes from conventional commits.
# https://git-cliff.org/docs/configuration
#
# One line per squash-merge commit, grouped by type:
# fix(graph): [OCISDEV-1234] return 404 for a deleted space (#1234)
# -> * **graph:** return 404 for a deleted space ([#1234](...))
[changelog]
header = ""
body = """
{%- macro subject(commit) -%}
{{ commit.message | split(pat="\n") | first | split(pat=" (#") | first | trim }}
{%- endmacro -%}
{%- macro entry(commit) -%}
{%- set title = commit.message | split(pat="\n") | first -%}
* {% if commit.scope %}**{{ commit.scope }}:** {% endif %}{{ self::subject(commit=commit) }}
{%- if title is containing(" (#") -%}
{%- set number = title | split(pat=" (#") | last | trim_end_matches(pat=")") %} ([#{{ number }}](https://github.com/owncloud/ocis/pull/{{ number }}))
{%- endif -%}
{%- endmacro -%}
{#- scripts/changelog.sh passes the previous release, git-cliff only knows it
when that tag is part of the range -#}
{%- set prev = get_env(name="CHANGELOG_PREVIOUS", default="") -%}
{%- if not prev and previous.version %}{% set prev = previous.version %}{% endif -%}
{% if version -%}
{%- set v = version | trim_start_matches(pat="v") -%}
# Changelog for [{{ v }}] ({{ timestamp | date(format="%Y-%m-%d") }})
{%- if prev %}
[{{ v }}]: https://github.com/owncloud/ocis/compare/{{ prev }}...{{ version }}
{%- endif %}
{%- else -%}
# Changelog for [unreleased]
{%- if prev %}
[unreleased]: https://github.com/owncloud/ocis/compare/{{ prev }}...master
{%- endif %}
{%- endif %}
{%- set breaking = commits | filter(attribute="breaking", value=true) %}
{%- if breaking | length > 0 %}
### Breaking Changes
{% for commit in breaking %}
{{ self::entry(commit=commit) }}
{%- endfor %}
{%- endif %}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim }}
{% for commit in commits %}
{{ self::entry(commit=commit) }}
{%- endfor %}
{% endfor %}
"""
trim = true
footer = ""
[git]
conventional_commits = true
# Non-conventional commits are kept (not dropped) and land in "Miscellaneous".
filter_unconventional = false
split_commits = false
protect_breaking_commits = true
filter_commits = false
# Final releases only: rc/dev tags and the web package tags are not versions.
tag_pattern = "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
sort_commits = "oldest"
commit_preprocessors = [
# drop CI markers ("[full-ci]") and ticket keys ("[OCISDEV-1234]") from the
# title, Jira is not public
{ pattern = '\s*\[(?:[a-z][a-z0-9.-]*|[A-Z][A-Z0-9]*-\d+)\]', replace = "" },
{ pattern = '\A\s+', replace = "" },
{ pattern = '\A(\w+(\([^)]*\))?!?:)\s*', replace = "${1} " },
]
# First match wins. The order of the groups is set by the HTML comment prefix.
commit_parsers = [
{ message = '^(chore|test|build|ci|docs|style|refactor)(\(.+\))?!?:', skip = true },
{ message = '^fix', group = "<!-- 1 -->Bug Fixes" },
{ message = '^feat', group = "<!-- 2 -->Features" },
{ message = '^perf', group = "<!-- 3 -->Performance" },
{ message = '^revert', group = "<!-- 4 -->Reverts" },
{ message = '.*', group = "<!-- 9 -->Miscellaneous" },
]
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Print the release notes of one version from conventional commits (see
# cliff.toml), from the previous final release up to the version's tag, or up
# to HEAD when the version is not tagged yet.
#
# Usage: changelog.sh <version>
set -euo pipefail
command -v git-cliff >/dev/null || { echo "git-cliff is not installed, see https://git-cliff.org/docs/installation" >&2; exit 1; }
version=${1:?usage: $0 <version>}
[[ $version == v* ]] || version="v$version"
# previous final release by version, so 8.2.1 follows 8.2.0 and 9.0.0 follows
# the newest 8.x; rc, dev and web package tags are ignored
previous=$( { git tag -l 'v[0-9]*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$'; echo "$version"; } \
| sort -uV | grep -B1 -Fx "$version" | grep -vFx "$version" || true)
# up to the tag, or up to HEAD named as the version when it is not tagged yet
if git rev-parse -q --verify "refs/tags/$version" >/dev/null; then
args=("${previous:+$previous..}$version")
else
args=("${previous:+$previous..}HEAD" --tag "$version")
fi
CHANGELOG_PREVIOUS=$previous git cliff --config cliff.toml "${args[@]}" | sed '/./,$!d'