-
Notifications
You must be signed in to change notification settings - Fork 7
86 lines (78 loc) · 3.17 KB
/
post_summaries.yaml
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
name: Comment on the pull request
on:
# Trigger this workflow after the Health workflow completes. This workflow will have permissions to
# do things like create comments on the PR, even if the original workflow couldn't.
workflow_call:
workflow_run:
workflows:
- Publish:Internal
- Health:Internal
types:
- completed
jobs:
upload:
permissions:
pull-requests: write
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
continue-on-error: true
steps:
# Download the output of the health workflow, consisting of the comment markdown and either
# the issue number or an existing comment ID.
- name: 'Download artifact'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
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 matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "output"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/comment.zip', Buffer.from(download.data));
- run: unzip comment.zip
# Create the comment, or update the existing one, with the markdown
# generated in the Health workflow.
- name: 'Comment on PR'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
if (fs.existsSync('./comment.md')) {
var markdown = fs.readFileSync('./comment.md', 'utf8');
if (fs.existsSync('./commentId')) {
var comment_number = Number(fs.readFileSync('./commentId', 'utf8'));
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_number,
body: markdown
});
} else {
var issue_number = Number(fs.readFileSync('./issueNumber', 'utf8'));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: markdown
});
}
} else if (fs.existsSync('./commentId')) {
var comment_number = Number(fs.readFileSync('./commentId', 'utf8'));
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_number,
});
}