forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (65 loc) · 2.25 KB
/
comment.yml
File metadata and controls
69 lines (65 loc) · 2.25 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
name: Post a comment
on:
workflow_run:
workflows:
- Check for Duplicated Code
- Check for linter warnings / exceptions
types:
- completed
permissions:
contents: read
pull-requests: write
issues: write
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
id: download
uses: actions/github-script@v8
with:
result-encoding: string
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 == "comment"
})[0];
if (matchArtifact == null) {
return "false"
}
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
if (!fs.existsSync(temp)){
fs.mkdirSync(temp);
}
fs.writeFileSync(path.join(temp, 'comment.zip'), Buffer.from(download.data));
return "true";
- name: 'Unzip artifact'
if: ${{ steps.download.outputs.result == 'true' }}
run: unzip "${{ runner.temp }}/artifacts/comment.zip" -d "${{ runner.temp }}/artifacts"
- name: 'Comment on PR'
if: ${{ steps.download.outputs.result == 'true' }}
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
const {issue_number, body} = JSON.parse(fs.readFileSync(path.join(temp, 'comment.json')));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body
});