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

#372-CI-add-linting,-formatting-and-commit-message-checks #233

Closed
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
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pre-Commit

on:
workflow_call:
inputs:
ref:
description: The reference to build
type: string
required: true

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10.11"

- name: Run pre-commit
uses: pre-commit/[email protected]
19 changes: 19 additions & 0 deletions .github/workflows/pull-request-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pull request main

on:
pull_request_target:
branches: [main]
paths-ignore: ["docs/**"]

jobs:
test:
uses: ./.github/workflows/test-and-build.yml
with:
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit

pre-commit:
uses: ./.github/workflows/pre-commit.yml
with:
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit
12 changes: 6 additions & 6 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Build and Test
on:
push:
branches:
- main
pull_request_target:
branches:
- main
workflow_call:
inputs:
ref:
description: The reference to build
type: string
required: true

env:
AIRFLOW_HOME: /home/runner/work/workflows/workflows
Expand Down
11 changes: 11 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[general]
ignore=body-is-missing
extra-path=./scripts/gitlint_rules/
debug=true
verbosity=3

[title-max-length]
line-length=50

[body-max-line-length]
line-length=72
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
rev: "v2.7.1"
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/pycqa/isort
rev: "5.12.0"
hooks:
Expand All @@ -22,3 +23,12 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/jorisroovers/gitlint
rev: "v0.17.0"
hooks:
- id: gitlint
language: python
entry: gitlint
stages: [commit-msg]
args: [--msg-filename]

40 changes: 40 additions & 0 deletions scripts/gitlint_rules/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import re

from gitlint.rules import CommitRule, RuleViolation

class SignedOffBy(CommitRule):
"""This rule will enforce that each commit contains a "Signed-off-by" line."""

name = "body-requires-signed-off-by"
id = "Workflows1"

def validate(self, commit):
for line in commit.message.body:
if line.startswith("Signed-off-by"):
return

msg = "Body does not contain a 'Signed-Off-By' line"
return [RuleViolation(self.id, msg, line_nr=1)]


class ApprovedSubject(CommitRule):
"""Validate subject of each commit.

This rule will enforce that each commit starts with a "module: text" format.
The 'module' can be any alphanumeric word, and the message must start with a colon followed by a space.
"""

name = "approved-subject-in-title"
id = "Workflows2"

MODULE_PATTERN = re.compile(r"^[a-zA-Z0-9_-]+: .+")

def validate(self, commit):
title = commit.message.title

if not self.MODULE_PATTERN.match(title):
msg = "Subject does not follow 'module: text' format"
return [RuleViolation(self.id, msg, line_nr=1)]

return

Loading