diff --git a/.github/workflows/commentPr.yml b/.github/workflows/commentPr.yml new file mode 100644 index 0000000000000..bab2931ab4079 --- /dev/null +++ b/.github/workflows/commentPr.yml @@ -0,0 +1,55 @@ +name: Comment on the pull request + +on: + workflow_run: + workflows: ["free-programming-books-lint"] + types: + - completed + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + upload: + runs-on: ubuntu-latest + if: > + ${{ github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' }} + steps: + - name: 'Download artifact' + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr.zip`, Buffer.from(download.data)); + + - name: 'Unzip artifact' + run: unzip pr.zip + - name: 'Comment on PR' + run: | + cat error.log + if [ -s error.log ] + then + gh pr review $(> output.log || echo "Analyzing..." fpb-lint ./more/ &>> output.log || echo "Analyzing..." + touch 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 + input: fs.createReadStream('output.log'), + output: process.stdout, + terminal: false, }); + let lastLine = ''; file.on('line', (line) => { - if (line.includes('/home/runner/work/free-programming-books/')) { - fs.writeFile('error.log', line.replace('/home/runner/work/free-programming-books/', '')); - } else if (line.includes('\u26a0')) { - fs.writeFile('error.log', '\n\n'); + 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 + - name: Upload artifact 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 \ No newline at end of file + mkdir -p ./pr + echo ${{ github.event.pull_request.html_url }} > ./pr/PRurl + mv error.log ./pr/error.log + - uses: actions/upload-artifact@v3 + with: + name: pr + path: pr/ diff --git a/books/free-programming-books-langs.md b/books/free-programming-books-langs.md index d267afd864f79..99ac89addde4b 100644 --- a/books/free-programming-books-langs.md +++ b/books/free-programming-books-langs.md @@ -248,7 +248,7 @@ That section got so big, we decided to split it into its own file, the [BY SUBJE ### Agda * [Agda Tutorial](http://people.inf.elte.hu/divip/AgdaTutorial/Index.html) -* [Programming Language Foundations in Agda](https://plfa.github.io) - Philip Wadler and Wen Kokke +* [Programming Language Foundations in Agda](https://plfa.github.io/) - Philip Wadler and Wen Kokke ### Alef @@ -375,14 +375,13 @@ That section got so big, we decided to split it into its own file, the [BY SUBJE * [Gawk: Effective AWK Programming](https://www.gnu.org/software/gawk/manual) - Arnold D. Robbins (HTML, PDF) * [GNU awk](https://learnbyexample.github.io/learn_gnuawk/) - Sundeep Agarwal - ### Bash * [Advanced Bash-Scripting Guide](http://tldp.org/LDP/abs/html/) - M. Cooper (HTML) * [Bash Guide for Beginners (2008)](http://www.tldp.org/LDP/Bash-Beginners-Guide/html/) - M. Garrels (HTML) * [Bash Notes for Professionals](http://goalkicker.com/BashBook/) - Compiled from StackOverflow documentation (PDF) * [BASH Programming (2000)](http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html) - Mike G. (HTML) -* [Bash Reference Manual](http://www.gnu.org/software/bash/manual/bashref.html) (HTML) +* [ABash Reference Manual](http://www.gnu.org/software/bash/manual/bashref.html) (HTML) * [Bash tutorial](https://web.archive.org/web/20180328183806/http://gdrcorelec.ups-tlse.fr/files/bash.pdf) - Anthony Scemama (PDF) * [BashGuide](http://mywiki.wooledge.org/BashGuide) - Maarten Billemont (HTML) [(PDF)](http://s.ntnu.no/bashguide.pdf) * [Conquer the Command Line](https://magpi.raspberrypi.org/books/command-line-second-edition/pdf/download) - Richard Smedley (PDF)