-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (87 loc) · 3.42 KB
/
commitlint.yml
File metadata and controls
99 lines (87 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Reusable commitlint workflow — called by consumer repos
# Usage: uses: Solvely-Colin/solvely-launchpad/.github/workflows/commitlint.yml@v1
name: Commitlint
on:
workflow_call:
inputs:
package-manager:
description: 'Package manager (npm, pnpm, yarn) — reserved for future use'
type: string
default: 'npm'
strict:
description: 'Fail CI on invalid commit messages when true; warn-only when false'
type: boolean
default: false
permissions:
contents: read
concurrency:
group: commitlint-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
commitlint:
name: Lint commits
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 22
- name: Determine commit range
id: range
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "from=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
echo "to=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
BEFORE_SHA="${{ github.event.before }}"
if [ -z "$BEFORE_SHA" ] || [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
BEFORE_SHA="$(git rev-list --max-count=1 HEAD^ 2>/dev/null || true)"
fi
echo "from=${BEFORE_SHA:-${{ github.sha }}}" >> "$GITHUB_OUTPUT"
echo "to=${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
- name: Write Launchpad baseline config
shell: bash
run: |
cat > .launchpad.commitlint.config.cjs <<'EOC'
module.exports = {
rules: {
'type-empty': [2, 'never'],
'subject-empty': [2, 'never'],
'header-max-length': [2, 'always', 100]
}
};
EOC
- name: Lint commits
shell: bash
run: |
set +e
npx --yes @commitlint/cli \
--config .launchpad.commitlint.config.cjs \
--from "${{ steps.range.outputs.from }}" \
--to "${{ steps.range.outputs.to }}"
STATUS=$?
set -e
if [ "$STATUS" -eq 0 ]; then
echo "Commitlint passed."
echo "### Commitlint" >> "$GITHUB_STEP_SUMMARY"
echo "- mode: ${{ inputs.strict && 'strict' || 'warn' }}" >> "$GITHUB_STEP_SUMMARY"
echo "- result: pass" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
if [ "${{ inputs.strict }}" = "true" ]; then
echo "::error::Commitlint failed in strict mode. Use Conventional Commits (e.g. feat:, fix:, chore:) or set strict: false."
echo "### Commitlint" >> "$GITHUB_STEP_SUMMARY"
echo "- mode: strict" >> "$GITHUB_STEP_SUMMARY"
echo "- result: fail" >> "$GITHUB_STEP_SUMMARY"
exit "$STATUS"
fi
echo "::warning::Commitlint failed, but strict mode is disabled. Use Conventional Commits to improve release/changelog automation."
echo "### Commitlint" >> "$GITHUB_STEP_SUMMARY"
echo "- mode: warn" >> "$GITHUB_STEP_SUMMARY"
echo "- result: warning (non-blocking)" >> "$GITHUB_STEP_SUMMARY"
exit 0