From 04d10ef3dde578f79f5bfb26d161e9b8f45aa783 Mon Sep 17 00:00:00 2001 From: mister-ben Date: Mon, 4 Mar 2024 17:54:33 +0100 Subject: [PATCH] chore: Add action to validate PR titles (#8614) --- .github/actions/pr-titles.js | 13 +++++++++++++ .github/workflows/pr-titles.yml | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .github/actions/pr-titles.js create mode 100644 .github/workflows/pr-titles.yml diff --git a/.github/actions/pr-titles.js b/.github/actions/pr-titles.js new file mode 100644 index 000000000..35b76047d --- /dev/null +++ b/.github/actions/pr-titles.js @@ -0,0 +1,13 @@ +const core = require('@actions/core'); +const github = require('@actions/github'); + +(async function run() { + const title = github.context.payload.pull_request?.title; + const titleRegex = /^(chore|ci|docs|feat|fix|refactor|revert|test)(\(.+\))?!?: (.+)/; + + if (!!title.match(titleRegex)) { + core.info('Pull request title is OK'); + } else { + core.setFailed('Please use conventional commit style for the PR title so the merged change appears in the changelog. See https://www.conventionalcommits.org/.'); + } +})(); diff --git a/.github/workflows/pr-titles.yml b/.github/workflows/pr-titles.yml new file mode 100644 index 000000000..6ec3a61f6 --- /dev/null +++ b/.github/workflows/pr-titles.yml @@ -0,0 +1,22 @@ +name: PR title check + +on: + pull_request: + types: [opened, reopened, edited, synchronize] + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }} + cancel-in-progress: true + +jobs: + pr-title-lint: + name: Should follow conventional commit spec + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + - run: npm i @actions/core @actions/github + - run: node .github/actions/pr-titles.js