From cd8da9c0d8ff25a2dabc588de6fdefe641a05c84 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Fri, 27 Sep 2024 18:36:38 -0700 Subject: [PATCH] chore: Check PR title for Conventional Commits syntax --- .commitlintrc.yml | 35 ++++++++++++++ .github/workflows/pr_title.yml | 86 ++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 .commitlintrc.yml create mode 100644 .github/workflows/pr_title.yml diff --git a/.commitlintrc.yml b/.commitlintrc.yml new file mode 100644 index 0000000..8a9d499 --- /dev/null +++ b/.commitlintrc.yml @@ -0,0 +1,35 @@ +rules: + # Body may be empty + body-empty: + level: ignore + + # Description must not be empty + description-empty: + level: error + + # Description must start with a capital letter and must not end with a period or space + description-format: + level: error + format: ^[A-Z0-9].*[^. ]$ + + # Description should be <70 chars + description-max-length: + level: warning + length: 70 + + # Scope is not allowed + scope: + level: error + options: [] + + # Subject line should exist + subject-empty: + level: error + + # Type must be one of these options + type: + level: error + options: + - fix + - feat + - chore diff --git a/.github/workflows/pr_title.yml b/.github/workflows/pr_title.yml new file mode 100644 index 0000000..f315c56 --- /dev/null +++ b/.github/workflows/pr_title.yml @@ -0,0 +1,86 @@ +name: PR title + +on: + pull_request: + types: [opened, synchronize, reopened, edited] + +jobs: + title_cc_validation: + name: Conventional commits validation + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check PR title + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + # If this step fails, please expand this step for more information. + # + # You will need to revise this pull request's title to + # match the "summary" (first) line of a Conventional Commit message. + # This enables us to automatically generate a meaningful changelog. + # + # The summary line (and thus the PR title) must have this exact format + # (including punctuation): + # + # type: description + # + # `type` describes the nature of changes you are making. This project + # requires the type to be one of these exact names: + # + # * fix + # * feat (will cause a minor version bump) + # * chore (will be omitted from changelog) + # + # NOTE: Conventional Commits also defines a `(scope)` parameter + # which can define a sub-area within the project where the change was + # made. This project is configured to disallow the use of `scope`. + # + # `description` is a short human-readable summary of the changes being made. + # + # This project enforces a few rules over and above the Conventional + # Commits definition of `description`: + # + # * The `description` must be non-empty. + # * The `description` must start with a capital letter or number. + # (Do not start `description` with a lower-case word.) + # * The `description` must not end with a period. + # + # This project does not currently enforce the following items, but + # we ask that you observe the following preferences in `description`: + # + # * The entire description should be written and capitalized as + # an English-language sentence, except (as noted earlier) that + # the trailing period must be omitted. + # * Any acronyms such as JSON or YAML should be capitalized as per + # commonusage in English-language sentences. + # + # After you edit the PR title, this task will run again and the + # warning should go away if you have made acceptable changes. + # + # For more information on Conventional Commits, please see: + # + # https://www.conventionalcommits.org/en/v1.0.0/ + # + # ------------ (end of message) ------------ + + if echo "$PR_TITLE" | grep -E '^chore(\(.*\))?: release '; then + echo "Exception / OK: chore release pattern" + exit 0; + fi + + echo "Installing commitlint-rs. Please wait 30-40 seconds ..." + cargo install --quiet commitlint-rs + set -e + + echo   + echo   + echo --- commitlint results for PR title \"$PR_TITLE\" --- + echo   + + echo "$PR_TITLE" | commitlint -g .commitlintrc.yml + + echo "✅ PR title matches all enforced rules."