Skip to content

Commit ccad449

Browse files
authored
chore(config): husky and commitlint husky and commitlint (#1472)
1 parent 4fbf0d2 commit ccad449

File tree

7 files changed

+578
-8
lines changed

7 files changed

+578
-8
lines changed

.github/workflows/ci-checks.yaml renamed to .github/workflows/checks.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# because act will use the proxy and the tests will fail
55
# act -j test --env-file dummy.env --rm
66

7-
name: CI Check
7+
name: Checks
88

99
on:
1010
pull_request:
@@ -15,6 +15,7 @@ on:
1515

1616
jobs:
1717
test:
18+
name: Run tests
1819
runs-on: ubuntu-latest
1920
container:
2021
image: ruby:3.2
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Pull Request Lint Check
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
- reopened
10+
11+
jobs:
12+
title-lint:
13+
name: Validate title
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Load config
21+
id: load_config
22+
run: |
23+
# Load types and scopes directly from commitlint.config.mjs and set as environment variables
24+
node --experimental-modules -e "
25+
import('./commitlint.config.mjs').then(({ types, scopes }) => {
26+
// Write types and scopes as multiline environment variables
27+
console.log('TYPES<<EOF');
28+
console.log(types.join('\n'));
29+
console.log('EOF');
30+
31+
console.log('SCOPES<<EOF');
32+
console.log(scopes.join('\n'));
33+
console.log('EOF');
34+
});
35+
" >> $GITHUB_ENV
36+
echo "Done!"
37+
38+
- name: CI Check Title
39+
uses: amannn/action-semantic-pull-request@v5
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
with:
43+
wip: true
44+
# Configure which types are allowed (newline-delimited).
45+
# Default: https://github.com/commitizen/conventional-commit-types
46+
types: |
47+
${{ env.TYPES }}
48+
scopes: |
49+
${{ env.SCOPES }}
50+
51+
# Configure that a scope must always be provided.
52+
requireScope: true
53+
# Configure which scopes are disallowed in PR titles (newline-delimited).
54+
# For instance by setting the value below, `chore(release): ...` (lowercase)
55+
# and `ci(e2e,release): ...` (unknown scope) will be rejected.
56+
# These are regex patterns auto-wrapped in `^ $`.
57+
disallowScopes: |
58+
release
59+
[A-Z]+
60+
# Configure additional validation for the subject based on a regex.
61+
# This example ensures the subject doesn't start with an uppercase character.
62+
subjectPattern: ^(?![A-Z]).+$
63+
# If `subjectPattern` is configured, you can use this property to override
64+
# the default error message that is shown when the pattern doesn't match.
65+
# The variables `subject` and `title` can be used within the message.
66+
subjectPatternError: |
67+
The subject "{subject}" found in the pull request title "{title}"
68+
didn't match the configured pattern. Please ensure that the subject
69+
doesn't start with an uppercase character.
70+
# If the PR contains one of these newline-delimited labels, the
71+
# validation is skipped. If you want to rerun the validation when
72+
# labels change, you might want to use the `labeled` and `unlabeled`
73+
# event triggers in your workflow.
74+
ignoreLabels: |
75+
bot
76+
ignore-semantic-pull-request
77+
# If you're using a format for the PR title that differs from the traditional Conventional
78+
# Commits spec, you can use these options to customize the parsing of the type, scope and
79+
# subject. The `headerPattern` should contain a regex where the capturing groups in parentheses
80+
# correspond to the parts listed in `headerPatternCorrespondence`.
81+
# See: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#headerpattern
82+
headerPattern: '^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$'
83+
headerPatternCorrespondence: type, scope, subject

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx commitlint --edit $1

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pnpm lint
2+
#pnpm format
3+
#pnpm typecheck

commitlint.config.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// import config from "./.github/commit-config.js"
2+
3+
export const types = ["build", "chore", "fix", "feat", "refactor", "research", "style", "test"]
4+
export const scopes = [
5+
"build",
6+
"config",
7+
"ci",
8+
"core",
9+
"docs",
10+
"deps",
11+
"infra",
12+
"ui",
13+
"version",
14+
/^ISSUE-\d+$/, // Regex pattern for ISSUE-<number>]
15+
]
16+
17+
export default {
18+
extends: ["@commitlint/config-conventional"],
19+
rules: {
20+
"type-enum": [2, "always", types], // Enforces the type to be one of the specified values
21+
"scope-enum": [2, "always", scopes],
22+
"scope-case": [2, "always", "kebab-case"], // Enforces kebab-case
23+
"subject-case": [
24+
2,
25+
"never",
26+
["start-case", "pascal-case", "upper-case"], // Disallows certain cases for the subject
27+
],
28+
},
29+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
"devDependencies": {
6868
"@babel/preset-env": "^7.24.7",
6969
"@babel/preset-react": "^7.24.7",
70+
"@commitlint/cli": "^19.6.0",
71+
"@commitlint/config-conventional": "^19.6.0",
7072
"@svgr/core": "^8.1.0",
7173
"@svgr/plugin-jsx": "^8.1.0",
7274
"@testing-library/react": "^14.0.0",
@@ -79,6 +81,7 @@
7981
"eslint-plugin-cypress": "^2.12.1",
8082
"eslint-plugin-react": "^7.29.4",
8183
"glob": "^8.0.1",
84+
"husky": "^9.1.7",
8285
"jest": "^29.7.0",
8386
"jest-environment-jsdom": "^29.7.0",
8487
"js-yaml": "^4.1.0",
@@ -97,7 +100,8 @@
97100
"test": "NODE_ENV=test jest --config jest.config.js",
98101
"build": "node ./config/esbuild/build.js",
99102
"format": "prettier --log-level warn --write \"**/*.{js,jsx,ts,tsx,md}\"",
100-
"check-format": "prettier --config ./.prettierrc --check \"**/*.{js,jsx,ts,tsx,md}\" "
103+
"check-format": "prettier --config ./.prettierrc --check \"**/*.{js,jsx,ts,tsx,md}\" ",
104+
"prepare": "husky"
101105
},
102106
"name": "elektra-cc-dashboard",
103107
"license": "SEE LICENSE IN LICENSE",

0 commit comments

Comments
 (0)