diff --git a/.github/workflows/clean-output.py b/.github/workflows/clean-output.py new file mode 100644 index 0000000000000..0752a5e01b78d --- /dev/null +++ b/.github/workflows/clean-output.py @@ -0,0 +1,15 @@ +import re + +with open('output.log') as oldfile, open('error.log', 'w') as newfile: + for line in oldfile: + if not (b'\xE2\x9A\xA0' in line.encode()): + if ('warning' in line): + r = line.partition("warning")[2].partition(" remark")[0] + s = str(r).rsplit(' ', 1)[0] + newfile.write(s) + if ('home/runner/work' in line): + s = line.replace("/home/runner/work/free-programming-books/", "", 1) + newfile.write(s) + else: + newfile.write("\n\n") + diff --git a/.github/workflows/fpb-lint.yml b/.github/workflows/fpb-lint.yml index 3762ea6607b3a..4d98e6b722201 100644 --- a/.github/workflows/fpb-lint.yml +++ b/.github/workflows/fpb-lint.yml @@ -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: @@ -9,12 +14,44 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Use Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' - name: Use Node.js uses: actions/setup-node@v3 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/ + + - 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..." + + python ./.github/workflows/clean-output.py + 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