forked from akabynda/comp23hw
-
Notifications
You must be signed in to change notification settings - Fork 0
454 lines (390 loc) · 15.7 KB
/
Copy pathPrPost.yml
File metadata and controls
454 lines (390 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
name: Comment on the PR
# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ["Build PR"]
types:
- completed
env:
OPAMROOT: /home/opam/.opam
OPAMCONFIRMLEVEL: unsafe-yes
#DOCKERIMAGE: kakadu18/ocaml:llvm14
jobs:
upload_lints:
runs-on: ubuntu-latest
container:
image: kakadu18/ocaml:llvm14
options: --user root
permissions:
pull-requests: write
if: ${{( github.event.workflow_run.event == 'pull_request') && (github.event.workflow_run.conclusion == 'success') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1 # fix me later
submodules: false
- run: echo "${{ (github.event.workflow_run.event == 'pull_request') && (github.event.workflow_run.conclusion == 'success') }}"
- run: echo "conclusion = ${{ github.event.workflow_run.conclusion }}"
- run: echo "event = ${{ github.event.workflow_run.event }}"
- name: Download artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: PR.yml
name: review
- run: ls
- run: |
echo "LANG_NAME=$(cat projectname.txt)" >> $GITHUB_ENV
echo "PIARAST_NAME=$(cat piarast.txt)" >> $GITHUB_ENV
echo "CI_PULL_REQUEST=$(cat PR_number.txt)" >> $GITHUB_ENV
echo "CI_COMMIT=$(cat CI_COMMIT.txt)" >> $GITHUB_ENV
echo "CI_REPO_OWNER=Kakadu" >> $GITHUB_ENV
- run: |
echo "${{ env.LANG_NAME }}"
echo "${{ env.PIARAST_NAME }}"
echo "CI_PULL_REQUEST = ${{ env.CI_PULL_REQUEST }}"
echo "CI_COMMIT = ${{ env.CI_COMMIT }}"
echo "CI_REPO_OWNER = ${{ env.CI_REPO_OWNER }}"
- run: |
opam pin add https://github.com/Kakadu/zanuda.git --no-action
opam reinstall zanuda
opam reinstall reviewer
- run: cat lints.rdjsonl
- name: Run reviewer
run: >
opam exec -- reviewer -token ${{ secrets.GITHUB_TOKEN }} \
-owner ${{env.CI_REPO_OWNER}} \
-repo ${{github.event.repository.name}} \
-pr_number ${{ env.CI_PULL_REQUEST }} \
-commit ${{ env.CI_COMMIT }} \
-irdjsonl lints.rdjsonl -review
# TODO: Maybe not deploy empty lint files
- run: |
echo "LINTS_NAME=$(date +%Y-%m-%d_%H_%M).json" >> $GITHUB_ENV
- run: |
mkdir -p lints
cp lints.rdjsonl lints/${{ env.LINTS_NAME }}
- name: Deploy found lints
uses: peaceiris/actions-gh-pages@v3
with:
#personal_token: ${{ secrets.FP2023_UPLOAD_LINTS }}
personal_token: ${{ secrets.CLASSIC_TOKEN }}
# used only to publish in local repo
publish_dir: ./lints
external_repository: Kakadu/fp2021-ci-artifacts
publish_branch: master
keep_files: true
destination_dir: 2023comp/${{ env.LANG_NAME }}/
# generate new token
# https://github.com/settings/tokens
# put it here
# https://github.com/Kakadu/fp2023/settings/secrets/actions/new
- name: Prepare text with found lints
shell: bash
run: |
export TZ='Europe/Moscow'
echo "Linter report from $(date +%F\ %k:%M), for mini language ${{ env.LANG_NAME }}" > text.md
echo '```' >> text.md
cat lints.txt >> text.md
echo '```' >> text.md
#- run: cat text.md
- name: Find a comment with linter report
uses: peter-evans/find-comment@v2
id: fc-linter
with:
issue-number: ${{ env.CI_PULL_REQUEST }}
body-includes: Linter report from
comment-author: Kakadu
- name: Tracing ${{ steps.fc-linter.outputs.comment-id }}
run: echo "${{ steps.fc-linter.outputs.comment-id }}"
- name: Manually remove comment '${{ steps.fc-linter.outputs.comment-id }}' with lints
if: ${{ steps.fc-linter.outputs.comment-id != 0 }}
run: |
opam exec -- ocaml .github/add_comment.ml \
-token ${{ secrets.CLASSIC_TOKEN }} \
-issue ${{ env.CI_PULL_REQUEST }} \
-delete-comment ${{ steps.fc-linter.outputs.comment-id }} \
-user Kakadu \
-repo comp23hw
# The way to remove comments changes to prevent pulling extra docker image should exist.
#- name: Delete old comment
# uses: jungwinter/comment@v1
# if: ${{ steps.fc.outputs.comment-id != 0 }}
# with:
# type: delete
# comment_id: ${{ steps.fc.outputs.comment-id }}
# token: ${{ secrets.GITHUB_TOKEN }}
# - name: Create comment
# uses: mshick/add-pr-comment@v2
# with:
# message: ${{ steps.read-escaped-markdown.outputs.contents }}
# issue: ${{ env.CI_PULL_REQUEST }}
# repo-owner: Kakadu
# repo-name: comp23hw
# #refresh-message-position: true
# proxy-url: https://add-pr-comment-proxy-94idvmwyie-uc.a.run.app
# - uses: mshick/add-pr-comment@v2
# with:
# message: Hello from lints
# issue: ${{ env.CI_PULL_REQUEST }}
# repo-token: ${{ secrets.CLASSIC_TOKEN }}
# repo-owner: Kakadu
# repo-name: comp23hw
# proxy-url: https://add-pr-comment-proxy-94idvmwyie-uc.a.run.app
- run: opam list
- name: Adding a comment from text.md via OCaml script
run: >
opam exec -- ocaml .github/add_comment.ml -file text.md \
-token ${{ secrets.GITHUB_TOKEN }} \
-issue ${{ env.CI_PULL_REQUEST }} \
-repo fp2023 \
-user Kakadu
- shell: bash
run: echo "LINTER_RESOLUTION=$(bash .github/check_rdjson.sh lints.rdjsonl)" >> $GITHUB_ENV
- name: Tag PR as FEW linter complains
if: ${{ env.LINTER_RESOLUTION == 'FEW' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.setLabels({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["FEW"]
})
var labels = github.rest.issues.listLabelsOnIssue({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
});
console.log(labels)
- name: Tag PR as TOOMANY linter complains
if: ${{ env.LINTER_RESOLUTION == 'TOOMANY' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.setLabels({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["TOOMANY"]
})
var labels = github.rest.issues.listLabelsOnIssue({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
});
console.log(labels)
- name: Remove tags related to linter complains
if: ${{ env.LINTER_RESOLUTION == 'OK' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.setLabels({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: []
})
var labels = github.rest.issues.listLabelsOnIssue({
issue_number: ${{ env.CI_PULL_REQUEST }},
owner: context.repo.owner,
repo: context.repo.repo,
});
console.log(labels)
###################################################################################################
upload_docs:
runs-on: ubuntu-latest
container:
image: kakadu18/ocaml:llvm14
options: --user root
permissions:
pull-requests: write
if: ${{( github.event.workflow_run.event == 'pull_request') && (github.event.workflow_run.conclusion == 'success') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download odoc artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: PR.yml
name: docs
path: _docs
#- run: ls docs
- run: |
echo "LANG_NAME=$(cat _docs/projectname.txt)" >> $GITHUB_ENV
echo "PR_NUMBER=$(cat _docs/PR_number.txt)" >> $GITHUB_ENV
- run: |
echo "${{ env.LANG_NAME }}"
echo "${{ env.PR_NUMBER }}"
# LANG_NAME is required for uploading docs.
# PR_NUMBER -- for adding a comment
- name: Deploy documentation
uses: peaceiris/actions-gh-pages@v3
with:
#github_token: ${{ secrets.GITHUB_TOKEN }}
personal_token: ${{ secrets.FP2023_UPLOAD_LINTS }}
#github_token: ${{ secrets.PAT1 }} # used only to publish in local repo
publish_dir: ./_docs/_html
publish_branch: gh-pages
enable_jekyll: false
keep_files: true
destination_dir: docs/${{ env.LANG_NAME }}
commit_message: >
Deploying documentation for ${{ env.LANG_NAME }}: https://kakadu.github.io/${{ github.event.repository.name }}/docs/${{ env.LANG_NAME }}
user_name: '${{ github.event.repository.name }}[bot]'
user_email: '${{ github.event.repository.name }}[bot]@users.noreply.github.com'
- run: >
.github/make_doc_msg.sh \
"${{ github.event.repository.name }}" \
"${{ env.LANG_NAME }}" \
_docs/percent.txt \
text.md
- run: cat text.md
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc-docs
if: ${{ always() }}
with:
issue-number: ${{ env.PR_NUMBER }}
body-includes: Документация и тестовое покрытие
comment-author: github-actions
#- run: |
# echo "${{ steps.fc.outputs.comment-id }}"
# echo "${{ steps.fc.outputs.comment-body }}"
# echo "${{ steps.fc.outputs.comment-author }}"
# echo "${{ steps.fc.outputs.comment-created-at }}"
# The way to remove comments changes to prevent pulling extra docker image should exist.
#- name: Delete old comment
# uses: jungwinter/comment@v1
# if: ${{ steps.fc.outputs.comment-id != 0 }}
# with:
# type: delete
# comment_id: ${{ steps.fc.outputs.comment-id }}
# token: ${{ secrets.GITHUB_TOKEN }}
- run: opam install yojson curly --yes
- name: Manually remove comment '${{ steps.fc-docs.outputs.comment-id }}' with docs info
if: ${{ steps.fc-docs.outputs.comment-id != 0 }}
run: |
opam exec -- ocaml .github/add_comment.ml \
-token ${{ secrets.CLASSIC_TOKEN }} \
-issue ${{ env.PR_NUMBER }} \
-delete-comment ${{ steps.fc-docs.outputs.comment-id }} \
-user Kakadu \
-repo comp23hw
- name: List installed OPAM packages
run: opam list
- run: opam exec -- ocamlopt --version
- name: Adding a comment from 'text.md' manually
run: >
opam exec -- ocaml .github/add_comment.ml \
-file text.md \
-token ${{ secrets.GITHUB_TOKEN }} \
-issue ${{ env.PR_NUMBER }} \
-repo comp23hw \
-user Kakadu
upload_coverage:
runs-on: ubuntu-latest
if: ${{( github.event.workflow_run.event == 'pull_request') && (github.event.workflow_run.conclusion == 'success') }}
steps:
- name: Download coverage artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: PR.yml
name: coverage
path: _coverage
- run: |
echo "LANG_NAME=$(cat _coverage/projectname.txt)" >> $GITHUB_ENV
- run: echo "${{ env.LANG_NAME }}"
- run: exit 1
if: ${{ env.LANG_NAME == '' }}
- name: Deploy coverage
uses: peaceiris/actions-gh-pages@v3
with:
#github_token: ${{ secrets.GITHUB_TOKEN }} # used only to publish in local repo
github_token: ${{ secrets.CLASSIC_TOKEN }}
publish_dir: ./_coverage
publish_branch: gh-pages
enable_jekyll: false
keep_files: true
destination_dir: cov/${{ env.LANG_NAME }}
commit_message: >
Deploying coverage for ${{ env.LANG_NAME }}: https://kakadu.github.io/${{ github.event.repository.name }}/cov/${{ env.LANG_NAME }}
user_name: '${{ github.event.repository.name }}[bot]'
user_email: '${{ github.event.repository.name }}[bot]@users.noreply.github.com'
###################################################################################################
process_clones:
runs-on: ubuntu-latest
if: false
#if: >
# ${{ github.event.workflow_run.event == 'pull_request' &&
# github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: PR.yml
name: jscpd_report
- run: |
echo "PR_NUMBER=$(cat PR_number.txt)" >> $GITHUB_ENV
echo "LANG_NAME=$(cat projectname.txt)" >> $GITHUB_ENV
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ env.PR_NUMBER }}
body-includes: "#### A report of looking for clones for mini language"
comment-author: github-actions[bot]
#- name: ${{ steps.fc.outputs.comment-id }}
# run: |
# echo "${{ steps.fc.outputs.comment-body }}"
- name: Delete old comment
uses: jungwinter/comment@v1
if: ${{ steps.fc.outputs.comment-id != 0 }}
with:
type: delete
comment_id: ${{ steps.fc.outputs.comment-id }}
token: ${{ secrets.GITHUB_TOKEN }}
#- name: Delete old comment
# if: ${{ steps.fc.outputs.comment-id != 0 }}
# run: |
# curl -L https://api.github.com/repos/Kakadu/fp2023/pulls/comments/${{ steps.fc.outputs.comment-id }} \
# -X DELETE -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "X-GitHub-Api-Version: 2022-11-28"
# I tried to remove manually but it doesn't work
# { "message": "Not Found",
# "documentation_url": "https://docs.github.com/rest/pulls/comments#delete-a-review-comment-for-a-pull-request"
#}
- name: Read file contents
id: read-escaped-markdown
uses: andstor/file-reader-action@v1
with:
path: jscpd_report.txt
# https://stackoverflow.com/a/7359879
- name: Prepare text with clones report
id: render_template
shell: bash
run: |
printf "#### A report of looking for clones for mini language ${{ env.LANG_NAME }}\n\n\`\`\`\n" > template.md
cat jscpd_report.txt >> template.md
printf "\`\`\`" >> template.md
- run: cat template.md
# I used the following action earlier, but it pull +1 docker image
#- name: Render template
# id: render_template
# uses: chuhlomin/render-template@v1.4
# with:
# template: .github/jscpd.template.md
# vars: |
# contents: ${{ steps.read-escaped-markdown.outputs.contents }}
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.read-escaped-markdown.outputs.contents != '' }}
with:
edit-mode: replace
issue-number: ${{ env.PR_NUMBER }}
body-path: template.md
- if: ${{ steps.read-escaped-markdown.outputs.contents == '' }}
run: echo "JSPD report is empty"