Skip to content

Commit 2f6ad74

Browse files
committed
Add spellcheck comment
1 parent bad177f commit 2f6ad74

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

.github/workflows/spelling.yml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,77 @@ jobs:
120120
121121
if ! pyspelling -c temp_config.yml; then
122122
FINAL_EXIT_CODE=1
123+
SPELLCHECK_LOG+="### $file\n$OUTPUT\n\n"
123124
fi
124125
fi
125126
done
126127
127128
if [ $FINAL_EXIT_CODE -ne 0 ]; then
128-
echo "Spell check failed!"
129+
echo "spell_failed=true" >> $GITHUB_OUTPUT
130+
echo "spell_log<<EOF" >> $GITHUB_OUTPUT
131+
echo "$SPELLCHECK_LOG" >> $GITHUB_OUTPUT
132+
echo "EOF" >> $GITHUB_OUTPUT
129133
exit 1
130134
fi
131135
136+
- name: Check for existing comment
137+
if: |
138+
failure() &&
139+
steps.spellcheck.outputs.spell_failed == 'true' &&
140+
github.event_name == 'pull_request'
141+
uses: actions/github-script@v6
142+
id: find-comment
143+
with:
144+
script: |
145+
const { data: comments } = await github.rest.issues.listComments({
146+
owner: context.repo.owner,
147+
repo: context.repo.repo,
148+
issue_number: context.issue.number,
149+
});
150+
const botComment = comments.find(comment =>
151+
comment.user.type === 'Bot' &&
152+
comment.body.includes('Spellcheck has failed')
153+
);
154+
return botComment ? botComment.id : '';
155+
result-encoding: string
156+
157+
- name: Post or update spell check comment
158+
if: |
159+
failure() &&
160+
steps.spellcheck.outputs.spell_failed == 'true' &&
161+
github.event_name == 'pull_request'
162+
uses: actions/github-script@v6
163+
with:
164+
script: |
165+
const message = `Spellcheck has failed. Please review the log and address the issues.
166+
167+
Here are a few tips:
168+
- All PyTorch API objects must be in double backticks or use an intersphinx directive. Example: \`\`torch.nn\`\`, :func:\`torch.load\`.
169+
- Consult en-wordlist.txt for spellings of some of the words. You can add a word to en-wordlist.txt if:
170+
1) It's a common abbreviation, like RNN.
171+
2) It's a word widely accepted in the industry.
172+
- Please do not add words like \`dtype\`, \`torch.nn.Transformer\` to pass spellcheck. Instead wrap it in double backticks or use an intersphinx directive.
173+
174+
Spell check log:
175+
\`\`\`
176+
${process.env.SPELL_LOG}
177+
\`\`\``;
178+
179+
const commentId = '${{ steps.find-comment.outputs.result }}';
180+
if (commentId) {
181+
await github.rest.issues.updateComment({
182+
owner: context.repo.owner,
183+
repo: context.repo.repo,
184+
comment_id: parseInt(commentId),
185+
body: message
186+
});
187+
} else {
188+
await github.rest.issues.createComment({
189+
owner: context.repo.owner,
190+
repo: context.repo.repo,
191+
issue_number: context.issue.number,
192+
body: message
193+
});
194+
}
195+
env:
196+
SPELL_LOG: ${{ steps.spellcheck.outputs.spell_log }}

0 commit comments

Comments
 (0)