|
45 | 45 | }
|
46 | 46 |
|
47 | 47 | core.setOutput('skip', skipCheck.toString());
|
48 |
| - core.setOutput('files', changedFiles.join(' ')); |
| 48 | + core.setOutput('files', changedFiles.join('\n')); |
49 | 49 | core.setOutput('is-pr', (context.eventName === 'pull_request').toString());
|
50 | 50 |
|
51 | 51 | - uses: actions/checkout@v4
|
|
60 | 60 | id: push-files
|
61 | 61 | run: |
|
62 | 62 | CHANGED_FILES=$(git diff --name-only HEAD^..HEAD -- '*.py' '*.rst' '*.md')
|
63 |
| - echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT |
| 63 | + echo "files<<EOF" >> $GITHUB_OUTPUT |
| 64 | + echo "$CHANGED_FILES" >> $GITHUB_OUTPUT |
| 65 | + echo "EOF" >> $GITHUB_OUTPUT |
64 | 66 |
|
65 | 67 | - name: Check if relevant files changed
|
66 | 68 | if: steps.check-files.outputs.skip != 'true'
|
@@ -97,14 +99,45 @@ jobs:
|
97 | 99 | pip install pyspelling
|
98 | 100 | sudo apt-get install aspell aspell-en
|
99 | 101 |
|
100 |
| - - name: Run pyspelling |
| 102 | + - name: Run spell check on each file |
101 | 103 | if: |
|
102 | 104 | steps.check-files.outputs.skip != 'true' &&
|
103 | 105 | steps.check.outputs.skip != 'true'
|
104 | 106 | run: |
|
| 107 | + # Get the list of files into an array |
105 | 108 | if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then
|
106 |
| - FILES="${{ steps.check-files.outputs.files }}" |
| 109 | + mapfile -t FILES <<< "${{ steps.check-files.outputs.files }}" |
107 | 110 | else
|
108 |
| - FILES="${{ steps.push-files.outputs.files }}" |
| 111 | + mapfile -t FILES <<< "${{ steps.push-files.outputs.files }}" |
| 112 | + fi |
| 113 | + |
| 114 | + # Check each file individually |
| 115 | + FINAL_EXIT_CODE=0 |
| 116 | + for file in "${FILES[@]}"; do |
| 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 |
| 121 | + import yaml |
| 122 | + |
| 123 | + with open('.pyspelling.yml', 'r') as f: |
| 124 | + config = yaml.safe_load(f) |
| 125 | + |
| 126 | + # Modify only the sources in each matrix entry |
| 127 | + for matrix in config['matrix']: |
| 128 | + matrix['sources'] = ['$file'] |
| 129 | + |
| 130 | + with open('temp_config.yml', 'w') as f: |
| 131 | + yaml.dump(config, f, default_flow_style=False) |
| 132 | + EOF |
| 133 | + |
| 134 | + if ! pyspelling -c temp_config.yml; then |
| 135 | + FINAL_EXIT_CODE=1 |
| 136 | + fi |
| 137 | + fi |
| 138 | + done |
| 139 | + |
| 140 | + if [ $FINAL_EXIT_CODE -ne 0 ]; then |
| 141 | + echo "Spell check failed!" |
| 142 | + exit 1 |
109 | 143 | fi
|
110 |
| - pyspelling --source "$FILES" |
|
0 commit comments