61 lines
1.9 KiB
YAML
61 lines
1.9 KiB
YAML
name: Commit Message Check
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
pull_request:
|
|
|
|
jobs:
|
|
conventional-commits:
|
|
runs-on: [self-hosted, linux]
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
|
|
- name: Install dependencies
|
|
run: npm ci --ignore-scripts
|
|
|
|
- name: Validate commit messages with commitlint
|
|
env:
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
BEFORE_SHA: ${{ github.event.before }}
|
|
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
|
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
HEAD_SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
BASE_SHA=""
|
|
TARGET_SHA="${HEAD_SHA}"
|
|
|
|
if [ "${EVENT_NAME}" = "pull_request" ] && [ -n "${PR_HEAD_SHA:-}" ]; then
|
|
TARGET_SHA="${PR_HEAD_SHA}"
|
|
fi
|
|
|
|
if [ "${EVENT_NAME}" = "pull_request" ] && [ -n "${PR_BASE_SHA:-}" ] && [ -n "${TARGET_SHA:-}" ]; then
|
|
BASE_SHA="$(git merge-base "${PR_BASE_SHA}" "${TARGET_SHA}" || true)"
|
|
|
|
if [ -z "${BASE_SHA}" ]; then
|
|
BASE_SHA="${PR_BASE_SHA}"
|
|
fi
|
|
elif [ -n "${BEFORE_SHA:-}" ] && [ "${BEFORE_SHA}" != "0000000000000000000000000000000000000000" ]; then
|
|
BASE_SHA="${BEFORE_SHA}"
|
|
elif git rev-parse "${TARGET_SHA}^" >/dev/null 2>&1; then
|
|
BASE_SHA="$(git rev-parse "${TARGET_SHA}^")"
|
|
fi
|
|
|
|
if [ -n "${BASE_SHA}" ] && [ "${BASE_SHA}" != "${TARGET_SHA}" ]; then
|
|
npx --no -- commitlint --from "${BASE_SHA}" --to "${TARGET_SHA}" --verbose
|
|
else
|
|
git log -1 --format=%s "${TARGET_SHA}" | npx --no -- commitlint --verbose
|
|
fi
|