Skip to content

Commit 168b82c

Browse files
committed
ci: add pr title linting to ci workflow
1 parent df108f6 commit 168b82c

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ on:
1212
branches: [ main ]
1313

1414
jobs:
15+
lint-pr-title:
16+
if: github.event_name == 'pull_request'
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
20+
- name: Set up Python
21+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
22+
with:
23+
python-version: "3.12"
24+
- name: Lint PR title
25+
run: python ops/lintcommit.py --subject "${{ github.event.pull_request.title }}"
26+
1527
build:
1628
runs-on: ubuntu-latest
1729
strategy:

ops/lintcommit.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,28 @@ def run_local() -> None:
192192

193193

194194
def main() -> None:
195-
run_local()
195+
import argparse
196+
197+
parser = argparse.ArgumentParser(
198+
description="Lint commit messages for conventional commits compliance."
199+
)
200+
parser.add_argument(
201+
"--subject",
202+
default=None,
203+
help="Validate a single subject line (e.g. a PR title). "
204+
"When omitted, runs in local mode checking commits ahead of origin/main.",
205+
)
206+
args = parser.parse_args()
207+
208+
if args.subject is not None:
209+
error: str | None = validate_subject(args.subject)
210+
if error:
211+
print(f"FAIL: {args.subject}", file=sys.stderr)
212+
print(f" Error: {error}", file=sys.stderr)
213+
sys.exit(1)
214+
print(f"PASS: {args.subject}")
215+
else:
216+
run_local()
196217

197218

198219
if __name__ == "__main__":

0 commit comments

Comments
 (0)