-
Notifications
You must be signed in to change notification settings - Fork 36
54 lines (52 loc) · 2.08 KB
/
style_check_comment.yml
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
name: Style-Check-Comment
on:
workflow_run:
workflows:
- Style-Check
types:
- completed
jobs:
style_check_comment:
name: Style-Check-Comment
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-22.04
steps:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Download artifact
uses: actions/github-script@v6
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var prArtifact = artifacts.data.artifacts.filter((artifact) => artifact.name == "pr")[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: prArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/pr.zip', Buffer.from(download.data));
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: prArtifact.id,
});
- run: unzip pr.zip
- name: Comment
uses: actions/github-script@v6
with:
script: |
var fs = require('fs');
var pr_number = Number(fs.readFileSync('./NR'));
await github.rest.issues.createComment({
issue_number: pr_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Style check found [formatting issues](https://github.com/'
+ context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + ${{ github.event.workflow_run.id }} + ')! '
+ 'Comment `/format`, to automatically commit the suggested changes.'
})