From a62fcf8b1baebc72946d0d74706fc0ebfa904638 Mon Sep 17 00:00:00 2001 From: Geoffrey van Wyk Date: Fri, 5 Jan 2024 05:26:19 +0200 Subject: [PATCH] build(ci): lint commits in pull requests Prevent the merging of unconventional commits into the master branch. Lint commits made directly onto the master branch. Issues: #18 --- .github/workflows/build.yml | 46 +++++++++++++++++++++++++++++++++++++ .husky/commit-msg | 2 +- package.json | 3 ++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4e2ef58 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,46 @@ +--- +name: Build + +on: + pull_request: {} + + push: + branches: + - master + +jobs: + commitlint: + name: Commit Lint + runs-on: ubuntu-latest + + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + with: + fetch-depth: ${{ github.event.pull_request.commits }} + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 21 + + - name: Install Node modules + run: npm install + + - name: Check program versions + run: | + node --version + npm --version + npm run commitlint -- --version + + - name: Validate last commit + if: github.event_name == 'push' + run: npm run commitlint -- --from HEAD~1 --to HEAD --verbose + + - name: Validate commits in pull request + if: github.event_name == 'pull_request' + run: >- + npm run commitlint -- + --from=${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} + --to=${{ github.event.pull_request.head.sha }} + --verbose diff --git a/.husky/commit-msg b/.husky/commit-msg index 482222a..45c2c4d 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npm run commitlint ${1} +npm run lint-commit-msg ${1} diff --git a/package.json b/package.json index 0e5eef2..f4d541b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ }, "scripts": { "prepare": "husky install", - "commitlint": "commitlint --edit" + "lint-commit-msg": "commitlint --edit", + "commitlint": "commitlint" } } \ No newline at end of file