Skip to content

Commit 89d6fd5

Browse files
authored
feature: Add codespell check (#204)
1 parent b3c8258 commit 89d6fd5

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.codespellrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[codespell]
2+
skip = build,*.drawio,*.svg,*.pdf,footprints/Espressif.pretty,*.png,3dmodels/espressif.3dshapes
3+
ignore-words-list = laf,OT
4+
write-changes = true

.github/workflows/pre_commit.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Pre-Commit Checks
2+
3+
# Triggers on pull requests and pushes to master or main branches
4+
on:
5+
pull_request:
6+
push:
7+
branches: [master, main]
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
# Fetches full Git history to enable branch comparison
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.x"
23+
24+
- name: Install pre-commit
25+
run: pip install pre-commit
26+
27+
# Identifies changed files using git diff
28+
- name: Get modified files
29+
id: modified_files
30+
shell: bash
31+
run: |
32+
if [ "${{ github.event_name }}" == "pull_request" ]; then
33+
BASE_BRANCH="${{ github.base_ref }}"
34+
git fetch origin "$BASE_BRANCH" --depth=1
35+
MODIFIED_FILES="$(git diff --name-only "origin/$BASE_BRANCH...HEAD" || echo "")"
36+
else
37+
MODIFIED_FILES="$(git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" || echo "")"
38+
fi
39+
if [ -n "$MODIFIED_FILES" ]; then
40+
echo "Running pre-commit on changed files:"
41+
echo "$MODIFIED_FILES"
42+
echo "files=$(echo "$MODIFIED_FILES" | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
43+
echo "has_files=true" >> "$GITHUB_OUTPUT"
44+
else
45+
echo "No modified files to check."
46+
echo "has_files=false" >> "$GITHUB_OUTPUT"
47+
fi
48+
- name: Run pre-commit on modified files
49+
if: steps.modified_files.outputs.has_files == 'true'
50+
run: pre-commit run --files ${{ steps.modified_files.outputs.files }}

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/codespell-project/codespell
3+
rev: v2.4.1
4+
hooks:
5+
- id: codespell
6+
args: [--config=.codespellrc]

0 commit comments

Comments
 (0)