10
10
pyspelling :
11
11
runs-on : ubuntu-20.04
12
12
steps :
13
- - uses : actions/checkout@v4
14
- with :
15
- fetch-depth : 0
16
-
17
- - name : Get changed files and check for skip label
18
- id : changes
13
+ - name : Check for skip label and get changed files
14
+ id : check-files
19
15
uses : actions/github-script@v6
20
16
with :
21
17
script : |
@@ -25,65 +21,123 @@ jobs:
25
21
if (context.eventName === 'pull_request') {
26
22
// Check for skip label
27
23
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
28
- ...context.repo,
24
+ owner: context.repo.owner,
25
+ repo: context.repo.repo,
29
26
issue_number: context.issue.number
30
27
});
31
28
skipCheck = labels.some(label => label.name === 'skip-spell-check');
32
29
33
30
if (!skipCheck) {
31
+ // Get changed files in PR
34
32
const { data: files } = await github.rest.pulls.listFiles({
35
- ...context.repo,
33
+ owner: context.repo.owner,
34
+ repo: context.repo.repo,
36
35
pull_number: context.issue.number
37
36
});
37
+
38
38
changedFiles = files
39
39
.filter(file => file.filename.match(/\.(py|rst|md)$/))
40
40
.map(file => file.filename);
41
41
}
42
42
} else {
43
- // For push events
44
- const exec = require('child_process').execSync;
45
- changedFiles = exec('git diff --name-only HEAD^..HEAD -- "*.py" "*.rst" "*.md"')
46
- .toString()
47
- .trim()
48
- .split('\n')
49
- .filter(Boolean);
43
+ // For push events, we'll still need to use git diff
44
+ // We'll handle this after checkout
50
45
}
51
46
52
- const shouldRun = !skipCheck && changedFiles.length > 0;
53
-
54
- core.setOutput('should-run', shouldRun);
47
+ core.setOutput('skip', skipCheck.toString());
55
48
core.setOutput('files', changedFiles.join('\n'));
49
+ core.setOutput('is-pr', (context.eventName === 'pull_request').toString());
50
+
51
+ - uses : actions/checkout@v4
52
+ if : steps.check-files.outputs.skip != 'true'
53
+ with :
54
+ fetch-depth : 0
55
+
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
61
+ run : |
62
+ CHANGED_FILES=$(git diff --name-only HEAD^..HEAD -- '*.py' '*.rst' '*.md')
63
+ echo "files<<EOF" >> $GITHUB_OUTPUT
64
+ echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
65
+ echo "EOF" >> $GITHUB_OUTPUT
66
+
67
+ - name : Check if relevant files changed
68
+ if : steps.check-files.outputs.skip != 'true'
69
+ id : check
70
+ run : |
71
+ if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then
72
+ FILES="${{ steps.check-files.outputs.files }}"
73
+ else
74
+ FILES="${{ steps.push-files.outputs.files }}"
75
+ fi
76
+
77
+ if [ -z "$FILES" ]; then
78
+ echo "skip=true" >> $GITHUB_OUTPUT
79
+ echo "No relevant files changed (*.py, *.rst, *.md), skipping spell check"
80
+ else
81
+ echo "skip=false" >> $GITHUB_OUTPUT
82
+ echo "Found changed files to check:"
83
+ echo "$FILES"
84
+ fi
56
85
57
86
- uses : actions/setup-python@v4
58
- if : steps.changes.outputs.should-run == 'true'
87
+ if : |
88
+ steps.check-files.outputs.skip != 'true' &&
89
+ steps.check.outputs.skip != 'true'
59
90
with :
60
91
python-version : ' 3.9'
61
92
cache : ' pip'
62
93
63
94
- name : Install dependencies
64
- if : steps.changes.outputs.should-run == 'true'
95
+ if : |
96
+ steps.check-files.outputs.skip != 'true' &&
97
+ steps.check.outputs.skip != 'true'
65
98
run : |
66
99
pip install pyspelling
67
100
sudo apt-get install aspell aspell-en
68
101
69
- - name : Run spell check
70
- if : steps.changes.outputs.should-run == 'true'
102
+ - name : Run spell check on each file
103
+ if : |
104
+ steps.check-files.outputs.skip != 'true' &&
105
+ steps.check.outputs.skip != 'true'
71
106
run : |
72
- # Get the list of files
73
- mapfile -t FILES <<< "${{ steps.changes.outputs.files }}"
107
+ # Get the list of files into an array
108
+ if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then
109
+ mapfile -t FILES <<< "${{ steps.check-files.outputs.files }}"
110
+ else
111
+ mapfile -t FILES <<< "${{ steps.push-files.outputs.files }}"
112
+ fi
74
113
75
- # Check each file
114
+ # Check each file individually
115
+ FINAL_EXIT_CODE=0
76
116
for file in "${FILES[@]}"; do
77
- echo "Checking spelling in $file"
78
- python3 - <<EOF > temp_config.yml
117
+ if [ -n "$file" ]; then
118
+ echo "Checking spelling in $file"
119
+ # Create a temporary config file based on the existing one
120
+ python3 - <<EOF > temp_config.yml
79
121
import yaml
122
+
80
123
with open('.pyspelling.yml', 'r') as f:
81
124
config = yaml.safe_load(f)
125
+
126
+ # Modify only the sources in each matrix entry
82
127
for matrix in config['matrix']:
83
128
matrix['sources'] = ['$file']
129
+
84
130
with open('temp_config.yml', 'w') as f:
85
- yaml.dump(config, f)
131
+ yaml.dump(config, f, default_flow_style=False )
86
132
EOF
87
-
88
- pyspelling -c temp_config.yml || exit 1
133
+
134
+ if ! pyspelling -c temp_config.yml; then
135
+ FINAL_EXIT_CODE=1
136
+ fi
137
+ fi
89
138
done
139
+
140
+ if [ $FINAL_EXIT_CODE -ne 0 ]; then
141
+ echo "Spell check failed!"
142
+ exit 1
143
+ fi
0 commit comments