@@ -2,19 +2,109 @@ name: free-programming-books-lint
2
2
3
3
on : [push, pull_request]
4
4
5
+ env :
6
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7
+ GITHUB_RUN_ID : ${{ github.run_id }}
8
+ PR : ${{ github.event.pull_request.html_url }}
9
+
5
10
jobs :
6
11
build :
7
12
8
13
runs-on : ubuntu-latest
9
14
10
15
steps :
11
16
- uses : actions/checkout@v3
17
+ - name : Use Python
18
+ uses : actions/setup-python@v4
19
+ with :
20
+ python-version : ' 3.x'
12
21
- name : Use Node.js
13
22
uses : actions/setup-node@v3
14
23
with :
15
24
node-version : ' 16.x'
16
25
- run : npm install -g free-programming-books-lint
17
- - run : fpb-lint ./books/
18
- - run : fpb-lint ./casts/
19
- - run : fpb-lint ./courses/
20
- - run : fpb-lint ./more/
26
+
27
+ - name : Push
28
+ if : ${{ github.event_name == 'push' }}
29
+ run : |
30
+ fpb-lint ./books/
31
+ fpb-lint ./casts/
32
+ fpb-lint ./courses/
33
+ fpb-lint ./more/
34
+
35
+ - name : Pull Request
36
+ if : ${{ always() &&
37
+ github.event_name == 'pull_request' }}
38
+ run : |
39
+ fpb-lint ./books/ &>> output.log || echo "Analyzing..."
40
+ fpb-lint ./casts/ &>> output.log || echo "Analyzing..."
41
+ fpb-lint ./courses/ &>> output.log || echo "Analyzing..."
42
+ fpb-lint ./more/ &>> output.log || echo "Analyzing..."
43
+
44
+ cat > error.log
45
+
46
+ - name : Clean output
47
+ if : ${{ always() &&
48
+ github.event_name == 'pull_request' }}
49
+ uses : actions/github-script@v6
50
+ with :
51
+ script : |
52
+ const fs = require('fs');
53
+ const readline = require('readline');
54
+
55
+ const file = readline.createInterface({
56
+ input: fs.createReadStream('output.log'),
57
+ output: process.stdout,
58
+ terminal: false,
59
+ });
60
+
61
+ let lastLine = '';
62
+ file.on('line', (line) => {
63
+ if (lastLine) {
64
+ fs.appendFile('error.log', lastLine, (err) => {
65
+ if (err) {
66
+ console.error(err);
67
+ }
68
+ });
69
+ }
70
+
71
+ if (line.includes('/home/runner/work/free-programming-books/')) {
72
+ lastLine = line.replace('/home/runner/work/free-programming-books/', '') + "\r\n";
73
+ } else if (line.includes('\u26a0')) {
74
+ lastLine = '\r\n\r\n';
75
+ } else if (line.includes('remark-lint')) {
76
+ lastLine = line + '\r\n';
77
+ } else {
78
+ lastLine = null;
79
+ }
80
+ });
81
+
82
+ file.on('close', () => {
83
+ if (!lastLine || lastLine === '\r\n\r\n') {
84
+ return;
85
+ }
86
+
87
+ fs.appendFile('error.log', lastLine, (err) => {
88
+ if (err) {
89
+ console.error(err);
90
+ }
91
+ });
92
+ });
93
+
94
+ - name : Print output
95
+ if : ${{ always() &&
96
+ github.event_name == 'pull_request' }}
97
+ run : |
98
+ cat error.log
99
+
100
+ if [ -s error.log ]
101
+ then
102
+ gh pr review $PR -r -b "Linter failed, fix the error(s):
103
+ \`\`\`
104
+ $(cat error.log)
105
+ \`\`\`"
106
+ gh pr edit $PR --add-label "linter error"
107
+ else
108
+ gh pr review $PR -a
109
+ gh pr edit $PR --remove-label "linter error"
110
+ fi
0 commit comments