ci: Use the ci-fairy job to check commit messages

Replace the custom signed-off-by job with one used across multiple fdo
projects. This one also checks a few more things including subject
lengths etc.

We don't want to run it on master so it doesn't fail after merging for
whatever reason (any error should be caught by the MR pipeline anyway).

And we need a higher git depth so ci-fairy can find the merge base.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2026-05-28 14:34:27 +10:00
commit 18f4a7ee8b
2 changed files with 9 additions and 64 deletions

View file

@ -4,6 +4,7 @@ include:
file:
- '/templates/fedora.yml'
- '/templates/debian.yml'
- '/templates/ci-fairy.yml'
variables:
FDO_DISTRIBUTION_TAG: latest
@ -52,12 +53,18 @@ stages:
image: $FEDORA_IMAGE
verify_signoff:
extends:
- .fdo.ci-fairy
stage: pre-commit
script:
- git fetch origin master
- python3 contrib/git-signoff.py
- ci-fairy -vv check-commits --signed-off-by --junit-xml=results.xml
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
GIT_DEPTH: 100
artifacts:
reports:
junit: results.xml
pre_commit:
stage: pre-commit

View file

@ -1,62 +0,0 @@
#!/usr/bin/env python3
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Verify that all commits added on the current branch (compared to
# origin/master) contain a properly formatted Signed-off-by tag.
from __future__ import annotations
import re
import subprocess
import sys
SIGNOFF_RE = re.compile(r"^Signed-off-by: .+ <.+@.+\..+>$")
def get_added_commits() -> list[tuple[str, str]]:
result = subprocess.run(
["git", "log", "--format=%H %s", "origin/master..HEAD"],
capture_output=True,
text=True,
check=True,
)
commits = []
for line in result.stdout.strip().splitlines():
sha, subject = line.split(" ", 1)
commits.append((sha, subject))
return commits
def get_commit_message(sha: str) -> str:
result = subprocess.run(
["git", "log", "-1", "--format=%B", sha],
capture_output=True,
text=True,
check=True,
)
return result.stdout
def main() -> int:
commits = get_added_commits()
if not commits:
print("No commits found between origin/master and HEAD.")
return 0
retval = 0
for sha, subject in commits:
message = get_commit_message(sha)
has_signoff = any(SIGNOFF_RE.match(line) for line in message.splitlines())
if not has_signoff:
print(
f"ERROR: Signed-off-by tag cannot be found in commit "
f'{sha[:12]} ("{subject}")'
)
retval = 1
return retval
if __name__ == "__main__":
raise SystemExit(main())