diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml new file mode 100644 index 0000000..70f3d13 --- /dev/null +++ b/.github/workflows/commit-lint.yml @@ -0,0 +1,29 @@ +name: Lint Commit Messages + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + commitlint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Install dependencies + run: npm install --legacy-peer-deps + + - name: Fetch base branch and run commitlint + run: | + git fetch --no-tags origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }} + FROM="$(git merge-base HEAD origin/${{ github.event.pull_request.base.ref }})" + npx commitlint --from "$FROM" --to ${{ github.event.pull_request.head.sha }} --verbose \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000..34eed8b --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no -- commitlint --edit $1 \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..2312dc5 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..43610a0 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,37 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'body-leading-blank': [2, 'always'], + 'body-max-line-length': [2, 'always', 100], + 'footer-leading-blank': [2, 'always'], + 'footer-max-line-length': [2, 'always', 100], + 'header-max-length': [2, 'always', 100], + 'subject-case': [ + 2, + 'never', + ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], + ], + 'subject-empty': [2, 'never'], + 'subject-full-stop': [2, 'never', '.'], + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + 'type-enum': [ + 2, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'style', + 'test' + ], + ], + }, + }; + \ No newline at end of file diff --git a/package.json b/package.json index 6c76d87..ca49f68 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,19 @@ "lint": "ng lint", "e2e": "ng e2e", "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build", - "build-ci": "(test -f src/environments/environment.ts || touch src/environments/environment.ts) && chmod +x ./scripts/*.js && ./scripts/ci-prebuild.js && node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --environment=ci && mkdir -p dist/WEB-INF && cp -R WEB-INF/* dist/WEB-INF/" + "build-ci": "(test -f src/environments/environment.ts || touch src/environments/environment.ts) && chmod +x ./scripts/*.js && ./scripts/ci-prebuild.js && node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --environment=ci && mkdir -p dist/WEB-INF && cp -R WEB-INF/* dist/WEB-INF/", + "prepare": "husky install", + "commit": "cz" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + }, + "lint-staged": { + "src/**/*.ts": [ + "tslint --fix" + ] }, "private": true, "dependencies": { @@ -83,6 +95,12 @@ "tslint": "5.2.0", "typescript": "2.2.0", "webpack": "3.10.0", - "xlsx": "^0.13.0" + "xlsx": "^0.13.0", + "@commitlint/cli": "^19.8.0", + "@commitlint/config-conventional": "^19.8.0", + "commitizen": "^4.3.1", + "cz-conventional-changelog": "^3.3.0", + "husky": "^9.1.7", + "lint-staged": "^15.2.2" } }