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