Compare commits

..

1 Commits

Author SHA1 Message Date
18f167418d chore: setup commitlint and git hooks
Some checks failed
Commit Message Check / conventional-commits (pull_request) Failing after 6s
Deploy monie-backend to dev (kaniko) / build-and-deploy (pull_request) Successful in 0s
Deploy monie-backend (kaniko) / build-and-deploy (pull_request) Successful in 0s
2026-04-05 00:15:38 +03:00

View File

@@ -10,50 +10,21 @@ jobs:
runs-on: [self-hosted, linux] runs-on: [self-hosted, linux]
steps: steps:
- name: Prepare git repository - name: Checkout
env: uses: actions/checkout@v4
SERVER_URL: ${{ github.server_url }} with:
REPOSITORY: ${{ github.repository }} fetch-depth: 0
GITHUB_TOKEN: ${{ github.token }}
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
if [ ! -d .git ]; then - name: Setup Node.js
git init uses: actions/setup-node@v4
fi with:
node-version: 22
cache: npm
if git remote get-url origin >/dev/null 2>&1; then - name: Install dependencies
git remote set-url origin "${SERVER_URL}/${REPOSITORY}.git" run: npm ci --ignore-scripts
else
git remote add origin "${SERVER_URL}/${REPOSITORY}.git"
fi
FETCH_CMD=(git fetch --force --prune --no-tags origin '+refs/heads/*:refs/remotes/origin/*') - name: Validate commit messages with commitlint
if [ -n "${GITHUB_TOKEN:-}" ]; then
FETCH_CMD=(git -c "http.extraHeader=Authorization: Bearer ${GITHUB_TOKEN}" fetch --force --prune --no-tags origin '+refs/heads/*:refs/remotes/origin/*')
fi
"${FETCH_CMD[@]}"
for SHA in "${HEAD_SHA:-}" "${PR_BASE_SHA:-}" "${PR_HEAD_SHA:-}" "${BEFORE_SHA:-}"; do
if [ -n "${SHA}" ] && [ "${SHA}" != "0000000000000000000000000000000000000000" ]; then
if [ -n "${GITHUB_TOKEN:-}" ]; then
git -c "http.extraHeader=Authorization: Bearer ${GITHUB_TOKEN}" fetch --no-tags origin "${SHA}" || true
else
git fetch --no-tags origin "${SHA}" || true
fi
fi
done
if [ -n "${HEAD_SHA:-}" ] && git cat-file -e "${HEAD_SHA}^{commit}" 2>/dev/null; then
git checkout --detach "${HEAD_SHA}"
fi
- name: Validate commit messages
env: env:
EVENT_NAME: ${{ github.event_name }} EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }} BEFORE_SHA: ${{ github.event.before }}
@@ -92,38 +63,7 @@ jobs:
fi fi
if [ -n "${BASE_SHA}" ] && [ "${BASE_SHA}" != "${TARGET_SHA}" ]; then if [ -n "${BASE_SHA}" ] && [ "${BASE_SHA}" != "${TARGET_SHA}" ]; then
MESSAGES="$(git log --format=%s "${BASE_SHA}..${TARGET_SHA}")" npx --no -- commitlint --from "${BASE_SHA}" --to "${TARGET_SHA}" --verbose
else else
MESSAGES="$(git log -1 --format=%s "${TARGET_SHA}")" git log -1 --format=%s "${TARGET_SHA}" | npx --no -- commitlint --verbose
fi
if [ -z "${MESSAGES}" ]; then
MESSAGES="$(git log -1 --format=%s "${TARGET_SHA}")"
fi
PATTERN='^(build|chore|ci|docs|feat|fix|perf|refactor|style|test)(\([a-z0-9._/-]+\))?(!)?: .+'
FAILED=0
while IFS= read -r SUBJECT; do
[ -z "${SUBJECT}" ] && continue
if [[ "${SUBJECT}" =~ ^Merge[[:space:]] ]]; then
continue
fi
if [[ "${SUBJECT}" =~ ^Revert[[:space:]] ]]; then
continue
fi
if [[ ! "${SUBJECT}" =~ ${PATTERN} ]]; then
echo "Invalid commit message: ${SUBJECT}"
FAILED=1
else
echo "OK: ${SUBJECT}"
fi
done <<< "${MESSAGES}"
if [ "${FAILED}" -ne 0 ]; then
echo "Conventional Commit check failed."
exit 1
fi fi