From 66d53cb6a86d0cf65dc028b32a8046f204a572e3 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Tue, 30 May 2023 15:59:39 -0400 Subject: [PATCH] chore(ci): add conventional commits check This ensures that the title of the PR conforms to conventional commit style, which in turn ensures that the text of the squash commit will conform to the expected style. --- .github/workflows/pr_title.yml | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/pr_title.yml diff --git a/.github/workflows/pr_title.yml b/.github/workflows/pr_title.yml new file mode 100644 index 0000000..f5ce3c2 --- /dev/null +++ b/.github/workflows/pr_title.yml @@ -0,0 +1,58 @@ +name: PR Title Check + +on: + pull_request_target: + types: [opened, edited, synchronize, reopened] +jobs: + commitlint: + name: PR title / description conforms to semantic-release + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v3 + with: + node-version: "18" + - run: npm install @commitlint/config-conventional + - run: > + echo 'module.exports = { + // Workaround for https://github.com/dependabot/dependabot-core/issues/5923 + "ignores": [(message) => /^Bumps \[.+]\(.+\) from .+ to .+\.$/m.test(message)] + }' > .commitlintrc.js + - run: npx commitlint --extends @commitlint/config-conventional --verbose <<< $COMMIT_MSG + env: + COMMIT_MSG: > + ${{ github.event.pull_request.title }} + + ${{ github.event.pull_request.body }} + - if: failure() + uses: actions/github-script@v6 + with: + script: | + const message = `**ACTION NEEDED** + + Substrait follows the [Conventional Commits + specification](https://www.conventionalcommits.org/en/v1.0.0/) for + release automation. + + The PR title and description are used as the merge commit message.\ + Please update your PR title and description to match the specification. + ` + // Get list of current comments + const comments = await github.paginate(github.rest.issues.listComments, { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + // Check if this job already commented + for (const comment of comments) { + if (comment.body === message) { + return // Already commented + } + } + // Post the comment about Conventional Commits + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: message + }) + core.setFailed(message)