Skip to content

Commit 4e57c80

Browse files
committed
ci: add commit lint
1 parent ba657d8 commit 4e57c80

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/commit-lint.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Lint Workflow (Commit)
2+
3+
on:
4+
push:
5+
branches: '**'
6+
pull_request:
7+
8+
env:
9+
NODE_VERSION: lts/*
10+
11+
jobs:
12+
lint:
13+
name: Lint the commits
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Setup Node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ env.NODE_VERSION }}
26+
check-latest: true
27+
28+
- name: Install commitlint
29+
run: npm install @commitlint/cli @commitlint/config-conventional
30+
31+
- name: Determine BASE commit (push)
32+
if: github.event_name == 'push'
33+
env:
34+
GIT_COMMIT_SHA: ${{ github.event.before }}
35+
GIT_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
36+
run: |
37+
COMMIT_SHA="${GIT_COMMIT_SHA}"
38+
if [[ "${COMMIT_SHA}" =~ ^0+$ ]]; then
39+
echo "'before' is all zeros. This is likely a new branch. Finding a common ancestor with the default branch."
40+
41+
DEFAULT_BRANCH="${GIT_DEFAULT_BRANCH}"
42+
readonly DEFAULT_BRANCH
43+
44+
COMMIT_SHA="$(git merge-base --fork-point "remotes/origin/${DEFAULT_BRANCH}" || true)"
45+
if [ -z "${COMMIT_SHA}" ]; then
46+
echo "No common ancestor found, using the first commit in the repository."
47+
COMMIT_SHA="$(git rev-list --max-parents=0 --reverse HEAD | head -n 1)"
48+
fi
49+
fi
50+
51+
readonly COMMIT_SHA
52+
echo "GEECORE_COMMIT_BEFORE=${COMMIT_SHA}" >> "$GITHUB_ENV"
53+
54+
- name: Determine BASE commit (pull request)
55+
if: github.event_name == 'pull_request'
56+
env:
57+
GIT_COMMIT_SHA: ${{ github.event.pull_request.base.sha }}
58+
run: echo "GEECORE_COMMIT_BEFORE=${GIT_COMMIT_SHA}" >> "$GITHUB_ENV"
59+
60+
- name: Determine HEAD commit
61+
env:
62+
GIT_COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
63+
run: echo "GEECORE_COMMIT_AFTER=${GIT_COMMIT_SHA}" >> "$GITHUB_ENV"
64+
65+
- name: Run commitlint
66+
run: |
67+
npx commitlint \
68+
--from "${{ env.GEECORE_COMMIT_BEFORE }}" \
69+
--to "${{ env.GEECORE_COMMIT_AFTER }}" \
70+
--verbose

0 commit comments

Comments
 (0)