From 35599b8c7898f4ea4ee63e04bdc14529d3c0abd3 Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Wed, 2 Oct 2024 21:09:38 +0300 Subject: [PATCH] CI: check PR title (#429) Signed-off-by: Evgeny Malygin --- .github/workflows/ext/check_pr_title.py | 56 +++++++++++++++++++++++++ .github/workflows/pr-title-check.yaml | 25 +++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/ext/check_pr_title.py create mode 100644 .github/workflows/pr-title-check.yaml diff --git a/.github/workflows/ext/check_pr_title.py b/.github/workflows/ext/check_pr_title.py new file mode 100644 index 000000000..612b61e0c --- /dev/null +++ b/.github/workflows/ext/check_pr_title.py @@ -0,0 +1,56 @@ +# Copyright 2024 Bloomberg Finance L.P. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Script for checking PR title. +The script expects PR_TITLE environment variable to be set as an input parameter. +Usage: +export PR_TITLE="<...>" +python3 check_pr_title.py +""" +import os + + +def check_pr_title(): + title = os.environ.get("PR_TITLE") + if title is None or len(title) == 0: + raise RuntimeError( + "This script expects a non-empty environment variable PR_TITLE set" + ) + title = title.lower() + valid_prefixes = [ + "fix", + "feat", + "perf", + "ci", + "build", + "revert", + "ut", + "it", + "doc", + "refactor", + "misc", + "test", + ] + if not any(title.startswith(prefix.lower()) for prefix in valid_prefixes): + raise RuntimeError( + 'PR title "{}" doesn\'t start with a valid prefix, allowed prefixes: {}'.format( + title, " ".join(valid_prefixes) + ) + ) + + +if __name__ == "__main__": + check_pr_title() diff --git a/.github/workflows/pr-title-check.yaml b/.github/workflows/pr-title-check.yaml new file mode 100644 index 000000000..878109304 --- /dev/null +++ b/.github/workflows/pr-title-check.yaml @@ -0,0 +1,25 @@ +name: PR title check + +on: + pull_request: + types: + - "opened" + - "reopened" + - "synchronize" + - "labeled" + - "unlabeled" + - "edited" + +jobs: + pr_title_check: + runs-on: ubuntu-latest + name: PR Title Check + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: pr title check + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + python3 ${{ github.workspace }}/.github/workflows/ext/check_pr_title.py