-
Notifications
You must be signed in to change notification settings - Fork 6
71 lines (59 loc) · 2.19 KB
/
pr-comment-on-trigger.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
name: pr-comment-on-trigger
on:
workflow_run:
workflows: ["pr-trigger-workflow-in-main"]
types: [completed]
jobs:
notify:
name: pr-comment-on-trigger
runs-on: ubuntu-latest
env:
ARTIFACT_FOLDER: '${{ github.workspace }}/tmp'
ARTIFACT_NAME: 'message'
steps:
- name: 'Download artifact'
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const { owner, repo } = context.repo;
const runId = "${{ github.event.workflow_run.id }}";
const artifactName = process.env.ARTIFACT_NAME;
const artifactFolder = process.env.ARTIFACT_FOLDER;
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId,
});
const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);
if (!artifact) {
throw new Error(`Could not find artifact ${ artifactName } in workflow (${ runId })`);
}
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.mkdirSync(artifactFolder, { recursive: true });
fs.writeFileSync(`${ artifactFolder }/${ artifactName }.zip`, Buffer.from(download.data));
- name: Unzip artifact
run: unzip "${ARTIFACT_FOLDER}/${ARTIFACT_NAME}.zip" -d "${ARTIFACT_FOLDER}"
- name: Parse artifact
id: parse-artifact
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const artifactFolder = process.env.ARTIFACT_FOLDER;
const content = fs.readFileSync(`${ artifactFolder }/result.json`);
const result = JSON.parse(content);
for (const property in result) {
core.setOutput(property, result[property]);
}
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.workflow_run.pull_requests[0].number }}
message: |
${{steps.parse-artifact.outputs.message}}