Skip to content
53 changes: 27 additions & 26 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ jobs:
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const files = (process.env.ALL_CHANGED_FILES ?? '').trim().split(':').filter(Boolean);
const files = (process.env.ALL_CHANGED_FILES ?? '')
.trim().replace('\\', '').split(':').filter(Boolean);
if (files.length === 0) {
console.log('\nNo such files affected!');
process.exit(0);
}
console.log('\nChecking formatting of the following MDX and Markdown files affected by this PR:\n');
for (const file of files) {
console.log(`- ${file}`);
const notice = file.includes(' ')
? ' (filename contains spaces, please remove them!)'
: '';
console.log(`- ${file}${notice}`);
}
const filesQuoted = files.map((it) => '"' + it + '"');
try {
Expand All @@ -76,45 +80,42 @@ jobs:
console.log('1. Install necessary dependencies: \x1b[31mnpm ci\x1b[0m');
console.log(`2. Run this command to fix the issues: \x1b[31mnpm run fmt:some -- ${filesJoined}\x1b[0m`);

// Prepare a comment on the PR
const comment = [
'To fix the **formatting** issues:\n',
'1. Install necessary dependencises: `npm ci`',
'2. Then, run this command:',
'```shell',
`npm run fmt:some -- ${filesJoined}`,
'```',
].join('\n');

// Set environment variable for subsequent steps
core.exportVariable('COMMENT', comment);

// Rethrow the exit code of the failed formatting check
core.setFailed('Some files are not properly formatted!');
process.exit(1);
}

- name: Hide prior PR comments and issue a new one in case of failure
if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event_name != 'pull_request_target' }}
if: |
(
!cancelled() &&
steps.changed-files.conclusion == 'success' &&
github.event_name == 'pull_request' &&
github.event_name != 'pull_request_target'
)
env:
COMMENT: ${{ env.COMMENT }}
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
SUCCESS: ${{ steps.check-fmt.conclusion == 'failure' && 'false' || 'true' }}
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const { hidePriorCommentsWithPrefix, createComment } = await import('${{ github.workspace }}/.github/scripts/common.mjs');
const success = JSON.parse(process.env.SUCCESS ?? 'false');
const rawCommentText = process.env.COMMENT ?? '';
if (!success && rawCommentText === '') {
console.log('There was a formatting error, but no comment was given, skipping...');
process.exit(0);
}
const prefix = rawCommentText.slice(1, 30);
const files = (process.env.ALL_CHANGED_FILES ?? '')
.trim().replace('\\', '').split(':').filter(Boolean);
const comment = [
'To fix the **formatting** issues:\n',
'1. Install necessary dependencises: `npm ci`',
'2. Then, run this command:',
'```shell',
`npm run fmt:some -- ${files.map((it) => '"' + it + '"').join(' ')}`,
'```',
].join('\n');
const prefix = comment.slice(0, 30);
await hidePriorCommentsWithPrefix({ github, context, exec, prefix, resolved: success });
// Create a new comment in case of a new failure
// Create a new PR comment in case of a new failure
if (!success) {
const body = rawCommentText.slice(1, -1).replace(/\\n/g, '\n');
await createComment({ github, context, exec, body });
await createComment({ github, context, exec, body: comment });
}

spell-check:
Expand Down