@@ -10,85 +10,101 @@ jobs:
10
10
pyspelling :
11
11
runs-on : ubuntu-20.04
12
12
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
16
15
uses : actions/github-script@v6
17
16
with :
18
17
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
+ }
28
42
} 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
30
45
}
46
+
47
+ core.setOutput('skip', skipCheck.toString());
48
+ core.setOutput('files', changedFiles.join(' '));
49
+ core.setOutput('is-pr', (context.eventName === 'pull_request').toString());
31
50
32
51
- 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'
34
53
with :
35
54
fetch-depth : 0
36
55
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
40
61
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')
58
63
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
59
64
60
65
- 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'
62
67
id : check
63
68
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
65
76
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"
67
78
else
68
79
echo "skip=false" >> $GITHUB_OUTPUT
69
80
echo "Found changed files to check:"
70
- echo "${{ steps.changed-files.outputs.files }} "
81
+ echo "$FILES "
71
82
fi
72
83
73
84
- uses : actions/setup-python@v4
74
85
if : |
75
- (github.event_name != 'pull_request' || steps.skip-label .outputs.skip != 'true') &&
86
+ steps.check-files .outputs.skip != 'true' &&
76
87
steps.check.outputs.skip != 'true'
77
88
with :
78
89
python-version : ' 3.9'
79
90
cache : ' pip'
80
91
81
92
- name : Install dependencies
82
93
if : |
83
- (github.event_name != 'pull_request' || steps.skip-label .outputs.skip != 'true') &&
94
+ steps.check-files .outputs.skip != 'true' &&
84
95
steps.check.outputs.skip != 'true'
85
96
run : |
86
97
pip install pyspelling
87
98
sudo apt-get install aspell aspell-en
88
99
89
100
- name : Run pyspelling
90
101
if : |
91
- (github.event_name != 'pull_request' || steps.skip-label .outputs.skip != 'true') &&
102
+ steps.check-files .outputs.skip != 'true' &&
92
103
steps.check.outputs.skip != 'true'
93
104
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