From 77f0c263ddeb509dcff05cb6add13081e17c227e Mon Sep 17 00:00:00 2001 From: Matteo Date: Mon, 26 Oct 2026 08:06:34 +0100 Subject: [PATCH] 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 --- .github/pull_request_template.md | 2 + .github/workflows/pr-title.yml | 28 +++++++++++ COMMIT_CONVENTION.md | 47 ++++++++++++++++++ CONTRIBUTING.md | 3 ++ Makefile | 8 +++ cliff.toml | 85 ++++++++++++++++++++++++++++++++ scripts/changelog.sh | 26 ++++++++++ 7 files changed, 199 insertions(+) create mode 100644 .github/workflows/pr-title.yml create mode 100644 COMMIT_CONVENTION.md create mode 100644 cliff.toml create mode 100755 scripts/changelog.sh diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 85a71262243..64f564335c9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -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. diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 00000000000..f052bd78af2 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -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.' diff --git a/COMMIT_CONVENTION.md b/COMMIT_CONVENTION.md new file mode 100644 index 00000000000..440125ac095 --- /dev/null +++ b/COMMIT_CONVENTION.md @@ -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 +``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65c99156de9..59428ff7cb3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/Makefile b/Makefile index 07355ea31fd..904703aa236 100644 --- a/Makefile +++ b/Makefile @@ -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; \ diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000000..cfd1153dfe9 --- /dev/null +++ b/cliff.toml @@ -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 = "Bug Fixes" }, + { message = '^feat', group = "Features" }, + { message = '^perf', group = "Performance" }, + { message = '^revert', group = "Reverts" }, + { message = '.*', group = "Miscellaneous" }, +] diff --git a/scripts/changelog.sh b/scripts/changelog.sh new file mode 100755 index 00000000000..f9108cf4318 --- /dev/null +++ b/scripts/changelog.sh @@ -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 +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 == 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'