-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add cspell and commitlint to pre-commit and ci (#2393)
- Loading branch information
Showing
8 changed files
with
1,582 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": "0.2", | ||
"language": "en", | ||
"words": [ | ||
"githubusercontent", | ||
"commitlint", | ||
"EDITMSG", | ||
"codespell" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
ORANGE='\033[0;33m' | ||
NC='\033[0m' | ||
BOLD='\033[1m' | ||
NORMAL='\033[0m' | ||
|
||
|
||
echo $GIT_COMMIT | ||
|
||
check_file() { | ||
local file=$1 | ||
local match_pattern=$2 | ||
|
||
local file_changes_with_context=$(git diff -U999999999 -p --cached --color=always -- $file) | ||
local matched_additions=$(echo "$file_changes_with_context" | grep -C4 $'^\e\\[32m\+.*'"$match_pattern") | ||
|
||
if [ -n "$matched_additions" ]; then | ||
echo -e "${ORANGE}[WARNING]${NC} ${BOLD}$file${NORMAL} contains some $match_pattern." | ||
echo "$matched_additions" | ||
echo -e "\n" | ||
fi | ||
} | ||
|
||
|
||
for file in `git diff --cached -p --name-status | cut -c3-`; do | ||
check_file $file 'TODO' | ||
done | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Validate PR Title | ||
on: | ||
pull_request: | ||
types: [opened, edited, synchronize] | ||
permissions: | ||
pull-requests: write | ||
contents: read | ||
jobs: | ||
lint: | ||
name: 'Lint' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
- name: Install Commitlint and CSpell | ||
run: npm install --save-dev @commitlint/{config-conventional,cli} cspell | ||
- run: echo "${{ github.event.pull_request.title }}" > pr-title.txt | ||
- name: Run Commitlint | ||
id: commitlint | ||
run: npx commitlint --edit pr-title.txt > commitlint_output.txt 2>&1 | ||
if: always() | ||
- name: Run CSpell | ||
id: cspell | ||
run: npx cspell --config .cspell.json pr-title.txt > cspell_output.txt 2>&1 | ||
if: always() | ||
- name: Delete Old Bot Comments | ||
if: always() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Fetch all comments on the PR | ||
COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[] | select(.user.login == "github-actions[bot]") | .id') | ||
# Delete comments authored by the bot | ||
for COMMENT_ID in $COMMENTS; do | ||
gh api repos/${{ github.repository }}/issues/comments/$COMMENT_ID -X DELETE | ||
done | ||
- name: Post PR Comment | ||
if: always() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Initialize status messages | ||
STATUS_COMMITLINT="PASSED" | ||
STATUS_CSPELL="PASSED" | ||
COMMITLINT_OUTPUT=$(cat commitlint_output.txt) | ||
CSPELL_OUTPUT=$(cat cspell_output.txt) | ||
COMMENT_BODY="### Found Issues In PR Title\n" | ||
if [ "${{ steps.commitlint.outcome }}" == "failure" ]; then | ||
STATUS_COMMITLINT="FAILED" | ||
fi | ||
if [ "${{ steps.cspell.outcome }}" == "failure" ]; then | ||
STATUS_CSPELL="FAILED" | ||
fi | ||
if [ "$STATUS_COMMITLINT" == "FAILED" ]; then | ||
COMMENT_BODY+="**❌ Conventional Commit Format**\n" | ||
COMMENT_BODY+="\n\`\`\`\n$COMMITLINT_OUTPUT\n\`\`\`\n" | ||
fi | ||
if [ "$STATUS_CSPELL" == "FAILED" ]; then | ||
COMMENT_BODY+="**❌ Spelling Error**\n" | ||
COMMENT_BODY+="\n\`\`\`\n$CSPELL_OUTPUT\n\`\`\`\n" | ||
COMMENT_BODY+="\n> If you believe the spelling error is a false positive, please add the word in **cspell.json** file.\n" | ||
fi | ||
if [ "$STATUS_COMMITLINT" == "FAILED" ] || [ "$STATUS_CSPELL" == "FAILED" ]; then | ||
# Post the comment | ||
echo -e "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file - | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
module.exports = { | ||
parserPreset: 'conventional-changelog-conventionalcommits', | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { | ||
'subject-empty': [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', | ||
], | ||
], | ||
'header-max-length': [2, 'always', 72], | ||
'subject-case': [2, 'always', 'sentence-case'], | ||
'scope-case': [2, 'always', 'kebab-case'], | ||
'body-case': [2, 'always', 'sentence-case'], | ||
'body-leading-blank': [2, 'always'], | ||
'footer-leading-blank': [2, 'always'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# !/usr/bin/env bash | ||
|
||
echo "Installing python dev dependencies" | ||
pip install -r dev-requirements.txt | ||
|
||
echo "Installing nodejs dev dependencies" | ||
yarn install --frozen-lockfile --dev | ||
|
||
echo "Setting up pre-commit hooks" | ||
pre-commit install | ||
|
||
echo "Setting up commit-msg hooks" | ||
pre-commit install -t commit-msg | ||
|
||
echo "Setup complete" |
Oops, something went wrong.