Skip to content

Commit 885a7ae

Browse files
committed
Update
1 parent 598d710 commit 885a7ae

File tree

1 file changed

+58
-42
lines changed

1 file changed

+58
-42
lines changed

.github/workflows/spelling.yml

+58-42
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,101 @@ jobs:
1010
pyspelling:
1111
runs-on: ubuntu-20.04
1212
steps:
13-
- name: Check for skip label
14-
if: github.event_name == 'pull_request'
15-
id: skip-label
13+
- name: Check for skip label and get changed files
14+
id: check-files
1615
uses: actions/github-script@v6
1716
with:
1817
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');
18+
let skipCheck = false;
19+
let changedFiles = [];
20+
21+
if (context.eventName === 'pull_request') {
22+
// Check for skip label
23+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
issue_number: context.issue.number
27+
});
28+
skipCheck = labels.some(label => label.name === 'skip-spell-check');
29+
30+
if (!skipCheck) {
31+
// Get changed files in PR
32+
const { data: files } = await github.rest.pulls.listFiles({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
pull_number: context.issue.number
36+
});
37+
38+
changedFiles = files
39+
.filter(file => file.filename.match(/\.(py|rst|md)$/))
40+
.map(file => file.filename);
41+
}
2842
} else {
29-
core.setOutput('skip', 'false');
43+
// For push events, we'll still need to use git diff
44+
// We'll handle this after checkout
3045
}
46+
47+
core.setOutput('skip', skipCheck.toString());
48+
core.setOutput('files', changedFiles.join(' '));
49+
core.setOutput('is-pr', (context.eventName === 'pull_request').toString());
3150
3251
- uses: actions/checkout@v4
33-
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
52+
if: steps.check-files.outputs.skip != 'true'
3453
with:
3554
fetch-depth: 0
3655

37-
- name: Get changed files
38-
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
39-
id: changed-files
56+
- name: Get changed files for push event
57+
if: |
58+
steps.check-files.outputs.skip != 'true' &&
59+
steps.check-files.outputs.is-pr != 'true'
60+
id: push-files
4061
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
62+
CHANGED_FILES=$(git diff --name-only HEAD^..HEAD -- '*.py' '*.rst' '*.md')
5863
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
5964
6065
- name: Check if relevant files changed
61-
if: github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true'
66+
if: steps.check-files.outputs.skip != 'true'
6267
id: check
6368
run: |
64-
if [ -z "${{ steps.changed-files.outputs.files }}" ]; then
69+
if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then
70+
FILES="${{ steps.check-files.outputs.files }}"
71+
else
72+
FILES="${{ steps.push-files.outputs.files }}"
73+
fi
74+
75+
if [ -z "$FILES" ]; then
6576
echo "skip=true" >> $GITHUB_OUTPUT
66-
echo "No relevant files changed in monitored directories, skipping spell check"
77+
echo "No relevant files changed (*.py, *.rst, *.md), skipping spell check"
6778
else
6879
echo "skip=false" >> $GITHUB_OUTPUT
6980
echo "Found changed files to check:"
70-
echo "${{ steps.changed-files.outputs.files }}"
81+
echo "$FILES"
7182
fi
7283
7384
- uses: actions/setup-python@v4
7485
if: |
75-
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
86+
steps.check-files.outputs.skip != 'true' &&
7687
steps.check.outputs.skip != 'true'
7788
with:
7889
python-version: '3.9'
7990
cache: 'pip'
8091

8192
- name: Install dependencies
8293
if: |
83-
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
94+
steps.check-files.outputs.skip != 'true' &&
8495
steps.check.outputs.skip != 'true'
8596
run: |
8697
pip install pyspelling
8798
sudo apt-get install aspell aspell-en
8899
89100
- name: Run pyspelling
90101
if: |
91-
(github.event_name != 'pull_request' || steps.skip-label.outputs.skip != 'true') &&
102+
steps.check-files.outputs.skip != 'true' &&
92103
steps.check.outputs.skip != 'true'
93104
run: |
94-
pyspelling --source "${{ steps.changed-files.outputs.files }}"
105+
if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then
106+
FILES="${{ steps.check-files.outputs.files }}"
107+
else
108+
FILES="${{ steps.push-files.outputs.files }}"
109+
fi
110+
pyspelling --source "$FILES"

0 commit comments

Comments
 (0)