Skip to content

Commit 7936d8c

Browse files
committed
Update spellcheck to run only on changed files
1 parent f7d06b6 commit 7936d8c

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

.github/workflows/spelling.yml

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,90 @@ on:
55
push:
66
branches:
77
- main
8+
89
jobs:
910
pyspelling:
1011
runs-on: ubuntu-20.04
1112
steps:
12-
- uses: actions/checkout@v3
13+
- name: Check for skip label
14+
if: github.event_name == 'pull_request'
15+
id: skip-label
16+
uses: actions/github-script@v6
17+
with:
18+
script: |
19+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
issue_number: context.issue.number
23+
});
24+
const skipLabel = labels.find(label => label.name === 'skip-spell-check');
25+
if (skipLabel) {
26+
console.log('Found skip-spell-check label, skipping spell check');
27+
core.setOutput('skip', 'true');
28+
} else {
29+
core.setOutput('skip', 'false');
30+
}
31+
32+
- uses: actions/checkout@v4
33+
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
34+
with:
35+
fetch-depth: 0
36+
37+
- name: Get changed files
38+
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
39+
id: changed-files
40+
run: |
41+
if [ "${{ github.event_name }}" == "pull_request" ]; then
42+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD -- \
43+
'./*.{rst,md}' \
44+
'beginner_source/**/*.{py,rst,md}' \
45+
'intermediate_source/**/*.{py,rst,md}' \
46+
'advanced_source/**/*.{py,rst,md}' \
47+
'recipes_source/**/*.{py,rst,md}' \
48+
'prototype_source/**/*.{py,rst,md}')
49+
else
50+
CHANGED_FILES=$(git diff --name-only HEAD^..HEAD -- \
51+
'./*.{rst,md}' \
52+
'beginner_source/**/*.{py,rst,md}' \
53+
'intermediate_source/**/*.{py,rst,md}' \
54+
'advanced_source/**/*.{py,rst,md}' \
55+
'recipes_source/**/*.{py,rst,md}' \
56+
'prototype_source/**/*.{py,rst,md}')
57+
fi
58+
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
59+
60+
- name: Check if relevant files changed
61+
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
62+
id: check
63+
run: |
64+
if [ -z "${{ steps.changed-files.outputs.files }}" ]; then
65+
echo "skip=true" >> $GITHUB_OUTPUT
66+
echo "No relevant files changed in monitored directories, skipping spell check"
67+
else
68+
echo "skip=false" >> $GITHUB_OUTPUT
69+
echo "Found changed files to check:"
70+
echo "${{ steps.changed-files.outputs.files }}"
71+
fi
72+
1373
- uses: actions/setup-python@v4
74+
if: |
75+
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
76+
steps.check.outputs.skip != 'true'
1477
with:
1578
python-version: '3.9'
1679
cache: 'pip'
17-
- run: pip install pyspelling
18-
- run: sudo apt-get install aspell aspell-en
19-
- run: pyspelling
2080

81+
- name: Install dependencies
82+
if: |
83+
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
84+
steps.check.outputs.skip != 'true'
85+
run: |
86+
pip install pyspelling
87+
sudo apt-get install aspell aspell-en
88+
89+
- name: Run pyspelling
90+
if: |
91+
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
92+
steps.check.outputs.skip != 'true'
93+
run: |
94+
pyspelling --source "${{ steps.changed-files.outputs.files }}"

.pyspelling.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ spellchecker: aspell
22
matrix:
33
- name: python
44
sources:
5-
- beginner_source/*.py
6-
- intermediate_source/*.py
7-
- advanced_source/*.py
8-
- recipes_source/*/*.py
5+
- "**/*.py"
96
dictionary:
107
wordlists:
118
- en-wordlist.txt
@@ -56,7 +53,7 @@ matrix:
5653
- pyspelling.filters.url:
5754
- name: reST
5855
sources:
59-
- beginner_source/*.rst
56+
- "**/*.rst"
6057
dictionary:
6158
wordlists:
6259
- en-wordlist.txt

0 commit comments

Comments
 (0)