forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (94 loc) · 4.11 KB
/
soak_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
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
# Based on https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# This workflow runs separately to have access to post PR comments for fork PRs
# which only have read access
name: Post soak analysis comment
on:
workflow_run:
workflows: ["Soak"]
types:
- completed
jobs:
upload:
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Output job parameters'
uses: actions/github-script@v3.1.0
with:
script: |
console.log("::group::github.event");
console.log(${{ toJSON(github.event) }}, {'depth': null, 'maxArrayLength': null});
console.log("::endgroup::");
console.log("::group::context");
console.dir(context, {'depth': null, 'maxArrayLength': null});
console.log("::endgroup::");
- name: 'Download PR number'
uses: actions/github-script@v3.1.0
with:
script: |
console.log("Fetching artifacts for run %s of %s/%s", "${{github.event.workflow_run.id }}", context.repo.owner, context.repo.repo);
var artifacts = await github.paginate(github.actions.listWorkflowRunArtifacts, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
console.log("::group::Fetched %d artifacts", artifacts.length);
console.dir(artifacts, {'maxArrayLength': null});
console.log("::endgroup::");
var matchArtifact = artifacts.filter((artifact) => {
return artifact.name == "pr-number"
})[0];
console.log("Downloading artifact %s", matchArtifact.id);
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('/tmp/pr.zip', Buffer.from(download.data));
- run: unzip -d /tmp /tmp/pr.zip
- name: Read PR number from file
id: pr-number
uses: juliangruber/read-file-action@v1
with:
path: /tmp/pr.txt
- name: 'Download soak analysis'
uses: actions/github-script@v3.1.0
with:
script: |
console.log("Fetching artifacts for run %s of %s/%s", "${{github.event.workflow_run.id }}", context.repo.owner, context.repo.repo);
var artifacts = await github.paginate(github.actions.listWorkflowRunArtifacts, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
console.log("::group::Fetched %d artifacts", artifacts.length);
console.dir(artifacts, {'maxArrayLength': null});
console.log("::endgroup::");
var matchArtifact = artifacts.filter((artifact) => {
return artifact.name == "soak-analysis"
})[0];
console.log("Downloading artifact %s", matchArtifact.id);
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('/tmp/soak-analysis.zip', Buffer.from(download.data));
- run: unzip -d /tmp /tmp/soak-analysis.zip
- name: Read analysis file
id: read-analysis
uses: juliangruber/read-file-action@v1
with:
path: /tmp/${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}-analysis
- name: Post Results To PR
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ steps.pr-number.outputs.content }}
edit-mode: replace
body: ${{ steps.read-analysis.outputs.content }}