Skip to content

build(fpb-lint): linting errors as PR comments, resolved #4416 #6914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 90 additions & 4 deletions .github/workflows/fpb-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: free-programming-books-lint

on: [push, pull_request]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_RUN_ID: ${{ github.run_id }}
PR: ${{ github.event.pull_request.html_url }}

jobs:
build:

Expand All @@ -14,7 +19,88 @@ jobs:
with:
node-version: '16.x'
- run: npm install -g free-programming-books-lint
- run: fpb-lint ./books/
- run: fpb-lint ./casts/
- run: fpb-lint ./courses/
- run: fpb-lint ./more/

- name: Push
if: ${{ github.event_name == 'push' }}
run: |
fpb-lint ./books/
fpb-lint ./casts/
fpb-lint ./courses/
fpb-lint ./more/
Comment on lines +21 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fpb-lint ./books/
fpb-lint ./casts/
fpb-lint ./courses/
fpb-lint ./more/
fpb-lint books casts courses more


- name: Pull Request
if: ${{ always() &&
github.event_name == 'pull_request' }}
run: |
fpb-lint ./books/ &>> output.log || echo "Analyzing..."
fpb-lint ./casts/ &>> output.log || echo "Analyzing..."
fpb-lint ./courses/ &>> output.log || echo "Analyzing..."
fpb-lint ./more/ &>> output.log || echo "Analyzing..."
Comment on lines +30 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fpb-lint ./books/ &>> output.log || echo "Analyzing..."
fpb-lint ./casts/ &>> output.log || echo "Analyzing..."
fpb-lint ./courses/ &>> output.log || echo "Analyzing..."
fpb-lint ./more/ &>> output.log || echo "Analyzing..."
fpb-lint books casts courses more &> output.log

The latest release of fpb-lint allows this to be done in one command.

I don't think it's worthwhile to echo Analyzing, since it will be performed after it's already finished anyway.


cat > error.log

- name: Clean output
if: ${{ always() &&
github.event_name == 'pull_request' }}
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const readline = require('readline');

const file = readline.createInterface({
input: fs.createReadStream('output.log'),
output: process.stdout,
terminal: false,
});

let lastLine = '';
file.on('line', (line) => {
if (lastLine) {
fs.appendFile('error.log', lastLine, (err) => {
if (err) {
console.error(err);
}
});
}

if (line.includes('/home/runner/work/free-programming-books/')) {
lastLine = line.replace('/home/runner/work/free-programming-books/', '') + "\r\n";
} else if (line.includes('\u26a0')) {
lastLine = '\r\n\r\n';
} else if (line.includes('remark-lint')) {
lastLine = line + '\r\n';
} else {
lastLine = null;
}
});

file.on('close', () => {
if (!lastLine || lastLine === '\r\n\r\n') {
return;
}

fs.appendFile('error.log', lastLine, (err) => {
if (err) {
console.error(err);
}
});
});

- name: Print output
if: ${{ always() &&
github.event_name == 'pull_request' }}
run: |
cat error.log

if [ -s error.log ]
then
gh pr review $PR -r -b "Linter failed, fix the error(s):
\`\`\`
$(cat error.log)
\`\`\`"
gh pr edit $PR --add-label "linter error"
else
gh pr review $PR -a
gh pr edit $PR --remove-label "linter error"
fi